aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-01-19 22:45:43 +0800
committercrupest <crupest@outlook.com>2020-01-19 22:45:43 +0800
commit40eea04e1ec9b71c5215e9dce5a6963ea60cafaa (patch)
tree1fa3969a53138becb76a7eef7bafdafc7046c12c
parent4ec507df6251bc1dae5204fdc6aaf14ddbb268f6 (diff)
downloadtimeline-40eea04e1ec9b71c5215e9dce5a6963ea60cafaa.tar.gz
timeline-40eea04e1ec9b71c5215e9dce5a6963ea60cafaa.tar.bz2
timeline-40eea04e1ec9b71c5215e9dce5a6963ea60cafaa.zip
Basically finish refactor of error codes.
-rw-r--r--Timeline.Tests/Controllers/PersonalTimelineControllerTest.cs12
-rw-r--r--Timeline.Tests/Controllers/TokenControllerTest.cs13
-rw-r--r--Timeline.Tests/Controllers/UserControllerTest.cs12
-rw-r--r--Timeline.Tests/ErrorCodeTest.cs1
-rw-r--r--Timeline.Tests/Helpers/ResponseAssertions.cs12
-rw-r--r--Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs6
-rw-r--r--Timeline.Tests/IntegratedTests/TokenTest.cs9
-rw-r--r--Timeline.Tests/IntegratedTests/UserAvatarTest.cs33
-rw-r--r--Timeline.Tests/IntegratedTests/UserDetailTest.cs7
-rw-r--r--Timeline.Tests/IntegratedTests/UserTest.cs11
-rw-r--r--Timeline/Controllers/PersonalTimelineController.cs3
-rw-r--r--Timeline/Controllers/TokenController.cs4
-rw-r--r--Timeline/Controllers/UserAvatarController.cs4
13 files changed, 65 insertions, 62 deletions
diff --git a/Timeline.Tests/Controllers/PersonalTimelineControllerTest.cs b/Timeline.Tests/Controllers/PersonalTimelineControllerTest.cs
index 372ba8a7..bbc8ba75 100644
--- a/Timeline.Tests/Controllers/PersonalTimelineControllerTest.cs
+++ b/Timeline.Tests/Controllers/PersonalTimelineControllerTest.cs
@@ -142,7 +142,7 @@ namespace Timeline.Tests.Controllers
.Which;
result.StatusCode.Should().Be(StatusCodes.Status403Forbidden);
result.Value.Should().BeAssignableTo<CommonResponse>()
- .Which.Code.Should().Be(ErrorCodes.Http.Timeline.PostListGetForbid);
+ .Which.Code.Should().Be(ErrorCodes.Common.Forbid);
_service.VerifyAll();
}
@@ -185,7 +185,7 @@ namespace Timeline.Tests.Controllers
})).Result.Should().NotBeNull().And.BeAssignableTo<ObjectResult>().Which;
result.StatusCode.Should().Be(StatusCodes.Status403Forbidden);
result.Value.Should().BeAssignableTo<CommonResponse>()
- .Which.Code.Should().Be(ErrorCodes.Http.Timeline.PostOperationCreateForbid);
+ .Which.Code.Should().Be(ErrorCodes.Common.Forbid);
_service.VerifyAll();
}
@@ -249,7 +249,7 @@ namespace Timeline.Tests.Controllers
})).Should().NotBeNull().And.BeAssignableTo<ObjectResult>().Which;
result.StatusCode.Should().Be(StatusCodes.Status403Forbidden);
result.Value.Should().BeAssignableTo<CommonResponse>()
- .Which.Code.Should().Be(ErrorCodes.Http.Timeline.PostOperationDeleteForbid);
+ .Which.Code.Should().Be(ErrorCodes.Common.Forbid);
_service.VerifyAll();
}
@@ -266,7 +266,7 @@ namespace Timeline.Tests.Controllers
})).Should().NotBeNull().And.BeAssignableTo<ObjectResult>().Which;
result.StatusCode.Should().Be(StatusCodes.Status400BadRequest);
result.Value.Should().BeAssignableTo<CommonResponse>()
- .Which.Code.Should().Be(ErrorCodes.Http.Timeline.PostOperationDeleteNotExist);
+ .Which.Code.Should().Be(ErrorCodes.TimelineController.PostOperationDelete_NotExist);
_service.VerifyAll();
}
@@ -347,7 +347,7 @@ namespace Timeline.Tests.Controllers
});
result.Should().NotBeNull().And.BeAssignableTo<BadRequestObjectResult>()
.Which.Value.Should().BeAssignableTo<CommonResponse>()
- .Which.Code.Should().Be(ErrorCodes.Http.Common.InvalidModel);
+ .Which.Code.Should().Be(ErrorCodes.Common.InvalidModel);
_service.VerifyAll();
}
@@ -366,7 +366,7 @@ namespace Timeline.Tests.Controllers
});
result.Should().NotBeNull().And.BeAssignableTo<BadRequestObjectResult>()
.Which.Value.Should().BeAssignableTo<CommonResponse>()
- .Which.Code.Should().Be(ErrorCodes.Http.Timeline.ChangeMemberUserNotExist);
+ .Which.Code.Should().Be(ErrorCodes.UserCommon.NotExist);
_service.VerifyAll();
}
diff --git a/Timeline.Tests/Controllers/TokenControllerTest.cs b/Timeline.Tests/Controllers/TokenControllerTest.cs
index 371884bb..2b3547ea 100644
--- a/Timeline.Tests/Controllers/TokenControllerTest.cs
+++ b/Timeline.Tests/Controllers/TokenControllerTest.cs
@@ -10,7 +10,6 @@ using Timeline.Models.Http;
using Timeline.Services;
using Timeline.Tests.Helpers;
using Xunit;
-using static Timeline.ErrorCodes.Token;
namespace Timeline.Tests.Controllers
{
@@ -67,7 +66,7 @@ namespace Timeline.Tests.Controllers
});
action.Result.Should().BeAssignableTo<BadRequestObjectResult>()
.Which.Value.Should().BeAssignableTo<CommonResponse>()
- .Which.Code.Should().Be(Create.BadCredential);
+ .Which.Code.Should().Be(ErrorCodes.TokenController.Create_BadCredential);
}
[Fact]
@@ -82,7 +81,7 @@ namespace Timeline.Tests.Controllers
});
action.Result.Should().BeAssignableTo<BadRequestObjectResult>()
.Which.Value.Should().BeAssignableTo<CommonResponse>()
- .Which.Code.Should().Be(Create.BadCredential);
+ .Which.Code.Should().Be(ErrorCodes.TokenController.Create_BadCredential);
}
[Fact]
@@ -98,10 +97,10 @@ namespace Timeline.Tests.Controllers
public static IEnumerable<object[]> Verify_BadRequest_Data()
{
- yield return new object[] { new JwtVerifyException(JwtVerifyException.ErrorCodes.Expired), Verify.TimeExpired };
- yield return new object[] { new JwtVerifyException(JwtVerifyException.ErrorCodes.IdClaimBadFormat), Verify.BadFormat };
- yield return new object[] { new JwtVerifyException(JwtVerifyException.ErrorCodes.OldVersion), Verify.OldVersion };
- yield return new object[] { new UserNotExistException(), Verify.UserNotExist };
+ yield return new object[] { new JwtVerifyException(JwtVerifyException.ErrorCodes.Expired), ErrorCodes.TokenController.Verify_TimeExpired };
+ yield return new object[] { new JwtVerifyException(JwtVerifyException.ErrorCodes.IdClaimBadFormat), ErrorCodes.TokenController.Verify_BadFormat };
+ yield return new object[] { new JwtVerifyException(JwtVerifyException.ErrorCodes.OldVersion), ErrorCodes.TokenController.Verify_OldVersion };
+ yield return new object[] { new UserNotExistException(), ErrorCodes.TokenController.Verify_UserNotExist };
}
[Theory]
diff --git a/Timeline.Tests/Controllers/UserControllerTest.cs b/Timeline.Tests/Controllers/UserControllerTest.cs
index 7a6541fb..043062c3 100644
--- a/Timeline.Tests/Controllers/UserControllerTest.cs
+++ b/Timeline.Tests/Controllers/UserControllerTest.cs
@@ -13,8 +13,6 @@ using Timeline.Models.Http;
using Timeline.Services;
using Timeline.Tests.Helpers;
using Xunit;
-using static Timeline.ErrorCodes.User;
-using static Timeline.ErrorCodes.UserCommon;
namespace Timeline.Tests.Controllers
{
@@ -62,7 +60,7 @@ namespace Timeline.Tests.Controllers
var action = await _controller.Get(username);
action.Result.Should().BeAssignableTo<NotFoundObjectResult>()
.Which.Value.Should().BeAssignableTo<CommonResponse>()
- .Which.Code.Should().Be(UserNotExist);
+ .Which.Code.Should().Be(ErrorCodes.UserCommon.NotExist);
}
[Theory]
@@ -115,7 +113,7 @@ namespace Timeline.Tests.Controllers
}, username);
action.Should().BeAssignableTo<NotFoundObjectResult>()
.Which.Value.Should().BeAssignableTo<CommonResponse>()
- .Which.Code.Should().Be(UserNotExist);
+ .Which.Code.Should().Be(ErrorCodes.UserCommon.NotExist);
}
[Fact]
@@ -155,8 +153,8 @@ namespace Timeline.Tests.Controllers
}
[Theory]
- [InlineData(typeof(UserNotExistException), UserNotExist)]
- [InlineData(typeof(UsernameConfictException), ChangeUsername_Conflict)]
+ [InlineData(typeof(UserNotExistException), ErrorCodes.UserCommon.NotExist)]
+ [InlineData(typeof(UsernameConfictException), ErrorCodes.UserController.ChangeUsername_Conflict)]
public async Task Op_ChangeUsername_Failure(Type exceptionType, int code)
{
const string oldUsername = "aaa";
@@ -213,7 +211,7 @@ namespace Timeline.Tests.Controllers
var action = await _controller.ChangePassword(new ChangePasswordRequest { OldPassword = oldPassword, NewPassword = newPassword });
action.Should().BeAssignableTo<BadRequestObjectResult>()
.Which.Value.Should().BeAssignableTo<CommonResponse>()
- .Which.Code.Should().Be(ChangePassword_BadOldPassword);
+ .Which.Code.Should().Be(ErrorCodes.UserController.ChangePassword_BadOldPassword);
}
}
}
diff --git a/Timeline.Tests/ErrorCodeTest.cs b/Timeline.Tests/ErrorCodeTest.cs
index 78a58131..258ebf4e 100644
--- a/Timeline.Tests/ErrorCodeTest.cs
+++ b/Timeline.Tests/ErrorCodeTest.cs
@@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
+using Timeline.Models.Http;
using Xunit;
using Xunit.Abstractions;
diff --git a/Timeline.Tests/Helpers/ResponseAssertions.cs b/Timeline.Tests/Helpers/ResponseAssertions.cs
index 301ceef6..be0043dc 100644
--- a/Timeline.Tests/Helpers/ResponseAssertions.cs
+++ b/Timeline.Tests/Helpers/ResponseAssertions.cs
@@ -3,6 +3,7 @@ using FluentAssertions.Execution;
using FluentAssertions.Formatting;
using FluentAssertions.Primitives;
using System;
+using System.Globalization;
using System.Net;
using System.Net.Http;
using System.Text;
@@ -147,14 +148,21 @@ namespace Timeline.Tests.Helpers
body.Data.Delete.Should().Be(delete);
}
+ public static void HaveCommonResponseBody(this HttpResponseMessageAssertions assertions, int code, string message = null, params object[] messageArgs)
+ {
+ message = string.IsNullOrEmpty(message) ? "" : ", " + string.Format(CultureInfo.CurrentCulture, message, messageArgs);
+ var body = assertions.HaveJsonBody<CommonResponse>("Response body should be CommonResponse{0}", message).Which;
+ body.Code.Should().Be(code, "Response body code is not the specified one{0}", message);
+ }
+
public static void BeInvalidModel(this HttpResponseMessageAssertions assertions, string message = null)
{
message = string.IsNullOrEmpty(message) ? "" : ", " + message;
assertions.HaveStatusCode(400, "Invalid Model Error must have 400 status code{0}", message)
.And.HaveCommonBody("Invalid Model Error must have CommonResponse body{0}", message)
- .Which.Code.Should().Be(ErrorCodes.Http.Common.InvalidModel,
+ .Which.Code.Should().Be(ErrorCodes.Common.InvalidModel,
"Invalid Model Error must have code {0} in body{1}",
- ErrorCodes.Http.Common.InvalidModel, message);
+ ErrorCodes.Common.InvalidModel, message);
}
}
}
diff --git a/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs b/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs
index c5d0addd..51e2d05e 100644
--- a/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs
+++ b/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs
@@ -98,14 +98,14 @@ namespace Timeline.Tests.IntegratedTests
new TimelineMemberChangeRequest { Add = new List<string> { "admin", "usernotexist" } });
res.Should().HaveStatusCode(400)
.And.HaveCommonBody()
- .Which.Code.Should().Be(ErrorCodes.Http.Timeline.ChangeMemberUserNotExist);
+ .Which.Code.Should().Be(ErrorCodes.UserCommon.NotExist);
}
{
var res = await client.PostAsJsonAsync(changeUrl,
new TimelineMemberChangeRequest { Remove = new List<string> { "admin", "usernotexist" } });
res.Should().HaveStatusCode(400)
.And.HaveCommonBody()
- .Which.Code.Should().Be(ErrorCodes.Http.Timeline.ChangeMemberUserNotExist);
+ .Which.Code.Should().Be(ErrorCodes.UserCommon.NotExist);
}
{
var res = await client.PostAsJsonAsync(changeUrl,
@@ -453,7 +453,7 @@ namespace Timeline.Tests.IntegratedTests
new TimelinePostDeleteRequest { Id = 30000 });
res.Should().HaveStatusCode(400)
.And.HaveCommonBody()
- .Which.Code.Should().Be(ErrorCodes.Http.Timeline.PostOperationDeleteNotExist);
+ .Which.Code.Should().Be(ErrorCodes.TimelineController.PostOperationDelete_NotExist);
}
{
var res = await client.GetAsync("users/user/timeline/posts");
diff --git a/Timeline.Tests/IntegratedTests/TokenTest.cs b/Timeline.Tests/IntegratedTests/TokenTest.cs
index e62228fc..ecd5d0b8 100644
--- a/Timeline.Tests/IntegratedTests/TokenTest.cs
+++ b/Timeline.Tests/IntegratedTests/TokenTest.cs
@@ -8,7 +8,6 @@ using Timeline.Models.Http;
using Timeline.Services;
using Timeline.Tests.Helpers;
using Xunit;
-using static Timeline.ErrorCodes.Http.Token;
namespace Timeline.Tests.IntegratedTests
{
@@ -66,7 +65,7 @@ namespace Timeline.Tests.IntegratedTests
new CreateTokenRequest { Username = username, Password = password });
response.Should().HaveStatusCode(400)
.And.HaveCommonBody()
- .Which.Code.Should().Be(Create.BadCredential);
+ .Which.Code.Should().Be(ErrorCodes.TokenController.Create_BadCredential);
}
[Fact]
@@ -97,7 +96,7 @@ namespace Timeline.Tests.IntegratedTests
new VerifyTokenRequest { Token = "bad token hahaha" });
response.Should().HaveStatusCode(400)
.And.HaveCommonBody()
- .Which.Code.Should().Be(Verify.BadFormat);
+ .Which.Code.Should().Be(ErrorCodes.TokenController.Verify_BadFormat);
}
[Fact]
@@ -117,7 +116,7 @@ namespace Timeline.Tests.IntegratedTests
new VerifyTokenRequest { Token = token }))
.Should().HaveStatusCode(400)
.And.HaveCommonBody()
- .Which.Code.Should().Be(Verify.OldVersion);
+ .Which.Code.Should().Be(ErrorCodes.TokenController.Verify_OldVersion);
}
[Fact]
@@ -136,7 +135,7 @@ namespace Timeline.Tests.IntegratedTests
new VerifyTokenRequest { Token = token }))
.Should().HaveStatusCode(400)
.And.HaveCommonBody()
- .Which.Code.Should().Be(Verify.UserNotExist);
+ .Which.Code.Should().Be(ErrorCodes.TokenController.Verify_UserNotExist);
}
//[Fact]
diff --git a/Timeline.Tests/IntegratedTests/UserAvatarTest.cs b/Timeline.Tests/IntegratedTests/UserAvatarTest.cs
index 25a7b675..a4e10634 100644
--- a/Timeline.Tests/IntegratedTests/UserAvatarTest.cs
+++ b/Timeline.Tests/IntegratedTests/UserAvatarTest.cs
@@ -13,11 +13,10 @@ using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
+using Timeline.Models.Http;
using Timeline.Services;
using Timeline.Tests.Helpers;
using Xunit;
-using static Timeline.ErrorCodes.Http.Common;
-using static Timeline.ErrorCodes.Http.UserAvatar;
namespace Timeline.Tests.IntegratedTests
{
@@ -45,7 +44,7 @@ namespace Timeline.Tests.IntegratedTests
var res = await client.GetAsync("users/usernotexist/avatar");
res.Should().HaveStatusCode(404)
.And.HaveCommonBody()
- .Which.Code.Should().Be(Get.UserNotExist);
+ .Which.Code.Should().Be(ErrorCodes.UserCommon.NotExist);
}
var env = Factory.Server.Host.Services.GetRequiredService<IWebHostEnvironment>();
@@ -85,7 +84,7 @@ namespace Timeline.Tests.IntegratedTests
request.Headers.TryAddWithoutValidation("If-None-Match", "\"dsdfd");
var res = await client.SendAsync(request);
res.Should().HaveStatusCode(HttpStatusCode.BadRequest)
- .And.HaveCommonBody().Which.Code.Should().Be(Header.IfNonMatch.BadFormat);
+ .And.HaveCommonBody().Which.Code.Should().Be(ErrorCodes.Common.Header.IfNonMatch_BadFormat);
}
{
@@ -115,7 +114,7 @@ namespace Timeline.Tests.IntegratedTests
content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
var res = await client.PutAsync("users/user/avatar", content);
res.Should().HaveStatusCode(HttpStatusCode.BadRequest)
- .And.HaveCommonBody().Which.Code.Should().Be(ErrorCodes.Http.Filter.Header.ContentLength.Missing); ;
+ .And.HaveCommonBody().Which.Code.Should().Be(ErrorCodes.Common.Header.ContentLength_Missing); ;
}
{
@@ -123,7 +122,7 @@ namespace Timeline.Tests.IntegratedTests
content.Headers.ContentLength = 1;
var res = await client.PutAsync("users/user/avatar", content);
res.Should().HaveStatusCode(HttpStatusCode.BadRequest)
- .And.HaveCommonBody().Which.Code.Should().Be(ErrorCodes.Http.Filter.Header.ContentType.Missing);
+ .And.HaveCommonBody().Which.Code.Should().Be(ErrorCodes.Common.Header.ContentType_Missing);
}
{
@@ -132,7 +131,7 @@ namespace Timeline.Tests.IntegratedTests
content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
var res = await client.PutAsync("users/user/avatar", content);
res.Should().HaveStatusCode(HttpStatusCode.BadRequest)
- .And.HaveCommonBody().Which.Code.Should().Be(ErrorCodes.Http.Filter.Header.ContentLength.Zero);
+ .And.HaveCommonBody().Which.Code.Should().Be(ErrorCodes.Common.Header.ContentLength_Zero);
}
{
@@ -146,7 +145,7 @@ namespace Timeline.Tests.IntegratedTests
content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
var res = await client.PutAsync("users/user/avatar", content);
res.Should().HaveStatusCode(HttpStatusCode.BadRequest)
- .And.HaveCommonBody().Which.Code.Should().Be(Content.TooBig);
+ .And.HaveCommonBody().Which.Code.Should().Be(ErrorCodes.Common.Content.TooBig);
}
{
@@ -155,7 +154,7 @@ namespace Timeline.Tests.IntegratedTests
content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
var res = await client.PutAsync("users/user/avatar", content);
res.Should().HaveStatusCode(HttpStatusCode.BadRequest)
- .And.HaveCommonBody().Which.Code.Should().Be(Content.UnmatchedLength_Smaller);
+ .And.HaveCommonBody().Which.Code.Should().Be(ErrorCodes.Common.Content.UnmatchedLength_Smaller);
}
{
@@ -164,25 +163,25 @@ namespace Timeline.Tests.IntegratedTests
content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
var res = await client.PutAsync("users/user/avatar", content);
res.Should().HaveStatusCode(HttpStatusCode.BadRequest)
- .And.HaveCommonBody().Which.Code.Should().Be(Content.UnmatchedLength_Bigger);
+ .And.HaveCommonBody().Which.Code.Should().Be(ErrorCodes.Common.Content.UnmatchedLength_Bigger);
}
{
var res = await client.PutByteArrayAsync("users/user/avatar", new[] { (byte)0x00 }, "image/png");
res.Should().HaveStatusCode(HttpStatusCode.BadRequest)
- .And.HaveCommonBody().Which.Code.Should().Be(Put.BadFormat_CantDecode);
+ .And.HaveCommonBody().Which.Code.Should().Be(ErrorCodes.UserAvatar.BadFormat_CantDecode);
}
{
var res = await client.PutByteArrayAsync("users/user/avatar", mockAvatar.Data, "image/jpeg");
res.Should().HaveStatusCode(HttpStatusCode.BadRequest)
- .And.HaveCommonBody().Which.Code.Should().Be(Put.BadFormat_UnmatchedFormat);
+ .And.HaveCommonBody().Which.Code.Should().Be(ErrorCodes.UserAvatar.BadFormat_UnmatchedFormat);
}
{
var res = await client.PutByteArrayAsync("users/user/avatar", ImageHelper.CreatePngWithSize(100, 200), "image/png");
res.Should().HaveStatusCode(HttpStatusCode.BadRequest)
- .And.HaveCommonBody().Which.Code.Should().Be(Put.BadFormat_BadSize);
+ .And.HaveCommonBody().Which.Code.Should().Be(ErrorCodes.UserAvatar.BadFormat_BadSize);
}
{
@@ -212,13 +211,13 @@ namespace Timeline.Tests.IntegratedTests
{
var res = await client.PutByteArrayAsync("users/admin/avatar", new[] { (byte)0x00 }, "image/png");
res.Should().HaveStatusCode(HttpStatusCode.Forbidden)
- .And.HaveCommonBody().Which.Code.Should().Be(Put.Forbid);
+ .And.HaveCommonBody().Which.Code.Should().Be(ErrorCodes.Common.Forbid);
}
{
var res = await client.DeleteAsync("users/admin/avatar");
res.Should().HaveStatusCode(HttpStatusCode.Forbidden)
- .And.HaveCommonBody().Which.Code.Should().Be(Delete.Forbid);
+ .And.HaveCommonBody().Which.Code.Should().Be(ErrorCodes.Common.Forbid);
}
for (int i = 0; i < 2; i++) // double delete should work.
@@ -246,13 +245,13 @@ namespace Timeline.Tests.IntegratedTests
var res = await client.PutByteArrayAsync("users/usernotexist/avatar", new[] { (byte)0x00 }, "image/png");
res.Should().HaveStatusCode(400)
.And.HaveCommonBody()
- .Which.Code.Should().Be(Put.UserNotExist);
+ .Which.Code.Should().Be(ErrorCodes.UserCommon.NotExist);
}
{
var res = await client.DeleteAsync("users/usernotexist/avatar");
res.Should().HaveStatusCode(400)
- .And.HaveCommonBody().Which.Code.Should().Be(Delete.UserNotExist);
+ .And.HaveCommonBody().Which.Code.Should().Be(ErrorCodes.UserCommon.NotExist);
}
}
diff --git a/Timeline.Tests/IntegratedTests/UserDetailTest.cs b/Timeline.Tests/IntegratedTests/UserDetailTest.cs
index 932c287e..3781a816 100644
--- a/Timeline.Tests/IntegratedTests/UserDetailTest.cs
+++ b/Timeline.Tests/IntegratedTests/UserDetailTest.cs
@@ -4,6 +4,7 @@ using System.Net;
using System.Net.Http.Headers;
using System.Net.Mime;
using System.Threading.Tasks;
+using Timeline.Models.Http;
using Timeline.Tests.Helpers;
using Xunit;
@@ -82,7 +83,7 @@ namespace Timeline.Tests.IntegratedTests
var res = await client.GetAsync(userNotExistUrl);
res.Should().HaveStatusCode(HttpStatusCode.NotFound)
.And.HaveCommonBody()
- .Which.Code.Should().Be(ErrorCodes.Http.Filter.User.NotExist);
+ .Which.Code.Should().Be(ErrorCodes.UserCommon.NotExist);
}
{
@@ -128,13 +129,13 @@ namespace Timeline.Tests.IntegratedTests
var res = await client.PutStringAsync(userNotExistUrl, "aaa");
res.Should().HaveStatusCode(HttpStatusCode.BadRequest)
.And.HaveCommonBody()
- .Which.Code.Should().Be(ErrorCodes.Http.Filter.User.NotExist);
+ .Which.Code.Should().Be(ErrorCodes.UserCommon.NotExist);
}
{
var res = await client.DeleteAsync(userNotExistUrl);
res.Should().HaveStatusCode(HttpStatusCode.BadRequest)
.And.HaveCommonBody()
- .Which.Code.Should().Be(ErrorCodes.Http.Filter.User.NotExist);
+ .Which.Code.Should().Be(ErrorCodes.UserCommon.NotExist);
}
var nickname = "nnn";
{
diff --git a/Timeline.Tests/IntegratedTests/UserTest.cs b/Timeline.Tests/IntegratedTests/UserTest.cs
index abfea18e..fbef6da3 100644
--- a/Timeline.Tests/IntegratedTests/UserTest.cs
+++ b/Timeline.Tests/IntegratedTests/UserTest.cs
@@ -7,7 +7,6 @@ using Timeline.Models;
using Timeline.Models.Http;
using Timeline.Tests.Helpers;
using Xunit;
-using static Timeline.ErrorCodes.Http.User;
namespace Timeline.Tests.IntegratedTests
{
@@ -54,7 +53,7 @@ namespace Timeline.Tests.IntegratedTests
var res = await client.GetAsync("users/usernotexist");
res.Should().HaveStatusCode(404)
.And.HaveCommonBody()
- .Which.Code.Should().Be(Get.NotExist);
+ .Which.Code.Should().Be(ErrorCodes.UserCommon.NotExist);
}
public static IEnumerable<object[]> Put_InvalidModel_Data()
@@ -118,7 +117,7 @@ namespace Timeline.Tests.IntegratedTests
var res = await client.PatchAsJsonAsync("users/usernotexist", new UserPatchRequest { });
res.Should().HaveStatusCode(404)
.And.HaveCommonBody()
- .Which.Code.Should().Be(Patch.NotExist);
+ .Which.Code.Should().Be(ErrorCodes.UserCommon.NotExist);
}
[Fact]
@@ -198,7 +197,7 @@ namespace Timeline.Tests.IntegratedTests
new ChangeUsernameRequest { OldUsername = "usernotexist", NewUsername = "newUsername" });
res.Should().HaveStatusCode(400)
.And.HaveCommonBody()
- .Which.Code.Should().Be(Op.ChangeUsername.NotExist);
+ .Which.Code.Should().Be(ErrorCodes.UserCommon.NotExist);
}
[Fact]
@@ -209,7 +208,7 @@ namespace Timeline.Tests.IntegratedTests
new ChangeUsernameRequest { OldUsername = MockUser.User.Username, NewUsername = MockUser.Admin.Username });
res.Should().HaveStatusCode(400)
.And.HaveCommonBody()
- .Which.Code.Should().Be(Op.ChangeUsername.AlreadyExist);
+ .Which.Code.Should().Be(ErrorCodes.UserController.ChangeUsername_Conflict);
}
private async Task TestLogin(string username, string password)
@@ -256,7 +255,7 @@ namespace Timeline.Tests.IntegratedTests
var res = await client.PostAsJsonAsync(changePasswordUrl, new ChangePasswordRequest { OldPassword = "???", NewPassword = "???" });
res.Should().HaveStatusCode(400)
.And.HaveCommonBody()
- .Which.Code.Should().Be(Op.ChangePassword.BadOldPassword);
+ .Which.Code.Should().Be(ErrorCodes.UserController.ChangePassword_BadOldPassword);
}
[Fact]
diff --git a/Timeline/Controllers/PersonalTimelineController.cs b/Timeline/Controllers/PersonalTimelineController.cs
index e1e3aba0..2c70fad1 100644
--- a/Timeline/Controllers/PersonalTimelineController.cs
+++ b/Timeline/Controllers/PersonalTimelineController.cs
@@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
-using System.Globalization;
using System.Threading.Tasks;
using Timeline.Auth;
using Timeline.Filters;
@@ -134,7 +133,7 @@ namespace Timeline.Controllers
}
else if (e.InnerException is UserNotExistException)
{
- return BadRequest(ErrorResponse.Common.CustomMessage_InvalidModel(
+ return BadRequest(ErrorResponse.UserCommon.CustomMessage_NotExist(
TimelineController_ChangeMember_UserNotExist, e.Index, e.Operation));
}
diff --git a/Timeline/Controllers/TokenController.cs b/Timeline/Controllers/TokenController.cs
index c360a109..67001e87 100644
--- a/Timeline/Controllers/TokenController.cs
+++ b/Timeline/Controllers/TokenController.cs
@@ -99,7 +99,7 @@ namespace Timeline.Controllers
if (e.ErrorCode == JwtVerifyException.ErrorCodes.Expired)
{
var innerException = e.InnerException as SecurityTokenExpiredException;
- LogFailure(LogVerifyExpire, e, ("Expires", innerException.Expires),
+ LogFailure(LogVerifyExpire, e, ("Expires", innerException?.Expires),
("Current Time", _clock.GetCurrentTime()));
return BadRequest(ErrorResponse.TokenController.Verify_TimeExpired());
}
@@ -107,7 +107,7 @@ namespace Timeline.Controllers
{
var innerException = e.InnerException as JwtBadVersionException;
LogFailure(LogVerifyOldVersion, e,
- ("Token Version", innerException.TokenVersion),
+ ("Token Version", innerException?.TokenVersion),
("Required Version", innerException?.RequiredVersion));
return BadRequest(ErrorResponse.TokenController.Verify_OldVersion());
}
diff --git a/Timeline/Controllers/UserAvatarController.cs b/Timeline/Controllers/UserAvatarController.cs
index b4a6d8fd..62f1d78c 100644
--- a/Timeline/Controllers/UserAvatarController.cs
+++ b/Timeline/Controllers/UserAvatarController.cs
@@ -66,7 +66,7 @@ namespace Timeline.Controllers
catch (UserNotExistException e)
{
_logger.LogInformation(e, Log.Format(LogGetUserNotExist, ("Username", username)));
- return NotFound(ErrorResponse.UserController.ChangePassword_BadOldPassword());
+ return NotFound(ErrorResponse.UserCommon.NotExist());
}
}
@@ -112,7 +112,7 @@ namespace Timeline.Controllers
catch (UserNotExistException e)
{
_logger.LogInformation(e, Log.Format(LogPutUserNotExist, ("Username", username)));
- return BadRequest(ErrorResponse.UserController.ChangePassword_BadOldPassword());
+ return BadRequest(ErrorResponse.UserCommon.NotExist());
}
catch (AvatarFormatException e)
{