From 5c0d0645fd2c1bfb51069d6f9079db32493f2956 Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 6 Mar 2021 19:32:38 +0800 Subject: refactor: Rename HttpCreateUserRequest to HttpUserPostRequest. --- .../Timeline.Tests/IntegratedTests/SearchTest.cs | 6 +++--- BackEnd/Timeline.Tests/IntegratedTests/UserTest.cs | 18 ++++++++-------- BackEnd/Timeline/Controllers/UserController.cs | 3 +-- .../Timeline/Models/Http/HttpCreateUserRequest.cs | 24 ---------------------- .../Timeline/Models/Http/HttpUserPostRequest.cs | 24 ++++++++++++++++++++++ 5 files changed, 37 insertions(+), 38 deletions(-) delete mode 100644 BackEnd/Timeline/Models/Http/HttpCreateUserRequest.cs create mode 100644 BackEnd/Timeline/Models/Http/HttpUserPostRequest.cs (limited to 'BackEnd') diff --git a/BackEnd/Timeline.Tests/IntegratedTests/SearchTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/SearchTest.cs index 7782ed82..10a2f115 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/SearchTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/SearchTest.cs @@ -39,10 +39,10 @@ namespace Timeline.Tests.IntegratedTests var client = await CreateClientAsAdministrator(); { - await client.TestPostAsync("users", new HttpCreateUserRequest { Username = "hahaha", Password = "p" }); - await client.TestPostAsync("users", new HttpCreateUserRequest { Username = "bababa", Password = "p" }); + await client.TestPostAsync("users", new HttpUserPostRequest { Username = "hahaha", Password = "p" }); + await client.TestPostAsync("users", new HttpUserPostRequest { Username = "bababa", Password = "p" }); await client.TestPatchAsync("users/bababa", new HttpUserPatchRequest { Nickname = "hahaha" }); - await client.TestPostAsync("users", new HttpCreateUserRequest { Username = "gagaga", Password = "p" }); + await client.TestPostAsync("users", new HttpUserPostRequest { Username = "gagaga", Password = "p" }); } { diff --git a/BackEnd/Timeline.Tests/IntegratedTests/UserTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/UserTest.cs index 664a0604..c728a280 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/UserTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/UserTest.cs @@ -214,7 +214,7 @@ namespace Timeline.Tests.IntegratedTests { using var client = await CreateClientAsAdministrator(); { - var body = await client.TestPostAsync(createUserUrl, new HttpCreateUserRequest + var body = await client.TestPostAsync(createUserUrl, new HttpUserPostRequest { Username = "aaa", Password = "bbb", @@ -233,15 +233,15 @@ namespace Timeline.Tests.IntegratedTests public static IEnumerable Op_CreateUser_InvalidModel_Data() { - yield return new[] { new HttpCreateUserRequest { Username = "aaa" } }; - yield return new[] { new HttpCreateUserRequest { Password = "bbb" } }; - yield return new[] { new HttpCreateUserRequest { Username = "a!a", Password = "bbb" } }; - yield return new[] { new HttpCreateUserRequest { Username = "aaa", Password = "" } }; + yield return new[] { new HttpUserPostRequest { Username = "aaa" } }; + yield return new[] { new HttpUserPostRequest { Password = "bbb" } }; + yield return new[] { new HttpUserPostRequest { Username = "a!a", Password = "bbb" } }; + yield return new[] { new HttpUserPostRequest { Username = "aaa", Password = "" } }; } [Theory] [MemberData(nameof(Op_CreateUser_InvalidModel_Data))] - public async Task Op_CreateUser_InvalidModel(HttpCreateUserRequest body) + public async Task Op_CreateUser_InvalidModel(HttpUserPostRequest body) { using var client = await CreateClientAsAdministrator(); await client.TestPostAssertInvalidModelAsync(createUserUrl, body); @@ -251,7 +251,7 @@ namespace Timeline.Tests.IntegratedTests public async Task Op_CreateUser_UsernameConflict() { using var client = await CreateClientAsAdministrator(); - await client.TestPostAssertErrorAsync(createUserUrl, new HttpCreateUserRequest + await client.TestPostAssertErrorAsync(createUserUrl, new HttpUserPostRequest { Username = "user1", Password = "bbb", @@ -262,7 +262,7 @@ namespace Timeline.Tests.IntegratedTests public async Task Op_CreateUser_NoAuth_Unauthorized() { using var client = await CreateDefaultClient(); - await client.TestPostAssertUnauthorizedAsync(createUserUrl, new HttpCreateUserRequest + await client.TestPostAssertUnauthorizedAsync(createUserUrl, new HttpUserPostRequest { Username = "aaa", Password = "bbb", @@ -273,7 +273,7 @@ namespace Timeline.Tests.IntegratedTests public async Task Op_CreateUser_User_Forbid() { using var client = await CreateClientAsUser(); - await client.TestPostAssertForbiddenAsync(createUserUrl, new HttpCreateUserRequest + await client.TestPostAssertForbiddenAsync(createUserUrl, new HttpUserPostRequest { Username = "aaa", Password = "bbb", diff --git a/BackEnd/Timeline/Controllers/UserController.cs b/BackEnd/Timeline/Controllers/UserController.cs index b6eaf152..76d6042f 100644 --- a/BackEnd/Timeline/Controllers/UserController.cs +++ b/BackEnd/Timeline/Controllers/UserController.cs @@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; -using System; using System.Collections.Generic; using System.Threading.Tasks; using Timeline.Auth; @@ -69,7 +68,7 @@ namespace Timeline.Controllers [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status403Forbidden)] - public async Task> Post([FromBody] HttpCreateUserRequest body) + public async Task> Post([FromBody] HttpUserPostRequest body) { try { diff --git a/BackEnd/Timeline/Models/Http/HttpCreateUserRequest.cs b/BackEnd/Timeline/Models/Http/HttpCreateUserRequest.cs deleted file mode 100644 index 7b221f73..00000000 --- a/BackEnd/Timeline/Models/Http/HttpCreateUserRequest.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using Timeline.Controllers; -using Timeline.Models.Validation; - -namespace Timeline.Models.Http -{ - /// - /// Request model for . - /// - public class HttpCreateUserRequest - { - /// - /// Username of the new user. - /// - [Required, Username] - public string Username { get; set; } = default!; - - /// - /// Password of the new user. - /// - [Required, MinLength(1)] - public string Password { get; set; } = default!; - } -} diff --git a/BackEnd/Timeline/Models/Http/HttpUserPostRequest.cs b/BackEnd/Timeline/Models/Http/HttpUserPostRequest.cs new file mode 100644 index 00000000..c8cc004b --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpUserPostRequest.cs @@ -0,0 +1,24 @@ +using System.ComponentModel.DataAnnotations; +using Timeline.Controllers; +using Timeline.Models.Validation; + +namespace Timeline.Models.Http +{ + /// + /// Request model for . + /// + public class HttpUserPostRequest + { + /// + /// Username of the new user. + /// + [Required, Username] + public string Username { get; set; } = default!; + + /// + /// Password of the new user. + /// + [Required, MinLength(1)] + public string Password { get; set; } = default!; + } +} -- cgit v1.2.3