From eec18bcaf0a362258096ee8f9ca7f99e12424a5d Mon Sep 17 00:00:00 2001 From: Argo-Surface Date: Wed, 16 Jan 2019 15:36:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=EF=BC=9A?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0NewController=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Api/NewController.cs | 2 +- UnitTest/Bootstrap.Admin/Api/NewTest.cs | 68 +++++++++++++++++++ .../Bootstrap.Admin/HttpClientExtensions.cs | 2 +- 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 UnitTest/Bootstrap.Admin/Api/NewTest.cs 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();