aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline.Tests
diff options
context:
space:
mode:
Diffstat (limited to 'BackEnd/Timeline.Tests')
-rw-r--r--BackEnd/Timeline.Tests/ErrorCodeTest.cs1
-rw-r--r--BackEnd/Timeline.Tests/IntegratedTests/CacheTestHelper.cs1
-rw-r--r--BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs12
-rw-r--r--BackEnd/Timeline.Tests/IntegratedTests/TokenTest.cs8
-rw-r--r--BackEnd/Timeline.Tests/IntegratedTests/UnknownEndpointTest.cs1
-rw-r--r--BackEnd/Timeline.Tests/IntegratedTests/UserAvatarTest.cs13
-rw-r--r--BackEnd/Timeline.Tests/IntegratedTests/UserPermissionTest.cs9
-rw-r--r--BackEnd/Timeline.Tests/IntegratedTests/UserTest.cs12
-rw-r--r--BackEnd/Timeline.Tests/Services/SearchServiceTest.cs4
-rw-r--r--BackEnd/Timeline.Tests/Services/UserPermissionServiceTest.cs9
-rw-r--r--BackEnd/Timeline.Tests/UsernameValidatorUnitTest.cs3
11 files changed, 34 insertions, 39 deletions
diff --git a/BackEnd/Timeline.Tests/ErrorCodeTest.cs b/BackEnd/Timeline.Tests/ErrorCodeTest.cs
index 94e2a488..0b6d8ed8 100644
--- a/BackEnd/Timeline.Tests/ErrorCodeTest.cs
+++ b/BackEnd/Timeline.Tests/ErrorCodeTest.cs
@@ -3,7 +3,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
-using Timeline.Models.Http;
using Xunit;
using Xunit.Abstractions;
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/CacheTestHelper.cs b/BackEnd/Timeline.Tests/IntegratedTests/CacheTestHelper.cs
index 8308eca8..73210320 100644
--- a/BackEnd/Timeline.Tests/IntegratedTests/CacheTestHelper.cs
+++ b/BackEnd/Timeline.Tests/IntegratedTests/CacheTestHelper.cs
@@ -4,7 +4,6 @@ using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
-using Timeline.Models.Http;
namespace Timeline.Tests.IntegratedTests
{
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<HttpUser> { 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/TokenTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/TokenTest.cs
index 08857dc1..ac96ef9d 100644
--- a/BackEnd/Timeline.Tests/IntegratedTests/TokenTest.cs
+++ b/BackEnd/Timeline.Tests/IntegratedTests/TokenTest.cs
@@ -53,7 +53,7 @@ namespace Timeline.Tests.IntegratedTests
using var client = await CreateDefaultClient();
await client.TestPostAssertErrorAsync(CreateTokenUrl,
new HttpCreateTokenRequest { Username = username, Password = password },
- errorCode: ErrorCodes.TokenController.Create_BadCredential);
+ errorCode: ErrorCodes.TokenController.CreateBadCredential);
}
[Fact]
@@ -79,7 +79,7 @@ namespace Timeline.Tests.IntegratedTests
using var client = await CreateDefaultClient();
await client.TestPostAssertErrorAsync(VerifyTokenUrl,
new HttpVerifyTokenRequest { Token = "bad token hahaha" },
- errorCode: ErrorCodes.TokenController.Verify_BadFormat);
+ errorCode: ErrorCodes.TokenController.VerifyBadFormat);
}
[Fact]
@@ -98,7 +98,7 @@ namespace Timeline.Tests.IntegratedTests
await client.TestPostAssertErrorAsync(VerifyTokenUrl,
new HttpVerifyTokenRequest { Token = token },
- errorCode: ErrorCodes.TokenController.Verify_OldVersion);
+ errorCode: ErrorCodes.TokenController.VerifyOldVersion);
}
[Fact]
@@ -115,7 +115,7 @@ namespace Timeline.Tests.IntegratedTests
await client.TestPostAssertErrorAsync(VerifyTokenUrl,
new HttpVerifyTokenRequest { Token = token },
- errorCode: ErrorCodes.TokenController.Verify_UserNotExist);
+ errorCode: ErrorCodes.TokenController.VerifyUserNotExist);
}
//[Fact]
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/UnknownEndpointTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/UnknownEndpointTest.cs
index 4389c6b4..2b6981ae 100644
--- a/BackEnd/Timeline.Tests/IntegratedTests/UnknownEndpointTest.cs
+++ b/BackEnd/Timeline.Tests/IntegratedTests/UnknownEndpointTest.cs
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
-using Timeline.Models.Http;
using Xunit;
namespace Timeline.Tests.IntegratedTests
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/UserAvatarTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/UserAvatarTest.cs
index 708120b1..e8c42d58 100644
--- a/BackEnd/Timeline.Tests/IntegratedTests/UserAvatarTest.cs
+++ b/BackEnd/Timeline.Tests/IntegratedTests/UserAvatarTest.cs
@@ -12,7 +12,6 @@ using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Timeline.Models;
-using Timeline.Models.Http;
using Timeline.Tests.Helpers;
using Xunit;
@@ -30,7 +29,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<IWebHostEnvironment>();
var defaultAvatarData = await File.ReadAllBytesAsync(Path.Combine(env.ContentRootPath, "default-avatar.png"));
@@ -99,9 +98,9 @@ namespace Timeline.Tests.IntegratedTests
}
{
- await client.TestPutByteArrayAssertErrorAsync("users/user1/avatar", new[] { (byte)0x00 }, "image/png", errorCode: ErrorCodes.UserAvatar.BadFormat_CantDecode);
- await client.TestPutByteArrayAssertErrorAsync("users/user1/avatar", mockAvatar.Data, "image/jpeg", errorCode: ErrorCodes.UserAvatar.BadFormat_UnmatchedFormat);
- await client.TestPutByteArrayAssertErrorAsync("users/user1/avatar", ImageHelper.CreatePngWithSize(100, 200), "image/png", errorCode: ErrorCodes.UserAvatar.BadFormat_BadSize);
+ await client.TestPutByteArrayAssertErrorAsync("users/user1/avatar", new[] { (byte)0x00 }, "image/png", errorCode: ErrorCodes.Image.CantDecode);
+ await client.TestPutByteArrayAssertErrorAsync("users/user1/avatar", mockAvatar.Data, "image/jpeg", errorCode: ErrorCodes.Image.UnmatchedFormat);
+ await client.TestPutByteArrayAssertErrorAsync("users/user1/avatar", ImageHelper.CreatePngWithSize(100, 200), "image/png", errorCode: ErrorCodes.Image.BadSize);
}
{
@@ -138,8 +137,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..bdb376de 100644
--- a/BackEnd/Timeline.Tests/IntegratedTests/UserPermissionTest.cs
+++ b/BackEnd/Timeline.Tests/IntegratedTests/UserPermissionTest.cs
@@ -3,7 +3,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
-using Timeline.Models.Http;
using Timeline.Services.User;
using Xunit;
@@ -41,10 +40,10 @@ namespace Timeline.Tests.IntegratedTests
using var client = await CreateClientAsAdministrator();
await client.TestPutAssertErrorAsync($"users/admin/permissions/{permission}",
- errorCode: ErrorCodes.UserController.ChangePermission_RootUser);
+ errorCode: ErrorCodes.UserController.InvalidOperationOnRootUser);
await client.TestDeleteAssertErrorAsync($"users/admin/permissions/{permission}",
- errorCode: ErrorCodes.UserController.ChangePermission_RootUser);
+ errorCode: ErrorCodes.UserController.InvalidOperationOnRootUser);
}
[Theory]
@@ -190,8 +189,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..d34bcaf9 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]
@@ -183,7 +183,7 @@ namespace Timeline.Tests.IntegratedTests
public async Task DeleteRootUser_Should_Error()
{
using var client = await CreateClientAsAdministrator();
- await client.TestDeleteAssertErrorAsync("users/admin", errorCode: ErrorCodes.UserController.Delete_RootUser);
+ await client.TestDeleteAssertErrorAsync("users/admin", errorCode: ErrorCodes.UserController.InvalidOperationOnRootUser);
}
[Fact]
@@ -255,7 +255,7 @@ namespace Timeline.Tests.IntegratedTests
{
Username = "user1",
Password = "bbb",
- }, errorCode: ErrorCodes.UserController.UsernameConflict);
+ }, errorCode: ErrorCodes.Conflict.User);
}
[Fact]
@@ -310,7 +310,7 @@ namespace Timeline.Tests.IntegratedTests
public async Task Op_ChangePassword_BadOldPassword()
{
using var client = await CreateClientAsUser();
- await client.TestPostAssertErrorAsync(changePasswordUrl, new HttpChangePasswordRequest { OldPassword = "???", NewPassword = "???" }, errorCode: ErrorCodes.UserController.ChangePassword_BadOldPassword);
+ await client.TestPostAssertErrorAsync(changePasswordUrl, new HttpChangePasswordRequest { OldPassword = "???", NewPassword = "???" }, errorCode: ErrorCodes.UserController.ChangePasswordBadOldPassword);
}
[Fact]
diff --git a/BackEnd/Timeline.Tests/Services/SearchServiceTest.cs b/BackEnd/Timeline.Tests/Services/SearchServiceTest.cs
index 1c96eb34..6e3c0f40 100644
--- a/BackEnd/Timeline.Tests/Services/SearchServiceTest.cs
+++ b/BackEnd/Timeline.Tests/Services/SearchServiceTest.cs
@@ -24,7 +24,7 @@ namespace Timeline.Tests.Services
await TimelineService.ChangePropertyAsync(t2.Id, new TimelineChangePropertyParams { Title = "hahaha" });
await TimelineService.CreateTimelineAsync("bbbbbb", UserId);
- var searchResult = await _service.SearchTimeline("hah");
+ var searchResult = await _service.SearchTimelineAsync("hah");
searchResult.Items.Should().HaveCount(2);
searchResult.Items[0].Item.Name.Should().Be("hahaha");
searchResult.Items[0].Score.Should().Be(2);
@@ -40,7 +40,7 @@ namespace Timeline.Tests.Services
await UserService.ModifyUserAsync(u2.Id, new ModifyUserParams { Nickname = "hahaha" });
await UserService.CreateUserAsync(new CreateUserParams("bbbbbb", "p"));
- var searchResult = await _service.SearchUser("hah");
+ var searchResult = await _service.SearchUserAsync("hah");
searchResult.Items.Should().HaveCount(2);
searchResult.Items[0].Item.Username.Should().Be("hahaha");
searchResult.Items[0].Score.Should().Be(2);
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<UserNotExistException>();
+ await _service.Awaiting(s => s.GetPermissionsOfUserAsync(10)).Should().ThrowAsync<EntityNotExistException>();
}
[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<UserNotExistException>();
+ await _service.Awaiting(s => s.AddPermissionToUserAsync(10, UserPermission.HighlightTimelineManagement)).Should().ThrowAsync<EntityNotExistException>();
}
[Fact]
public async Task RemovePermissionFromInexistentUserShouldThrown()
{
- await _service.Awaiting(s => s.RemovePermissionFromUserAsync(10, UserPermission.HighlightTimelineManagement)).Should().ThrowAsync<UserNotExistException>();
+ await _service.Awaiting(s => s.RemovePermissionFromUserAsync(10, UserPermission.HighlightTimelineManagement)).Should().ThrowAsync<EntityNotExistException>();
}
[Fact]
diff --git a/BackEnd/Timeline.Tests/UsernameValidatorUnitTest.cs b/BackEnd/Timeline.Tests/UsernameValidatorUnitTest.cs
index 7022b311..9e845641 100644
--- a/BackEnd/Timeline.Tests/UsernameValidatorUnitTest.cs
+++ b/BackEnd/Timeline.Tests/UsernameValidatorUnitTest.cs
@@ -41,8 +41,7 @@ namespace Timeline.Tests
[InlineData("ab c!")] // This is a chinese ! .
public void BadCharactor(string value)
{
- FailAndMessage(value).Should().ContainEquivalentOf("invalid")
- .And.ContainEquivalentOf("character");
+ FailAndMessage(value).Should().ContainEquivalentOf("only consists of");
}
[Fact]