diff --git a/Bootstrap.Admin/Controllers/Api/NewController.cs b/Bootstrap.Admin/Controllers/Api/NewController.cs index cfc59926..f8f4c41b 100644 --- a/Bootstrap.Admin/Controllers/Api/NewController.cs +++ b/Bootstrap.Admin/Controllers/Api/NewController.cs @@ -32,7 +32,7 @@ namespace Bootstrap.Admin.Controllers /// 新用户授权/拒绝接口 /// /// - [HttpPut("{id}")] + [HttpPut] public bool Put([FromBody]User value) { var ret = false; diff --git a/UnitTest/Bootstrap.Admin/Api/NewTest.cs b/UnitTest/Bootstrap.Admin/Api/NewTest.cs new file mode 100644 index 00000000..0fca73f3 --- /dev/null +++ b/UnitTest/Bootstrap.Admin/Api/NewTest.cs @@ -0,0 +1,68 @@ +using Bootstrap.DataAccess; +using System.Collections.Generic; +using System.Linq; +using Xunit; + +namespace Bootstrap.Admin.Api +{ + public class NewTest : ApiTest + { + public NewTest(BAWebHost factory) : base(factory, "New", true) + { + + } + + [Fact] + public async void Get_Ok() + { + var nusr = InsertNewUser(); + + var resp = await Client.GetAsJsonAsync>(); + Assert.NotEmpty(resp); + + // 删除新用户 + nusr.Delete(new string[] { nusr.Id }); + } + + [Fact] + public async void Put_Ok() + { + DeleteUnitTestUser(); + var nusr = InsertNewUser(); + + // Approve + nusr.UserStatus = UserStates.ApproveUser; + var resp = await Client.PutAsJsonAsync("", nusr); + Assert.True(resp); + + // 删除新用户 + nusr.Delete(new string[] { nusr.Id }); + + // Reject + nusr = InsertNewUser(); + nusr.UserStatus = UserStates.RejectUser; + resp = await Client.PutAsJsonAsync("", nusr); + Assert.True(resp); + + // 删除新用户 + nusr.Delete(new string[] { nusr.Id }); + } + + private User InsertNewUser() + { + // 插入新用户 + var nusr = new User() { UserName = "UnitTest-Register", DisplayName = "UnitTest", Password = "1", Description = "UnitTest" }; + Assert.True(new User().Save(nusr)); + return nusr; + } + + private void DeleteUnitTestUser() + { + var ids = new User().RetrieveNewUsers().Where(u => u.UserName == "UnitTest-Register").Select(u => u.Id); + new User().Delete(ids); + + ids = new User().Retrieves().Where(u => u.UserName == "UnitTest-Register").Select(u => u.Id); + new User().Delete(ids); + } + } +} diff --git a/UnitTest/Bootstrap.Admin/HttpClientExtensions.cs b/UnitTest/Bootstrap.Admin/HttpClientExtensions.cs index 07dfc158..7cb115ca 100644 --- a/UnitTest/Bootstrap.Admin/HttpClientExtensions.cs +++ b/UnitTest/Bootstrap.Admin/HttpClientExtensions.cs @@ -7,7 +7,7 @@ namespace Bootstrap.Admin { public static class HttpClientExtensions { - public static async Task GetAsJsonAsync(this HttpClient client, string requestUri) + public static async Task GetAsJsonAsync(this HttpClient client, string requestUri = null) { var resp = await client.GetAsync(requestUri); var json = await resp.Content.ReadAsStringAsync();