diff --git a/Bootstrap.Admin/Controllers/Api/GroupsController.cs b/Bootstrap.Admin/Controllers/Api/GroupsController.cs index 46b9389a..482b66a9 100644 --- a/Bootstrap.Admin/Controllers/Api/GroupsController.cs +++ b/Bootstrap.Admin/Controllers/Api/GroupsController.cs @@ -63,7 +63,7 @@ namespace Bootstrap.Admin.Controllers.Api /// /// [HttpPost("{id}")] - public IEnumerable Post(string id, [FromQuery]string type) + public IEnumerable Post(string id, [FromQuery]string type) { IEnumerable ret = new List(); switch (type) @@ -77,7 +77,7 @@ namespace Bootstrap.Admin.Controllers.Api default: break; } - return ret.Select(p => new { p.Id, p.Checked, p.GroupName, p.Description }); + return ret; } /// diff --git a/UnitTest/Bootstrap.Admin/Api/ApiTest.cs b/UnitTest/Bootstrap.Admin/Api/ApiTest.cs index 7aebde1f..b8ab9f2c 100644 --- a/UnitTest/Bootstrap.Admin/Api/ApiTest.cs +++ b/UnitTest/Bootstrap.Admin/Api/ApiTest.cs @@ -7,9 +7,9 @@ namespace Bootstrap.Admin.Api { protected HttpClient Client { get; } - public ApiTest(BAWebHost factory, string view, bool login) + public ApiTest(BAWebHost factory, string controller, bool login) { - factory.ClientOptions.BaseAddress = new System.Uri($"http://localhost/api/{view}"); + factory.ClientOptions.BaseAddress = new System.Uri($"http://localhost/api/{controller}/"); Client = factory.CreateClient(); if (login) factory.LoginAsync(Client).GetAwaiter(); diff --git a/UnitTest/Bootstrap.Admin/Api/GroupsTest.cs b/UnitTest/Bootstrap.Admin/Api/GroupsTest.cs new file mode 100644 index 00000000..3b8bc538 --- /dev/null +++ b/UnitTest/Bootstrap.Admin/Api/GroupsTest.cs @@ -0,0 +1,68 @@ +using Longbow.Web.Mvc; +using Xunit; +using Bootstrap.DataAccess; +using System.Linq; +using System.Collections.Generic; + +namespace Bootstrap.Admin.Api +{ + public class GroupsTest : ApiTest + { + public GroupsTest(BAWebHost factory) : base(factory, "Groups", true) + { + + } + + [Fact] + public async void Get_Ok() + { + // 菜单 系统菜单 系统使用条件 + var query = "?sort=GroupName&order=asc&offset=0&limit=20&groupName=Admin&description=%E7%B3%BB%E7%BB%9F%E9%BB%98%E8%AE%A4%E7%BB%84&_=1547614230481"; + var qd = await Client.GetAsJsonAsync>(query); + Assert.Single(qd.rows); + } + + [Fact] + public async void GetById_Ok() + { + var id = new Group().Retrieves().Where(gp => gp.GroupName == "Admin").First().Id; + var g = await Client.GetAsJsonAsync(id); + Assert.Equal("Admin", g.GroupName); + } + + [Fact] + public async void PostAndDelete_Ok() + { + var ret = await Client.PostAsJsonAsync("", new Group() { GroupName = "UnitTest-Group", Description = "UnitTest-Desc" }); + Assert.True(ret); + + var ids = new Group().Retrieves().Where(d => d.GroupName == "UnitTest-Group").Select(d => d.Id); + Assert.True(await Client.DeleteAsJsonAsync, bool>("", ids)); + } + + [Fact] + public async void PostById_Ok() + { + var uid = new User().Retrieves().Where(u => u.UserName == "Admin").First().Id; + var ret = await Client.PostAsJsonAsync>($"{uid}?type=user", string.Empty); + Assert.NotEmpty(ret); + + var rid = new Role().Retrieves().Where(r => r.RoleName == "Administrators").First().Id; + ret = await Client.PostAsJsonAsync>($"{rid}?type=role", string.Empty); + Assert.NotEmpty(ret); + } + + [Fact] + public async void PutById_Ok() + { + var ids = new Group().Retrieves().Select(g => g.Id); + var uid = new User().Retrieves().Where(u => u.UserName == "Admin").First().Id; + var ret = await Client.PutAsJsonAsync, bool>($"{uid}?type=user", ids); + Assert.True(ret); + + var rid = new Role().Retrieves().Where(r => r.RoleName == "Administrators").First().Id; + ret = await Client.PutAsJsonAsync, bool>($"{rid}?type=role", ids); + Assert.True(ret); + } + } +} \ No newline at end of file