From a672e10faad434899d81ef9d0d0d5adbbc7841da Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 30 Apr 2021 16:52:55 +0800 Subject: refactor: ... --- BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs | 12 ++++++------ BackEnd/Timeline.Tests/IntegratedTests/UserAvatarTest.cs | 6 +++--- BackEnd/Timeline.Tests/IntegratedTests/UserPermissionTest.cs | 4 ++-- BackEnd/Timeline.Tests/IntegratedTests/UserTest.cs | 8 ++++---- BackEnd/Timeline.Tests/Services/UserPermissionServiceTest.cs | 9 +++++---- 5 files changed, 20 insertions(+), 19 deletions(-) (limited to 'BackEnd/Timeline.Tests') diff --git a/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs index e2ce8875..0e7bb735 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs @@ -188,7 +188,7 @@ namespace Timeline.Tests.IntegratedTests body.Should().BeEquivalentTo(await client.GetTimelineAsync("aaa")); } - await client.TestPostAssertErrorAsync("timelines", new HttpTimelineCreateRequest { Name = "aaa" }, errorCode: ErrorCodes.TimelineController.NameConflict); + await client.TestPostAssertErrorAsync("timelines", new HttpTimelineCreateRequest { Name = "aaa" }, errorCode: ErrorCodes.Conflict.Timeline); } } @@ -210,7 +210,7 @@ namespace Timeline.Tests.IntegratedTests await client.TestDeleteAssertInvalidModelAsync("timelines/!!!"); await client.TestDeleteAsync("timelines/t2"); - await client.TestDeleteAssertErrorAsync("timelines/t2"); + await client.TestDeleteAsync("timelines/t2"); } { @@ -218,7 +218,7 @@ namespace Timeline.Tests.IntegratedTests await client.TestDeleteAssertInvalidModelAsync("timelines/!!!"); await client.TestDeleteAsync("timelines/t1"); - await client.TestDeleteAssertErrorAsync("timelines/t1"); + await client.TestDeleteAsync("timelines/t1"); } } @@ -294,13 +294,13 @@ namespace Timeline.Tests.IntegratedTests } await AssertEmptyMembers(); - await client.TestPutAssertErrorAsync($"timelines/{timelineName}/members/usernotexist", errorCode: ErrorCodes.UserCommon.NotExist); + await client.TestPutAssertErrorAsync($"timelines/{timelineName}/members/usernotexist", errorCode: ErrorCodes.NotExist.User); await AssertEmptyMembers(); await client.PutTimelineMemberAsync(timelineName, "user2"); await AssertMembers(new List { await client.GetUserAsync("user2") }); await client.DeleteTimelineMemberAsync(timelineName, "user2", true); await AssertEmptyMembers(); - await client.TestDeleteAssertErrorAsync($"timelines/{timelineName}/members/usernotexist", errorCode: ErrorCodes.UserCommon.NotExist); + await client.TestDeleteAsync($"timelines/{timelineName}/members/usernotexist", false); await AssertEmptyMembers(); } @@ -377,7 +377,7 @@ namespace Timeline.Tests.IntegratedTests using (var client = await CreateClientAsUser()) { await client.TestPatchAssertInvalidModelAsync("timelines/t1", new HttpTimelinePatchRequest { Name = "!!!" }); - await client.TestPatchAssertErrorAsync("timelines/t1", new HttpTimelinePatchRequest { Name = "t2" }, errorCode: ErrorCodes.TimelineController.NameConflict); + await client.TestPatchAssertErrorAsync("timelines/t1", new HttpTimelinePatchRequest { Name = "t2" }, errorCode: ErrorCodes.Conflict.Timeline); await client.TestPatchAsync("timelines/t1", new HttpTimelinePatchRequest { Name = "newt" }); diff --git a/BackEnd/Timeline.Tests/IntegratedTests/UserAvatarTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/UserAvatarTest.cs index 708120b1..c2ccff64 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/UserAvatarTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/UserAvatarTest.cs @@ -30,7 +30,7 @@ namespace Timeline.Tests.IntegratedTests using (var client = await CreateClientAsUser()) { - await client.TestGetAssertNotFoundAsync("users/usernotexist/avatar", errorCode: ErrorCodes.UserCommon.NotExist); + await client.TestGetAssertNotFoundAsync("users/usernotexist/avatar", errorCode: ErrorCodes.NotExist.User); var env = TestApp.Host.Services.GetRequiredService(); var defaultAvatarData = await File.ReadAllBytesAsync(Path.Combine(env.ContentRootPath, "default-avatar.png")); @@ -138,8 +138,8 @@ namespace Timeline.Tests.IntegratedTests { await client.TestPutByteArrayAsync("users/user1/avatar", mockAvatar.Data, mockAvatar.ContentType); await client.TestDeleteAsync("users/user1/avatar"); - await client.TestPutByteArrayAssertErrorAsync("users/usernotexist/avatar", new[] { (byte)0x00 }, "image/png", errorCode: ErrorCodes.UserCommon.NotExist); - await client.TestDeleteAssertErrorAsync("users/usernotexist/avatar", errorCode: ErrorCodes.UserCommon.NotExist); + await client.TestPutByteArrayAssertErrorAsync("users/usernotexist/avatar", new[] { (byte)0x00 }, "image/png", errorCode: ErrorCodes.NotExist.User); + await client.TestDeleteAsync("users/usernotexist/avatar"); } // bad username check diff --git a/BackEnd/Timeline.Tests/IntegratedTests/UserPermissionTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/UserPermissionTest.cs index 32e25aaa..83dc51f9 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/UserPermissionTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/UserPermissionTest.cs @@ -190,8 +190,8 @@ namespace Timeline.Tests.IntegratedTests const string url = "users/user123/permissions/UserManagement"; - await client.TestPutAssertNotFoundAsync(url, errorCode: ErrorCodes.UserCommon.NotExist); - await client.TestDeleteAssertNotFoundAsync(url, errorCode: ErrorCodes.UserCommon.NotExist); + await client.TestPutAssertErrorAsync(url, errorCode: ErrorCodes.NotExist.User); + await client.TestDeleteAsync(url); } } } diff --git a/BackEnd/Timeline.Tests/IntegratedTests/UserTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/UserTest.cs index c728a280..7286e12e 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/UserTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/UserTest.cs @@ -47,7 +47,7 @@ namespace Timeline.Tests.IntegratedTests public async Task Get_404() { using var client = await CreateDefaultClient(); - await client.TestGetAssertNotFoundAsync("users/usernotexist", errorCode: ErrorCodes.UserCommon.NotExist); + await client.TestGetAssertNotFoundAsync("users/usernotexist", errorCode: ErrorCodes.NotExist.User); } [Fact] @@ -104,7 +104,7 @@ namespace Timeline.Tests.IntegratedTests public async Task Patch_NotExist() { using var client = await CreateClientAsAdministrator(); - await client.TestPatchAssertNotFoundAsync("users/usernotexist", new HttpUserPatchRequest { }, errorCode: ErrorCodes.UserCommon.NotExist); + await client.TestPatchAssertErrorAsync("users/usernotexist", new HttpUserPatchRequest { }, errorCode: ErrorCodes.NotExist.User); } [Fact] @@ -133,7 +133,7 @@ namespace Timeline.Tests.IntegratedTests public async Task Patch_UsernameConflict() { using var client = await CreateClientAsAdministrator(); - await client.TestPatchAssertErrorAsync("users/user1", new HttpUserPatchRequest { Username = "admin" }, errorCode: ErrorCodes.UserController.UsernameConflict); + await client.TestPatchAssertErrorAsync("users/user1", new HttpUserPatchRequest { Username = "admin" }, errorCode: ErrorCodes.Conflict.User); } [Fact] @@ -255,7 +255,7 @@ namespace Timeline.Tests.IntegratedTests { Username = "user1", Password = "bbb", - }, errorCode: ErrorCodes.UserController.UsernameConflict); + }, errorCode: ErrorCodes.Conflict.User); } [Fact] diff --git a/BackEnd/Timeline.Tests/Services/UserPermissionServiceTest.cs b/BackEnd/Timeline.Tests/Services/UserPermissionServiceTest.cs index aa92ff73..7923e9db 100644 --- a/BackEnd/Timeline.Tests/Services/UserPermissionServiceTest.cs +++ b/BackEnd/Timeline.Tests/Services/UserPermissionServiceTest.cs @@ -1,6 +1,7 @@ using FluentAssertions; using System; using System.Threading.Tasks; +using Timeline.Services; using Timeline.Services.User; using Xunit; @@ -17,7 +18,7 @@ namespace Timeline.Tests.Services protected override void OnInitialize() { - _service = new UserPermissionService(Database); + _service = new UserPermissionService(Database, UserService); } [Fact] @@ -37,7 +38,7 @@ namespace Timeline.Tests.Services [Fact] public async Task GetPermissionsOfInexistentUserShouldThrow() { - await _service.Awaiting(s => s.GetPermissionsOfUserAsync(10)).Should().ThrowAsync(); + await _service.Awaiting(s => s.GetPermissionsOfUserAsync(10)).Should().ThrowAsync(); } [Fact] @@ -91,13 +92,13 @@ namespace Timeline.Tests.Services [Fact] public async Task AddPermissionToInexistentUserShouldThrown() { - await _service.Awaiting(s => s.AddPermissionToUserAsync(10, UserPermission.HighlightTimelineManagement)).Should().ThrowAsync(); + await _service.Awaiting(s => s.AddPermissionToUserAsync(10, UserPermission.HighlightTimelineManagement)).Should().ThrowAsync(); } [Fact] public async Task RemovePermissionFromInexistentUserShouldThrown() { - await _service.Awaiting(s => s.RemovePermissionFromUserAsync(10, UserPermission.HighlightTimelineManagement)).Should().ThrowAsync(); + await _service.Awaiting(s => s.RemovePermissionFromUserAsync(10, UserPermission.HighlightTimelineManagement)).Should().ThrowAsync(); } [Fact] -- cgit v1.2.3