diff --git a/WebApiStudy.Bll/Class1.cs b/WebApiStudy.Bll/Class1.cs new file mode 100644 index 0000000..6903836 --- /dev/null +++ b/WebApiStudy.Bll/Class1.cs @@ -0,0 +1,8 @@ +using System; + +namespace WebApiStudy.Bll +{ + public class Class1 + { + } +} diff --git a/WebApiStudy.Bll/UserBll.cs b/WebApiStudy.Bll/UserBll.cs new file mode 100644 index 0000000..74593b6 --- /dev/null +++ b/WebApiStudy.Bll/UserBll.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Text; + +using WebApiStudy.Model; +using WebApiStudy.IDal; +using WebApiStudy.IBll; + +namespace WebApiStudy.Bll +{ + public class UserBll : IUserBll + { + private IUserDal IDal; + public UserBll(IUserDal userDal) + { + this.IDal = userDal; + } + + public List GetAllUser() + { + return IDal.GetAllUser(); + } + + public User GetUser(int userId) + { + return IDal.GetUser(userId); + } + + public (bool result, User user) InsertUser(User user) + { + return IDal.InsertUser(user); + } + + public (bool result, User user) UpdateUser(User user) + { + return IDal.UpdateUser(user); + } + + public bool DeleteUser(int userId) + { + int effectRow=IDal.DeleteUser(userId); + + return effectRow > 0; + } + + public decimal TotalIncome(int userId) + { + var user = IDal.GetUser(userId); + if (user == null) + { + return 0; + } + return user.TotalIncome(); + } + + public decimal TotalCost(int userId) + { + var user = IDal.GetUser(userId); + if (user == null) + { + return 0; + } + return user.TotalCost(); + } + } +} diff --git a/WebApiStudy.Bll/WebApiStudy.Bll.csproj b/WebApiStudy.Bll/WebApiStudy.Bll.csproj new file mode 100644 index 0000000..9511737 --- /dev/null +++ b/WebApiStudy.Bll/WebApiStudy.Bll.csproj @@ -0,0 +1,13 @@ + + + + netcoreapp2.1 + + + + + + + + + diff --git a/WebApiStudy.Dal/UserDal.cs b/WebApiStudy.Dal/UserDal.cs new file mode 100644 index 0000000..f8ac74c --- /dev/null +++ b/WebApiStudy.Dal/UserDal.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections; +using WebApiStudy.Model; +using WebApiStudy.IDal; +using System.Collections.Generic; +using System.Linq; + +namespace WebApiStudy.Dal +{ + public class UserDal : IUserDal + { + private List users; + + public UserDal() + { + users = new List() + { + new User(){ Id=3, Name="张三", Gender=1, Age=23 }, + new User(){ Id=4, Name="李四", Gender=0, Age=24 }, + new User(){ Id=5, Name="王五", Gender=1, Age=25 }, + new User(){ Id=6, Name="赵六", Gender=0, Age=26 }, + new User(){ Id=7, Name="周七", Gender=1, Age=27 }, + }; + } + + public List GetAllUser() + { + return users; + } + + public User GetUser(int userId) + { + var findUser = users.FirstOrDefault(u => u.Id == userId); + + return findUser; + } + + public (bool result, User user) InsertUser(User user) + { + var findUser = users.FirstOrDefault(u => u.Id == user.Id); + if (findUser == null) + { + users.Add(user); + } + + var result = ValueTuple.Create(findUser == null, user); + return result; + } + + public (bool result, User user) UpdateUser(User user) + { + var findUser = users.FirstOrDefault(u => u.Id == user.Id); + if (findUser != null) + { + users.Remove(findUser); + users.Add(user); + } + + var result = ValueTuple.Create(findUser != null, user); + return result; + } + + public int DeleteUser(int userId) + { + var findUser = users.FirstOrDefault(u => u.Id == userId); + if (findUser != null) + { + users.Remove(findUser); + } + + var result = findUser == null ? 0 : 1; + return result; + } + } +} diff --git a/WebApiStudy.Dal/WebApiStudy.Dal.csproj b/WebApiStudy.Dal/WebApiStudy.Dal.csproj new file mode 100644 index 0000000..2daf6a2 --- /dev/null +++ b/WebApiStudy.Dal/WebApiStudy.Dal.csproj @@ -0,0 +1,12 @@ + + + + netcoreapp2.1 + + + + + + + + diff --git a/WebApiStudy.IBll/IUserBll.cs b/WebApiStudy.IBll/IUserBll.cs new file mode 100644 index 0000000..02bc22d --- /dev/null +++ b/WebApiStudy.IBll/IUserBll.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; + +using WebApiStudy.Model; + +namespace WebApiStudy.IBll +{ + public interface IUserBll + { + List GetAllUser(); + + User GetUser(int userId); + + (bool result, User user) InsertUser(User user); + + (bool result, User user) UpdateUser(User user); + + bool DeleteUser(int userId); + + decimal TotalIncome(int userId); + + decimal TotalCost(int userId); + } +} diff --git a/WebApiStudy.IBll/WebApiStudy.IBll.csproj b/WebApiStudy.IBll/WebApiStudy.IBll.csproj new file mode 100644 index 0000000..dff3419 --- /dev/null +++ b/WebApiStudy.IBll/WebApiStudy.IBll.csproj @@ -0,0 +1,11 @@ + + + + netcoreapp2.1 + + + + + + + diff --git a/WebApiStudy.IDal/IUserDal.cs b/WebApiStudy.IDal/IUserDal.cs new file mode 100644 index 0000000..0d975dd --- /dev/null +++ b/WebApiStudy.IDal/IUserDal.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; + +using WebApiStudy.Model; + +namespace WebApiStudy.IDal +{ + public interface IUserDal + { + List GetAllUser(); + + User GetUser(int userId); + + (bool result, User user) InsertUser(User user); + + (bool result, User user) UpdateUser(User user); + + int DeleteUser(int userId); + } +} diff --git a/WebApiStudy.IDal/WebApiStudy.IDal.csproj b/WebApiStudy.IDal/WebApiStudy.IDal.csproj new file mode 100644 index 0000000..dff3419 --- /dev/null +++ b/WebApiStudy.IDal/WebApiStudy.IDal.csproj @@ -0,0 +1,11 @@ + + + + netcoreapp2.1 + + + + + + + diff --git a/WebApiStudy.IntegrationTest/GlobalFixture/TestServerFixture.cs b/WebApiStudy.IntegrationTest/GlobalFixture/TestServerFixture.cs new file mode 100644 index 0000000..8bf6adf --- /dev/null +++ b/WebApiStudy.IntegrationTest/GlobalFixture/TestServerFixture.cs @@ -0,0 +1,27 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.TestHost; +using System; +using System.Collections.Generic; +using System.Text; +using WebApiStudy.WebApp; + +namespace WebApiStudy.IntegrationTest +{ + public class TestServerFixture : IDisposable + { + public TestServer TestServer; + + /// + /// 设置测试内存服务器 TestServer + /// + public TestServerFixture() + { + TestServer = new TestServer(new WebHostBuilder().UseStartup()); + } + + public void Dispose() + { + TestServer = null; + } + } +} diff --git a/WebApiStudy.IntegrationTest/GlobalFixture/TestServerFixtureSetup.cs b/WebApiStudy.IntegrationTest/GlobalFixture/TestServerFixtureSetup.cs new file mode 100644 index 0000000..ef5dcd7 --- /dev/null +++ b/WebApiStudy.IntegrationTest/GlobalFixture/TestServerFixtureSetup.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Text; + +using Xunit; +using Xunit.Abstractions; +using Xunit.Extensions; +using Xunit.Sdk; + +namespace WebApiStudy.IntegrationTest +{ + /// + /// 测试服务器,全局共享设置 + /// + [CollectionDefinition(name:"GlobalTestServer")] + public class TestServerFixtureSetup : ICollectionFixture + { + + } +} diff --git a/WebApiStudy.IntegrationTest/TestControllerTest.cs b/WebApiStudy.IntegrationTest/TestControllerTest.cs new file mode 100644 index 0000000..aa08e2b --- /dev/null +++ b/WebApiStudy.IntegrationTest/TestControllerTest.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Threading.Tasks; + +using Microsoft.AspNetCore.TestHost; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Hosting; + +using Newtonsoft.Json; +using Xunit; +using Xunit.Abstractions; +using Xunit.Extensions; +using Moq; + +using WebApiStudy.Model; +using WebApiStudy.WebApp; + +namespace WebApiStudy.IntegrationTest +{ + [Collection("GlobalTestServer")] + public class TestControllerTest + { + private TestServer _server; + private readonly HttpClient _client; + + public TestControllerTest(TestServerFixture testServer) + { + _server = testServer.TestServer; + _client = _server.CreateClient(); + } + + [Fact] + public async Task Test() + { + var response = await _client.GetAsync("/api/values"); + response.EnsureSuccessStatusCode(); + + var responseString = await response.Content.ReadAsStringAsync(); + IList list = JsonConvert.DeserializeObject>(responseString); + + Assert.Equal(2, list.Count); + + Assert.Contains("value1", list); + Assert.Contains("value2", list); + } + } +} diff --git a/WebApiStudy.IntegrationTest/UserControllerTest.cs b/WebApiStudy.IntegrationTest/UserControllerTest.cs new file mode 100644 index 0000000..81e26f9 --- /dev/null +++ b/WebApiStudy.IntegrationTest/UserControllerTest.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Threading.Tasks; + +using Microsoft.AspNetCore.TestHost; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Hosting; + +using Newtonsoft.Json; +using Xunit; +using Xunit.Abstractions; +using Xunit.Extensions; +using Moq; + +using WebApiStudy.Model; +using WebApiStudy.WebApp; + +namespace WebApiStudy.IntegrationTest +{ + [Collection("GlobalTestServer")] + public class UserControllerTest + { + private TestServer _server; + private readonly HttpClient _client; + + public UserControllerTest(TestServerFixture testServer) + { + _server = testServer.TestServer; + _client = _server.CreateClient(); + } + + [Fact] + public async Task GetUsers_Test() + { + var response = await _client.GetAsync("/api/user/GetAllUser"); + response.EnsureSuccessStatusCode(); + + var responseString = await response.Content.ReadAsStringAsync(); + IList list = JsonConvert.DeserializeObject>(responseString); + + Assert.Equal(5, list.Count); + } + + [Fact] + public async Task AddUser_Test() + { + Uri uri = new Uri("http://localhost:5000/api/user/AddUser"); + HttpContent httpContent = new StringContent("{\"id\": 55,\"name\": \"张三\",\"age\": 23,\"gender\": 1}", System.Text.Encoding.UTF8, "application/json"); + + //HttpRequestMessage requestMessage = new HttpRequestMessage(); + //requestMessage.RequestUri =uri ; + //requestMessage.Method = HttpMethod.Post; + //requestMessage.Content =httpContent; + + var response = await _client.PostAsync(uri, httpContent); + response.EnsureSuccessStatusCode(); + + var responseString = await response.Content.ReadAsStringAsync(); + (bool result, User user) = JsonConvert.DeserializeObject>(responseString); + + Assert.True(result); + Assert.Equal(55, user.Id); + } + } +} diff --git a/WebApiStudy.IntegrationTest/WebApiStudy.IntegrationTest.csproj b/WebApiStudy.IntegrationTest/WebApiStudy.IntegrationTest.csproj new file mode 100644 index 0000000..e75ade7 --- /dev/null +++ b/WebApiStudy.IntegrationTest/WebApiStudy.IntegrationTest.csproj @@ -0,0 +1,29 @@ + + + + netcoreapp2.1 + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WebApiStudy.Model/Student.cs b/WebApiStudy.Model/Student.cs new file mode 100644 index 0000000..4930ae8 --- /dev/null +++ b/WebApiStudy.Model/Student.cs @@ -0,0 +1,8 @@ +using System; + +namespace WebApiStudy.Model +{ + public class Student + { + } +} diff --git a/WebApiStudy.Model/Teacher.cs b/WebApiStudy.Model/Teacher.cs new file mode 100644 index 0000000..f762202 --- /dev/null +++ b/WebApiStudy.Model/Teacher.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WebApiStudy.Model +{ + public class Teacher + { + + } +} diff --git a/WebApiStudy.Model/User.cs b/WebApiStudy.Model/User.cs new file mode 100644 index 0000000..5079b94 --- /dev/null +++ b/WebApiStudy.Model/User.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WebApiStudy.Model +{ + public class User + { + public int Id { get; set; } + + public string Name { get; set; } + + public int Age { get; set; } + + public int Gender { get; set; } + + public virtual decimal TotalIncome() + { + return 1000; + } + + public virtual decimal TotalCost() + { + return 500; + } + } +} diff --git a/WebApiStudy.Model/WebApiStudy.Model.csproj b/WebApiStudy.Model/WebApiStudy.Model.csproj new file mode 100644 index 0000000..86ea3bb --- /dev/null +++ b/WebApiStudy.Model/WebApiStudy.Model.csproj @@ -0,0 +1,7 @@ + + + + netcoreapp2.1 + + + diff --git a/WebApiStudy.WebApp/Controllers/TestController.cs b/WebApiStudy.WebApp/Controllers/TestController.cs new file mode 100644 index 0000000..d62b2a1 --- /dev/null +++ b/WebApiStudy.WebApp/Controllers/TestController.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ApiExplorer; +using Microsoft.Net; +using Microsoft.Net.Http; +using Microsoft.AspNetCore.WebUtilities; + +namespace WebApiStudy.WebApp.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class TestController : ControllerBase + { + [HttpGet] + public IEnumerable Get() + { + return new string[] { "value1", "value2" }; + } + + [HttpGet("{id}", Name = "Get")] + public string Get(int id) + { + return "value"; + } + + //[Route("MyName")] + [HttpGet("GetName/{id:int}")] + public string GetName(int id) + { + var myName = ""; + + if (id >20) + { + myName = "wanggaofeng"; + } + else + { + myName = "wangxiangqian"; + } + return myName; + } + + [HttpPost] + public void Post([FromBody] string value) + { + } + + [HttpPut("{id}")] + public void Put(int id, [FromBody] string value) + { + } + + [HttpDelete("{id}")] + public void Delete(int id) + { + } + } +} diff --git a/WebApiStudy.WebApp/Controllers/UserController.cs b/WebApiStudy.WebApp/Controllers/UserController.cs new file mode 100644 index 0000000..0983ec3 --- /dev/null +++ b/WebApiStudy.WebApp/Controllers/UserController.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +using WebApiStudy.Model; +using WebApiStudy.IDal; +using WebApiStudy.IBll; + +namespace WebApiStudy.WebApp.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class UserController : ControllerBase + { + IUserBll userBll; + + public UserController(IUserBll userBll) + { + this.userBll = userBll; + } + + [HttpGet("GetAllUser")] + public List GetUsers() + { + return userBll.GetAllUser(); + } + + [HttpGet("GetUser/{userId:int}")] + public User GetUser(int userId) + { + return userBll.GetUser(userId); + } + + [HttpPost("AddUser")] + public (bool result, User user) InsertUser([FromBody]User user) + { + return userBll.InsertUser(user); + } + + [HttpPost("UpdateUser")] + public (bool result, User user) UpdateUser([FromBody]User user) + { + return userBll.UpdateUser(user); + } + + [HttpDelete("UpdateUser/{userId}")] + public bool DeleteUser(int userId) + { + return userBll.DeleteUser(userId); + } + + [HttpGet("GetIncome/{userId:int}")] + public decimal TotalIncome(int userId) + { + return userBll.TotalIncome(userId); + } + + [HttpGet("GetCost/{userId:int}")] + public decimal TotalCost(int userId) + { + return userBll.TotalCost(userId); + } + } +} \ No newline at end of file diff --git a/WebApiStudy.WebApp/Controllers/ValuesController.cs b/WebApiStudy.WebApp/Controllers/ValuesController.cs new file mode 100644 index 0000000..256cfbc --- /dev/null +++ b/WebApiStudy.WebApp/Controllers/ValuesController.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; + +namespace WebApiStudy.WebApp.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ValuesController : ControllerBase + { + // GET api/values + [HttpGet] + public ActionResult> Get() + { + return new string[] { "value1", "value2" }; + } + + // GET api/values/5 + [HttpGet("{id}")] + public ActionResult Get(int id) + { + return "value"; + } + + // POST api/values + [HttpPost] + public void Post([FromBody] string value) + { + } + + // PUT api/values/5 + [HttpPut("{id}")] + public void Put(int id, [FromBody] string value) + { + } + + // DELETE api/values/5 + [HttpDelete("{id}")] + public void Delete(int id) + { + } + } +} diff --git a/WebApiStudy.WebApp/Program.cs b/WebApiStudy.WebApp/Program.cs new file mode 100644 index 0000000..0a1426d --- /dev/null +++ b/WebApiStudy.WebApp/Program.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; + +namespace WebApiStudy.WebApp +{ + public class Program + { + public static void Main(string[] args) + { + CreateWebHostBuilder(args).Build().Run(); + } + + public static IWebHostBuilder CreateWebHostBuilder(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseStartup(); + } +} diff --git a/WebApiStudy.WebApp/Properties/launchSettings.json b/WebApiStudy.WebApp/Properties/launchSettings.json new file mode 100644 index 0000000..8c38b6a --- /dev/null +++ b/WebApiStudy.WebApp/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:1633", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "api/values", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "WebApiStudy.WebApp": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "api/values", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} \ No newline at end of file diff --git a/WebApiStudy.WebApp/Startup.cs b/WebApiStudy.WebApp/Startup.cs new file mode 100644 index 0000000..2328f85 --- /dev/null +++ b/WebApiStudy.WebApp/Startup.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; + +using WebApiStudy.Model; +using WebApiStudy.Dal; +using WebApiStudy.IDal; +using WebApiStudy.IBll; +using WebApiStudy.Bll; + +namespace WebApiStudy.WebApp +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); + + //注册IUserBll + IUserBll userBll = new UserBll(new UserDal()); + services.AddTransient((ServiceProvider) => { return userBll; }); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IHostingEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseMvc(); + } + } +} diff --git a/WebApiStudy.WebApp/WebApiStudy.WebApp.csproj b/WebApiStudy.WebApp/WebApiStudy.WebApp.csproj new file mode 100644 index 0000000..b4130e6 --- /dev/null +++ b/WebApiStudy.WebApp/WebApiStudy.WebApp.csproj @@ -0,0 +1,24 @@ + + + + netcoreapp2.1 + + + + + + + + + + + + + + + + + + + + diff --git a/WebApiStudy.WebApp/appsettings.Development.json b/WebApiStudy.WebApp/appsettings.Development.json new file mode 100644 index 0000000..e203e94 --- /dev/null +++ b/WebApiStudy.WebApp/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/WebApiStudy.WebApp/appsettings.json b/WebApiStudy.WebApp/appsettings.json new file mode 100644 index 0000000..def9159 --- /dev/null +++ b/WebApiStudy.WebApp/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/WebApiStudy.WebAppTest/TestControllerTest.cs b/WebApiStudy.WebAppTest/TestControllerTest.cs new file mode 100644 index 0000000..0d2ab9f --- /dev/null +++ b/WebApiStudy.WebAppTest/TestControllerTest.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; + +using Xunit; + +using WebApiStudy.WebApp; +using WebApiStudy.WebApp.Controllers; + +namespace WebApiStudy.WebAppTest +{ + public class TestControllerTest + { + [Fact] + public void Get_Test() + { + TestController controller = new TestController(); + + var actualList = controller.Get(); + var expected = new string[] {"value1", "value2"}; + + Assert.Equal(expected, actualList); + } + } +} diff --git a/WebApiStudy.WebAppTest/UseXunitTest.cs b/WebApiStudy.WebAppTest/UseXunitTest.cs new file mode 100644 index 0000000..5edb326 --- /dev/null +++ b/WebApiStudy.WebAppTest/UseXunitTest.cs @@ -0,0 +1,14 @@ +using System; +using Xunit; + +namespace WebApiStudy.WebAppTest +{ + public class UseXunitTest + { + [Fact] + public void Use_Test() + { + Assert.True(true, "xUnit"); + } + } +} diff --git a/WebApiStudy.WebAppTest/UserControllerTest.cs b/WebApiStudy.WebAppTest/UserControllerTest.cs new file mode 100644 index 0000000..02ba52b --- /dev/null +++ b/WebApiStudy.WebAppTest/UserControllerTest.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Text; + +using Xunit; + +using WebApiStudy.Model; +using WebApiStudy.Dal; +using WebApiStudy.IDal; +using WebApiStudy.Bll; +using WebApiStudy.IBll; + +using WebApiStudy.WebApp; +using WebApiStudy.WebApp.Controllers; + +namespace WebApiStudy.WebAppTest +{ + public class UserControllerTest : IDisposable + { + IUserBll userBll; + + public UserControllerTest() + { + userBll = new UserBll(new UserDal()); + } + + + [Fact] + public void GetAllUsers() + { + UserController controller = new UserController(userBll); + + List users = controller.GetUsers(); + + Assert.NotNull(users); + Assert.Equal(5, users.Count); + } + + public void Dispose() + { + + } + } +} diff --git a/WebApiStudy.WebAppTest/WebApiStudy.WebAppTest.csproj b/WebApiStudy.WebAppTest/WebApiStudy.WebAppTest.csproj new file mode 100644 index 0000000..1827023 --- /dev/null +++ b/WebApiStudy.WebAppTest/WebApiStudy.WebAppTest.csproj @@ -0,0 +1,27 @@ + + + + netcoreapp2.1 + + false + + + + + + + + + + + + + + + + + + + + + diff --git a/WebApiStudy.sln b/WebApiStudy.sln new file mode 100644 index 0000000..76400a9 --- /dev/null +++ b/WebApiStudy.sln @@ -0,0 +1,67 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27703.2047 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApiStudy.WebApp", "WebApiStudy.WebApp\WebApiStudy.WebApp.csproj", "{4860C826-31EB-41D7-B541-E48F7F10379B}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApiStudy.IDal", "WebApiStudy.IDal\WebApiStudy.IDal.csproj", "{DE63C251-7FA4-4904-B9F3-063D82FD4171}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApiStudy.Dal", "WebApiStudy.Dal\WebApiStudy.Dal.csproj", "{01C0A6E4-E9C7-4684-9EFB-D917569A60B1}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApiStudy.IBll", "WebApiStudy.IBll\WebApiStudy.IBll.csproj", "{3DEBC327-1119-4420-BB1D-85A1314D66DC}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApiStudy.Bll", "WebApiStudy.Bll\WebApiStudy.Bll.csproj", "{AA338A3B-BF1B-43EF-9EA2-DD6315B83C5D}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApiStudy.WebAppTest", "WebApiStudy.WebAppTest\WebApiStudy.WebAppTest.csproj", "{F78D594D-6206-4D33-A289-D97F1902C64F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiStudy.Model", "WebApiStudy.Model\WebApiStudy.Model.csproj", "{D61BB773-F8EA-4FC6-B38E-622EE87E3126}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiStudy.IntegrationTest", "WebApiStudy.IntegrationTest\WebApiStudy.IntegrationTest.csproj", "{F9FBBAE5-1429-4801-BB30-C62D762EE481}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4860C826-31EB-41D7-B541-E48F7F10379B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4860C826-31EB-41D7-B541-E48F7F10379B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4860C826-31EB-41D7-B541-E48F7F10379B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4860C826-31EB-41D7-B541-E48F7F10379B}.Release|Any CPU.Build.0 = Release|Any CPU + {DE63C251-7FA4-4904-B9F3-063D82FD4171}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DE63C251-7FA4-4904-B9F3-063D82FD4171}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DE63C251-7FA4-4904-B9F3-063D82FD4171}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DE63C251-7FA4-4904-B9F3-063D82FD4171}.Release|Any CPU.Build.0 = Release|Any CPU + {01C0A6E4-E9C7-4684-9EFB-D917569A60B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {01C0A6E4-E9C7-4684-9EFB-D917569A60B1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {01C0A6E4-E9C7-4684-9EFB-D917569A60B1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {01C0A6E4-E9C7-4684-9EFB-D917569A60B1}.Release|Any CPU.Build.0 = Release|Any CPU + {3DEBC327-1119-4420-BB1D-85A1314D66DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3DEBC327-1119-4420-BB1D-85A1314D66DC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3DEBC327-1119-4420-BB1D-85A1314D66DC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3DEBC327-1119-4420-BB1D-85A1314D66DC}.Release|Any CPU.Build.0 = Release|Any CPU + {AA338A3B-BF1B-43EF-9EA2-DD6315B83C5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AA338A3B-BF1B-43EF-9EA2-DD6315B83C5D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AA338A3B-BF1B-43EF-9EA2-DD6315B83C5D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AA338A3B-BF1B-43EF-9EA2-DD6315B83C5D}.Release|Any CPU.Build.0 = Release|Any CPU + {F78D594D-6206-4D33-A289-D97F1902C64F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F78D594D-6206-4D33-A289-D97F1902C64F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F78D594D-6206-4D33-A289-D97F1902C64F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F78D594D-6206-4D33-A289-D97F1902C64F}.Release|Any CPU.Build.0 = Release|Any CPU + {D61BB773-F8EA-4FC6-B38E-622EE87E3126}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D61BB773-F8EA-4FC6-B38E-622EE87E3126}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D61BB773-F8EA-4FC6-B38E-622EE87E3126}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D61BB773-F8EA-4FC6-B38E-622EE87E3126}.Release|Any CPU.Build.0 = Release|Any CPU + {F9FBBAE5-1429-4801-BB30-C62D762EE481}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F9FBBAE5-1429-4801-BB30-C62D762EE481}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F9FBBAE5-1429-4801-BB30-C62D762EE481}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F9FBBAE5-1429-4801-BB30-C62D762EE481}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {28342AA8-4D03-493A-B952-F87251FD0E61} + EndGlobalSection +EndGlobal