From 3f4e88757f961532b84df85e86d21995655a29d4 Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 27 Nov 2020 00:07:09 +0800 Subject: refactor: ... --- .../HttpClientTimelineExtensions.cs | 8 +- .../IntegratedTests/HttpClientUserExtensions.cs | 4 +- .../IntegratedTests/IntegratedTestBase.cs | 4 +- .../Timeline.Tests/IntegratedTests/TimelineTest.cs | 150 ++++++++++----------- .../Timeline.Tests/IntegratedTests/TokenTest.cs | 24 ++-- BackEnd/Timeline.Tests/IntegratedTests/UserTest.cs | 66 ++++----- 6 files changed, 128 insertions(+), 128 deletions(-) (limited to 'BackEnd/Timeline.Tests/IntegratedTests') diff --git a/BackEnd/Timeline.Tests/IntegratedTests/HttpClientTimelineExtensions.cs b/BackEnd/Timeline.Tests/IntegratedTests/HttpClientTimelineExtensions.cs index 8e48ccbf..ac60ce7c 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/HttpClientTimelineExtensions.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/HttpClientTimelineExtensions.cs @@ -6,11 +6,11 @@ namespace Timeline.Tests.IntegratedTests { public static class HttpClientTimelineExtensions { - public static Task GetTimelineAsync(this HttpClient client, string timelineName) - => client.TestGetAsync($"timelines/{timelineName}"); + public static Task GetTimelineAsync(this HttpClient client, string timelineName) + => client.TestGetAsync($"timelines/{timelineName}"); - public static Task PatchTimelineAsync(this HttpClient client, string timelineName, TimelinePatchRequest body) - => client.TestPatchAsync($"timelines/{timelineName}", body); + public static Task PatchTimelineAsync(this HttpClient client, string timelineName, HttpTimelinePatchRequest body) + => client.TestPatchAsync($"timelines/{timelineName}", body); public static Task PutTimelineMemberAsync(this HttpClient client, string timelineName, string memberUsername) => client.TestPutAsync($"timelines/{timelineName}/members/{memberUsername}"); diff --git a/BackEnd/Timeline.Tests/IntegratedTests/HttpClientUserExtensions.cs b/BackEnd/Timeline.Tests/IntegratedTests/HttpClientUserExtensions.cs index 81787eef..7ca62e38 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/HttpClientUserExtensions.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/HttpClientUserExtensions.cs @@ -6,7 +6,7 @@ namespace Timeline.Tests.IntegratedTests { public static class HttpClientUserExtensions { - public static Task GetUserAsync(this HttpClient client, string username) - => client.TestGetAsync($"users/{username}"); + public static Task GetUserAsync(this HttpClient client, string username) + => client.TestGetAsync($"users/{username}"); } } diff --git a/BackEnd/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs b/BackEnd/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs index e426ac98..82aed24e 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs @@ -103,8 +103,8 @@ namespace Timeline.Tests.IntegratedTests public async Task CreateClientWithCredential(string username, string password, bool setApiBase = true) { var client = await CreateDefaultClient(setApiBase); - var res = await client.TestPostAsync("token/create", - new CreateTokenRequest { Username = username, Password = password }); + var res = await client.TestPostAsync("token/create", + new HttpCreateTokenRequest { Username = username, Password = password }); var token = res.Token; client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token); return client; diff --git a/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs index 9845e1b1..12dd2b8d 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs @@ -19,20 +19,20 @@ namespace Timeline.Tests.IntegratedTests { public static class TimelineHelper { - public static TimelinePostContentInfo TextPostContent(string text) + public static HttpTimelinePostContent TextPostContent(string text) { - return new TimelinePostContentInfo + return new HttpTimelinePostContent { Type = "text", Text = text }; } - public static TimelinePostCreateRequest TextPostCreateRequest(string text, DateTime? time = null) + public static HttpTimelinePostCreateRequest TextPostCreateRequest(string text, DateTime? time = null) { - return new TimelinePostCreateRequest + return new HttpTimelinePostCreateRequest { - Content = new TimelinePostCreateRequestContent + Content = new HttpTimelinePostCreateRequestContent { Type = "text", Text = text @@ -72,7 +72,7 @@ namespace Timeline.Tests.IntegratedTests { - var body = await client.TestGetAsync("timelines/@user1"); + var body = await client.TestGetAsync("timelines/@user1"); body.Owner.Should().BeEquivalentTo(await client.GetUserAsync("user1")); body.Visibility.Should().Be(TimelineVisibility.Register); body.Description.Should().Be(""); @@ -84,7 +84,7 @@ namespace Timeline.Tests.IntegratedTests } { - var body = await client.TestGetAsync("timelines/t1"); + var body = await client.TestGetAsync("timelines/t1"); body.Owner.Should().BeEquivalentTo(await client.GetUserAsync("user1")); body.Visibility.Should().Be(TimelineVisibility.Register); body.Description.Should().Be(""); @@ -101,7 +101,7 @@ namespace Timeline.Tests.IntegratedTests { using var client = await CreateDefaultClient(); - var result = new List + var result = new List { await client.GetTimelineAsync("@user1") }; @@ -112,7 +112,7 @@ namespace Timeline.Tests.IntegratedTests } - var body = await client.TestGetAsync>("timelines"); + var body = await client.TestGetAsync>("timelines"); body.Should().BeEquivalentTo(result); } @@ -127,14 +127,14 @@ namespace Timeline.Tests.IntegratedTests await client.TestGetAssertInvalidModelAsync("timelines?visibility=aaa"); } - var testResultRelate = new List(); - var testResultOwn = new List(); - var testResultJoin = new List(); - var testResultOwnPrivate = new List(); - var testResultRelatePublic = new List(); - var testResultRelateRegister = new List(); - var testResultJoinPrivate = new List(); - var testResultPublic = new List(); + var testResultRelate = new List(); + var testResultOwn = new List(); + var testResultJoin = new List(); + var testResultOwnPrivate = new List(); + var testResultRelatePublic = new List(); + var testResultRelateRegister = new List(); + var testResultJoinPrivate = new List(); + var testResultPublic = new List(); { using var client = await CreateClientAsUser(); @@ -185,8 +185,8 @@ namespace Timeline.Tests.IntegratedTests { using var client = await CreateClientAs(3); - await client.PatchTimelineAsync("@user3", new TimelinePatchRequest { Visibility = TimelineVisibility.Private }); - await client.PatchTimelineAsync("t3", new TimelinePatchRequest { Visibility = TimelineVisibility.Register }); + await client.PatchTimelineAsync("@user3", new HttpTimelinePatchRequest { Visibility = TimelineVisibility.Private }); + await client.PatchTimelineAsync("t3", new HttpTimelinePatchRequest { Visibility = TimelineVisibility.Register }); { var timeline = await client.GetTimelineAsync("@user3"); @@ -206,9 +206,9 @@ namespace Timeline.Tests.IntegratedTests { using var client = await CreateDefaultClient(); - async Task TestAgainst(string url, List against) + async Task TestAgainst(string url, List against) { - var body = await client.TestGetAsync>(url); + var body = await client.TestGetAsync>(url); body.Should().BeEquivalentTo(against); } @@ -236,7 +236,7 @@ namespace Timeline.Tests.IntegratedTests await client.TestPostAssertInvalidModelAsync("timelines", new TimelineCreateRequest { Name = "!!!" }); { - var body = await client.TestPostAsync("timelines", new TimelineCreateRequest { Name = "aaa" }); + var body = await client.TestPostAsync("timelines", new TimelineCreateRequest { Name = "aaa" }); body.Should().BeEquivalentTo(await client.GetTimelineAsync("aaa")); } @@ -342,7 +342,7 @@ namespace Timeline.Tests.IntegratedTests var timelineName = generator(1); - async Task AssertMembers(List members) + async Task AssertMembers(List members) { var body = await client.GetTimelineAsync(timelineName); body.Members.Should().NotBeNull().And.BeEquivalentTo(members); @@ -358,7 +358,7 @@ namespace Timeline.Tests.IntegratedTests await client.TestPutAssertErrorAsync($"timelines/{timelineName}/members/usernotexist", errorCode: ErrorCodes.TimelineController.MemberPut_NotExist); await AssertEmptyMembers(); await client.PutTimelineMemberAsync(timelineName, "user2"); - await AssertMembers(new List { await client.GetUserAsync("user2") }); + await AssertMembers(new List { await client.GetUserAsync("user2") }); await client.DeleteTimelineMemberAsync(timelineName, "user2", true); await AssertEmptyMembers(); await client.DeleteTimelineMemberAsync(timelineName, "aaa", false); @@ -462,7 +462,7 @@ namespace Timeline.Tests.IntegratedTests async Task CreatePost(int userNumber) { using var client = await CreateClientAs(userNumber); - var body = await client.TestPostAsync($"timelines/{generator(1)}/posts", TimelineHelper.TextPostCreateRequest("aaa")); + var body = await client.TestPostAsync($"timelines/{generator(1)}/posts", TimelineHelper.TextPostCreateRequest("aaa")); return body.Id; } @@ -515,28 +515,28 @@ namespace Timeline.Tests.IntegratedTests using var client = await CreateClientAsUser(); { - var body = await client.TestGetAsync>($"timelines/{generator(1)}/posts"); + var body = await client.TestGetAsync>($"timelines/{generator(1)}/posts"); body.Should().BeEmpty(); } const string mockContent = "aaa"; - TimelinePostInfo createRes; + HttpTimelinePost createRes; { - var body = await client.TestPostAsync($"timelines/{generator(1)}/posts", TimelineHelper.TextPostCreateRequest(mockContent)); + var body = await client.TestPostAsync($"timelines/{generator(1)}/posts", TimelineHelper.TextPostCreateRequest(mockContent)); body.Content.Should().BeEquivalentTo(TimelineHelper.TextPostContent(mockContent)); body.Author.Should().BeEquivalentTo(await client.GetUserAsync("user1")); body.Deleted.Should().BeFalse(); createRes = body; } { - var body = await client.TestGetAsync>($"timelines/{generator(1)}/posts"); + var body = await client.TestGetAsync>($"timelines/{generator(1)}/posts"); body.Should().BeEquivalentTo(createRes); } const string mockContent2 = "bbb"; var mockTime2 = DateTime.UtcNow.AddDays(-1); - TimelinePostInfo createRes2; + HttpTimelinePost createRes2; { - var body = await client.TestPostAsync($"timelines/{generator(1)}/posts", TimelineHelper.TextPostCreateRequest(mockContent2, mockTime2)); + var body = await client.TestPostAsync($"timelines/{generator(1)}/posts", TimelineHelper.TextPostCreateRequest(mockContent2, mockTime2)); body.Should().NotBeNull(); body.Content.Should().BeEquivalentTo(TimelineHelper.TextPostContent(mockContent2)); body.Author.Should().BeEquivalentTo(await client.GetUserAsync("user1")); @@ -545,7 +545,7 @@ namespace Timeline.Tests.IntegratedTests createRes2 = body; } { - var body = await client.TestGetAsync>($"timelines/{generator(1)}/posts"); + var body = await client.TestGetAsync>($"timelines/{generator(1)}/posts"); body.Should().BeEquivalentTo(createRes, createRes2); } { @@ -554,7 +554,7 @@ namespace Timeline.Tests.IntegratedTests await client.TestDeleteAsync($"timelines/{generator(1)}/posts/30000", false); } { - var body = await client.TestGetAsync>($"timelines/{generator(1)}/posts"); + var body = await client.TestGetAsync>($"timelines/{generator(1)}/posts"); body.Should().BeEquivalentTo(createRes2); } } @@ -567,7 +567,7 @@ namespace Timeline.Tests.IntegratedTests async Task CreatePost(DateTime time) { - var body = await client.TestPostAsync($"timelines/{generator(1)}/posts", TimelineHelper.TextPostCreateRequest("aaa", time)); + var body = await client.TestPostAsync($"timelines/{generator(1)}/posts", TimelineHelper.TextPostCreateRequest("aaa", time)); return body.Id; } @@ -577,7 +577,7 @@ namespace Timeline.Tests.IntegratedTests var id2 = await CreatePost(now); { - var body = await client.TestGetAsync>($"timelines/{generator(1)}/posts"); + var body = await client.TestGetAsync>($"timelines/{generator(1)}/posts"); body.Select(p => p.Id).Should().Equal(id1, id2, id0); } } @@ -588,15 +588,15 @@ namespace Timeline.Tests.IntegratedTests { using var client = await CreateClientAsUser(); var postUrl = $"timelines/{generator(1)}/posts"; - await client.TestPostAssertInvalidModelAsync(postUrl, new TimelinePostCreateRequest { Content = null! }); - await client.TestPostAssertInvalidModelAsync(postUrl, new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = null! } }); - await client.TestPostAssertInvalidModelAsync(postUrl, new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "hahaha" } }); - await client.TestPostAssertInvalidModelAsync(postUrl, new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "text", Text = null } }); - await client.TestPostAssertInvalidModelAsync(postUrl, new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "image", Data = null } }); + await client.TestPostAssertInvalidModelAsync(postUrl, new HttpTimelinePostCreateRequest { Content = null! }); + await client.TestPostAssertInvalidModelAsync(postUrl, new HttpTimelinePostCreateRequest { Content = new HttpTimelinePostCreateRequestContent { Type = null! } }); + await client.TestPostAssertInvalidModelAsync(postUrl, new HttpTimelinePostCreateRequest { Content = new HttpTimelinePostCreateRequestContent { Type = "hahaha" } }); + await client.TestPostAssertInvalidModelAsync(postUrl, new HttpTimelinePostCreateRequest { Content = new HttpTimelinePostCreateRequestContent { Type = "text", Text = null } }); + await client.TestPostAssertInvalidModelAsync(postUrl, new HttpTimelinePostCreateRequest { Content = new HttpTimelinePostCreateRequestContent { Type = "image", Data = null } }); // image not base64 - await client.TestPostAssertInvalidModelAsync(postUrl, new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "image", Data = "!!!" } }); + await client.TestPostAssertInvalidModelAsync(postUrl, new HttpTimelinePostCreateRequest { Content = new HttpTimelinePostCreateRequestContent { Type = "image", Data = "!!!" } }); // image base64 not image - await client.TestPostAssertInvalidModelAsync(postUrl, new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "image", Data = Convert.ToBase64String(new byte[] { 0x01, 0x02, 0x03 }) } }); + await client.TestPostAssertInvalidModelAsync(postUrl, new HttpTimelinePostCreateRequest { Content = new HttpTimelinePostCreateRequestContent { Type = "image", Data = Convert.ToBase64String(new byte[] { 0x01, 0x02, 0x03 }) } }); } [Theory] @@ -608,7 +608,7 @@ namespace Timeline.Tests.IntegratedTests long postId; string postImageUrl; - void AssertPostContent(TimelinePostContentInfo content) + void AssertPostContent(HttpTimelinePostContent content) { content.Type.Should().Be(TimelinePostContentTypes.Image); content.Url.Should().EndWith($"timelines/{generator(1)}/posts/{postId}/data"); @@ -618,10 +618,10 @@ namespace Timeline.Tests.IntegratedTests using var client = await CreateClientAsUser(); { - var body = await client.TestPostAsync($"timelines/{generator(1)}/posts", - new TimelinePostCreateRequest + var body = await client.TestPostAsync($"timelines/{generator(1)}/posts", + new HttpTimelinePostCreateRequest { - Content = new TimelinePostCreateRequestContent + Content = new HttpTimelinePostCreateRequestContent { Type = TimelinePostContentTypes.Image, Data = Convert.ToBase64String(imageData) @@ -633,7 +633,7 @@ namespace Timeline.Tests.IntegratedTests } { - var body = await client.TestGetAsync>($"timelines/{generator(1)}/posts"); + var body = await client.TestGetAsync>($"timelines/{generator(1)}/posts"); body.Should().HaveCount(1); var post = body[0]; post.Id.Should().Be(postId); @@ -655,7 +655,7 @@ namespace Timeline.Tests.IntegratedTests await client.TestDeleteAsync($"timelines/{generator(1)}/posts/{postId}", false); { - var body = await client.TestGetAsync>($"timelines/{generator(1)}/posts"); + var body = await client.TestGetAsync>($"timelines/{generator(1)}/posts"); body.Should().BeEmpty(); } @@ -677,7 +677,7 @@ namespace Timeline.Tests.IntegratedTests long postId; { - var body = await client.TestPostAsync($"timelines/{generator(1)}/posts", TimelineHelper.TextPostCreateRequest("aaa")); + var body = await client.TestPostAsync($"timelines/{generator(1)}/posts", TimelineHelper.TextPostCreateRequest("aaa")); postId = body.Id; } @@ -726,12 +726,12 @@ namespace Timeline.Tests.IntegratedTests using var client = await CreateClientAsUser(); var postContentList = new List { "a", "b", "c", "d" }; - var posts = new List(); + var posts = new List(); foreach (var content in postContentList) { - var post = await client.TestPostAsync($"timelines/{generator(1)}/posts", - new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Text = content, Type = TimelinePostContentTypes.Text } }); + var post = await client.TestPostAsync($"timelines/{generator(1)}/posts", + new HttpTimelinePostCreateRequest { Content = new HttpTimelinePostCreateRequestContent { Text = content, Type = TimelinePostContentTypes.Text } }); posts.Add(post); await Task.Delay(1000); } @@ -739,7 +739,7 @@ namespace Timeline.Tests.IntegratedTests await client.TestDeleteAsync($"timelines/{generator(1)}/posts/{posts[2].Id}", true); { - var body = await client.TestGetAsync>($"timelines/{generator(1)}/posts?modifiedSince={posts[1].LastUpdated.ToString("s", CultureInfo.InvariantCulture) }"); + var body = await client.TestGetAsync>($"timelines/{generator(1)}/posts?modifiedSince={posts[1].LastUpdated.ToString("s", CultureInfo.InvariantCulture) }"); body.Should().HaveCount(2) .And.Subject.Select(p => p.Content!.Text).Should().Equal("b", "d"); } @@ -752,12 +752,12 @@ namespace Timeline.Tests.IntegratedTests using var client = await CreateClientAsUser(); var postContentList = new List { "a", "b", "c", "d" }; - var posts = new List(); + var posts = new List(); foreach (var content in postContentList) { - var body = await client.TestPostAsync($"timelines/{generator(1)}/posts", - new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Text = content, Type = TimelinePostContentTypes.Text } }); + var body = await client.TestPostAsync($"timelines/{generator(1)}/posts", + new HttpTimelinePostCreateRequest { Content = new HttpTimelinePostCreateRequestContent { Text = content, Type = TimelinePostContentTypes.Text } }); posts.Add(body); } @@ -767,7 +767,7 @@ namespace Timeline.Tests.IntegratedTests } { - posts = await client.TestGetAsync>($"timelines/{generator(1)}/posts?includeDeleted=true"); + posts = await client.TestGetAsync>($"timelines/{generator(1)}/posts?includeDeleted=true"); posts.Should().HaveCount(4); posts.Select(p => p.Deleted).Should().Equal(true, false, true, false); posts.Select(p => p.Content == null).Should().Equal(true, false, true, false); @@ -781,12 +781,12 @@ namespace Timeline.Tests.IntegratedTests using var client = await CreateClientAsUser(); var postContentList = new List { "a", "b", "c", "d" }; - var posts = new List(); + var posts = new List(); foreach (var (content, index) in postContentList.Select((v, i) => (v, i))) { - var post = await client.TestPostAsync($"timelines/{generator(1)}/posts", - new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Text = content, Type = TimelinePostContentTypes.Text } }); + var post = await client.TestPostAsync($"timelines/{generator(1)}/posts", + new HttpTimelinePostCreateRequest { Content = new HttpTimelinePostCreateRequestContent { Text = content, Type = TimelinePostContentTypes.Text } }); posts.Add(post); await Task.Delay(1000); } @@ -795,7 +795,7 @@ namespace Timeline.Tests.IntegratedTests { - posts = await client.TestGetAsync>($"timelines/{generator(1)}/posts?modifiedSince={posts[1].LastUpdated.ToString("s", CultureInfo.InvariantCulture)}&includeDeleted=true"); + posts = await client.TestGetAsync>($"timelines/{generator(1)}/posts?modifiedSince={posts[1].LastUpdated.ToString("s", CultureInfo.InvariantCulture)}&includeDeleted=true"); posts.Should().HaveCount(3); posts.Select(p => p.Deleted).Should().Equal(false, true, false); posts.Select(p => p.Content == null).Should().Equal(false, true, false); @@ -809,7 +809,7 @@ namespace Timeline.Tests.IntegratedTests using var client = await CreateClientAsUser(); DateTime lastModifiedTime; - TimelineInfo timeline; + HttpTimeline timeline; string uniqueId; { @@ -830,7 +830,7 @@ namespace Timeline.Tests.IntegratedTests { - var body = await client.TestGetAsync($"timelines/{generator(1)}", + var body = await client.TestGetAsync($"timelines/{generator(1)}", headerSetup: (headers, _) => { headers.IfModifiedSince = lastModifiedTime.AddSeconds(-1); @@ -843,7 +843,7 @@ namespace Timeline.Tests.IntegratedTests } { - var body = await client.TestGetAsync($"timelines/{generator(1)}?ifModifiedSince={lastModifiedTime.AddSeconds(-1).ToString("s", CultureInfo.InvariantCulture) }"); + var body = await client.TestGetAsync($"timelines/{generator(1)}?ifModifiedSince={lastModifiedTime.AddSeconds(-1).ToString("s", CultureInfo.InvariantCulture) }"); body.Should().BeEquivalentTo(timeline); } @@ -853,7 +853,7 @@ namespace Timeline.Tests.IntegratedTests { var testUniqueId = (uniqueId[0] == 'a' ? "b" : "a") + uniqueId[1..]; - var body = await client.TestGetAsync($"timelines/{generator(1)}?ifModifiedSince={lastModifiedTime.AddSeconds(1).ToString("s", CultureInfo.InvariantCulture) }&checkUniqueId={testUniqueId}"); + var body = await client.TestGetAsync($"timelines/{generator(1)}?ifModifiedSince={lastModifiedTime.AddSeconds(1).ToString("s", CultureInfo.InvariantCulture) }&checkUniqueId={testUniqueId}"); body.Should().BeEquivalentTo(timeline); } } @@ -870,7 +870,7 @@ namespace Timeline.Tests.IntegratedTests } { - var body = await client.PatchTimelineAsync(generator(1), new TimelinePatchRequest { Title = "atitle" }); + var body = await client.PatchTimelineAsync(generator(1), new HttpTimelinePatchRequest { Title = "atitle" }); body.Title.Should().Be("atitle"); } @@ -885,26 +885,26 @@ namespace Timeline.Tests.IntegratedTests { { using var client = await CreateDefaultClient(); - await client.TestPostAssertUnauthorizedAsync("timelineop/changename", new TimelineChangeNameRequest { OldName = "t1", NewName = "tttttttt" }); + await client.TestPostAssertUnauthorizedAsync("timelineop/changename", new HttpTimelineChangeNameRequest { OldName = "t1", NewName = "tttttttt" }); } { using var client = await CreateClientAs(2); - await client.TestPostAssertForbiddenAsync("timelineop/changename", new TimelineChangeNameRequest { OldName = "t1", NewName = "tttttttt" }); + await client.TestPostAssertForbiddenAsync("timelineop/changename", new HttpTimelineChangeNameRequest { OldName = "t1", NewName = "tttttttt" }); } using (var client = await CreateClientAsUser()) { - await client.TestPostAssertInvalidModelAsync("timelineop/changename", new TimelineChangeNameRequest { OldName = "!!!", NewName = "tttttttt" }); - await client.TestPostAssertInvalidModelAsync("timelineop/changename", new TimelineChangeNameRequest { OldName = "ttt", NewName = "!!!!" }); - await client.TestPostAssertErrorAsync("timelineop/changename", new TimelineChangeNameRequest { OldName = "ttttt", NewName = "tttttttt" }, errorCode: ErrorCodes.TimelineController.NotExist); + await client.TestPostAssertInvalidModelAsync("timelineop/changename", new HttpTimelineChangeNameRequest { OldName = "!!!", NewName = "tttttttt" }); + await client.TestPostAssertInvalidModelAsync("timelineop/changename", new HttpTimelineChangeNameRequest { OldName = "ttt", NewName = "!!!!" }); + await client.TestPostAssertErrorAsync("timelineop/changename", new HttpTimelineChangeNameRequest { OldName = "ttttt", NewName = "tttttttt" }, errorCode: ErrorCodes.TimelineController.NotExist); - await client.TestPostAsync("timelineop/changename", new TimelineChangeNameRequest { OldName = "t1", NewName = "newt" }); + await client.TestPostAsync("timelineop/changename", new HttpTimelineChangeNameRequest { OldName = "t1", NewName = "newt" }); await client.TestGetAsync("timelines/t1", expectedStatusCode: HttpStatusCode.NotFound); { - var body = await client.TestGetAsync("timelines/newt"); + var body = await client.TestGetAsync("timelines/newt"); body.Name.Should().Be("newt"); } } @@ -920,9 +920,9 @@ namespace Timeline.Tests.IntegratedTests string etag; { - var body = await client.TestPostAsync($"timelines/{generator(1)}/posts", new TimelinePostCreateRequest + var body = await client.TestPostAsync($"timelines/{generator(1)}/posts", new HttpTimelinePostCreateRequest { - Content = new TimelinePostCreateRequestContent + Content = new HttpTimelinePostCreateRequestContent { Type = TimelinePostContentTypes.Image, Data = Convert.ToBase64String(ImageHelper.CreatePngWithSize(100, 50)) diff --git a/BackEnd/Timeline.Tests/IntegratedTests/TokenTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/TokenTest.cs index a5208618..fdf1af99 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/TokenTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/TokenTest.cs @@ -14,9 +14,9 @@ namespace Timeline.Tests.IntegratedTests private const string CreateTokenUrl = "token/create"; private const string VerifyTokenUrl = "token/verify"; - private static async Task CreateUserTokenAsync(HttpClient client, string username, string password, int? expireOffset = null) + private static async Task CreateUserTokenAsync(HttpClient client, string username, string password, int? expireOffset = null) { - return await client.TestPostAsync(CreateTokenUrl, new CreateTokenRequest { Username = username, Password = password, Expire = expireOffset }); + return await client.TestPostAsync(CreateTokenUrl, new HttpCreateTokenRequest { Username = username, Password = password, Expire = expireOffset }); } public static IEnumerable CreateToken_InvalidModel_Data() @@ -32,7 +32,7 @@ namespace Timeline.Tests.IntegratedTests public async Task CreateToken_InvalidModel(string username, string password, int expire) { using var client = await CreateDefaultClient(); - await client.TestPostAssertInvalidModelAsync(CreateTokenUrl, new CreateTokenRequest + await client.TestPostAssertInvalidModelAsync(CreateTokenUrl, new HttpCreateTokenRequest { Username = username, Password = password, @@ -52,7 +52,7 @@ namespace Timeline.Tests.IntegratedTests { using var client = await CreateDefaultClient(); await client.TestPostAssertErrorAsync(CreateTokenUrl, - new CreateTokenRequest { Username = username, Password = password }, + new HttpCreateTokenRequest { Username = username, Password = password }, errorCode: ErrorCodes.TokenController.Create_BadCredential); } @@ -60,8 +60,8 @@ namespace Timeline.Tests.IntegratedTests public async Task CreateToken_Success() { using var client = await CreateDefaultClient(); - var body = await client.TestPostAsync(CreateTokenUrl, - new CreateTokenRequest { Username = "user1", Password = "user1pw" }); + var body = await client.TestPostAsync(CreateTokenUrl, + new HttpCreateTokenRequest { Username = "user1", Password = "user1pw" }); body.Token.Should().NotBeNullOrWhiteSpace(); body.User.Should().BeEquivalentTo(await client.GetUserAsync("user1")); } @@ -70,7 +70,7 @@ namespace Timeline.Tests.IntegratedTests public async Task VerifyToken_InvalidModel() { using var client = await CreateDefaultClient(); - await client.TestPostAssertInvalidModelAsync(VerifyTokenUrl, new VerifyTokenRequest { Token = null! }); + await client.TestPostAssertInvalidModelAsync(VerifyTokenUrl, new HttpVerifyTokenRequest { Token = null! }); } [Fact] @@ -78,7 +78,7 @@ namespace Timeline.Tests.IntegratedTests { using var client = await CreateDefaultClient(); await client.TestPostAssertErrorAsync(VerifyTokenUrl, - new VerifyTokenRequest { Token = "bad token hahaha" }, + new HttpVerifyTokenRequest { Token = "bad token hahaha" }, errorCode: ErrorCodes.TokenController.Verify_BadFormat); } @@ -97,7 +97,7 @@ namespace Timeline.Tests.IntegratedTests } await client.TestPostAssertErrorAsync(VerifyTokenUrl, - new VerifyTokenRequest { Token = token }, + new HttpVerifyTokenRequest { Token = token }, errorCode: ErrorCodes.TokenController.Verify_OldVersion); } @@ -114,7 +114,7 @@ namespace Timeline.Tests.IntegratedTests } await client.TestPostAssertErrorAsync(VerifyTokenUrl, - new VerifyTokenRequest { Token = token }, + new HttpVerifyTokenRequest { Token = token }, errorCode: ErrorCodes.TokenController.Verify_UserNotExist); } @@ -141,8 +141,8 @@ namespace Timeline.Tests.IntegratedTests { using var client = await CreateDefaultClient(); var createTokenResult = await CreateUserTokenAsync(client, "user1", "user1pw"); - var body = await client.TestPostAsync(VerifyTokenUrl, - new VerifyTokenRequest { Token = createTokenResult.Token }); + var body = await client.TestPostAsync(VerifyTokenUrl, + new HttpVerifyTokenRequest { Token = createTokenResult.Token }); body.User.Should().BeEquivalentTo(await client.GetUserAsync("user1")); } } diff --git a/BackEnd/Timeline.Tests/IntegratedTests/UserTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/UserTest.cs index e0ebf635..56dbf92a 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/UserTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/UserTest.cs @@ -12,7 +12,7 @@ namespace Timeline.Tests.IntegratedTests public async Task UserListShouldHaveUniqueId() { using var client = await CreateDefaultClient(); - foreach (var user in await client.TestGetAsync>("users")) + foreach (var user in await client.TestGetAsync>("users")) { user.UniqueId.Should().NotBeNullOrWhiteSpace(); } @@ -22,14 +22,14 @@ namespace Timeline.Tests.IntegratedTests public async Task GetList() { using var client = await CreateDefaultClient(); - await client.TestGetAsync>("users"); + await client.TestGetAsync>("users"); } [Fact] public async Task Get() { using var client = await CreateDefaultClient(); - var user = await client.TestGetAsync($"users/admin"); + var user = await client.TestGetAsync($"users/admin"); user.Username.Should().Be("admin"); user.Nickname.Should().Be("administrator"); user.UniqueId.Should().NotBeNullOrEmpty(); @@ -55,8 +55,8 @@ namespace Timeline.Tests.IntegratedTests { using var client = await CreateClientAsUser(); { - var body = await client.TestPatchAsync("users/user1", - new UserPatchRequest { Nickname = "aaa" }); + var body = await client.TestPatchAsync("users/user1", + new HttpUserPatchRequest { Nickname = "aaa" }); body.Nickname.Should().Be("aaa"); } @@ -73,8 +73,8 @@ namespace Timeline.Tests.IntegratedTests using var userClient = await CreateClientAsUser(); { - var body = await client.TestPatchAsync("users/user1", - new UserPatchRequest + var body = await client.TestPatchAsync("users/user1", + new HttpUserPatchRequest { Username = "newuser", Password = "newpw", @@ -91,7 +91,7 @@ namespace Timeline.Tests.IntegratedTests { var token = userClient.DefaultRequestHeaders.Authorization!.Parameter!; // Token should expire. - await userClient.TestPostAssertErrorAsync("token/verify", new VerifyTokenRequest() { Token = token }); + await userClient.TestPostAssertErrorAsync("token/verify", new HttpVerifyTokenRequest() { Token = token }); } { @@ -104,26 +104,26 @@ namespace Timeline.Tests.IntegratedTests public async Task Patch_NotExist() { using var client = await CreateClientAsAdministrator(); - await client.TestPatchAssertNotFoundAsync("users/usernotexist", new UserPatchRequest { }, errorCode: ErrorCodes.UserCommon.NotExist); + await client.TestPatchAssertNotFoundAsync("users/usernotexist", new HttpUserPatchRequest { }, errorCode: ErrorCodes.UserCommon.NotExist); } [Fact] public async Task Patch_InvalidModel() { using var client = await CreateClientAsAdministrator(); - await client.TestPatchAssertInvalidModelAsync("users/aaa!a", new UserPatchRequest { }); + await client.TestPatchAssertInvalidModelAsync("users/aaa!a", new HttpUserPatchRequest { }); } public static IEnumerable Patch_InvalidModel_Body_Data() { - yield return new[] { new UserPatchRequest { Username = "aaa!a" } }; - yield return new[] { new UserPatchRequest { Password = "" } }; - yield return new[] { new UserPatchRequest { Nickname = new string('a', 50) } }; + yield return new[] { new HttpUserPatchRequest { Username = "aaa!a" } }; + yield return new[] { new HttpUserPatchRequest { Password = "" } }; + yield return new[] { new HttpUserPatchRequest { Nickname = new string('a', 50) } }; } [Theory] [MemberData(nameof(Patch_InvalidModel_Body_Data))] - public async Task Patch_InvalidModel_Body(UserPatchRequest body) + public async Task Patch_InvalidModel_Body(HttpUserPatchRequest body) { using var client = await CreateClientAsAdministrator(); await client.TestPatchAssertInvalidModelAsync("users/user1", body); @@ -133,35 +133,35 @@ namespace Timeline.Tests.IntegratedTests public async Task Patch_UsernameConflict() { using var client = await CreateClientAsAdministrator(); - await client.TestPatchAssertErrorAsync("users/user1", new UserPatchRequest { Username = "admin" }, errorCode: ErrorCodes.UserController.UsernameConflict); + await client.TestPatchAssertErrorAsync("users/user1", new HttpUserPatchRequest { Username = "admin" }, errorCode: ErrorCodes.UserController.UsernameConflict); } [Fact] public async Task Patch_NoAuth_Unauthorized() { using var client = await CreateDefaultClient(); - await client.TestPatchAssertUnauthorizedAsync("users/user1", new UserPatchRequest { Nickname = "aaa" }); + await client.TestPatchAssertUnauthorizedAsync("users/user1", new HttpUserPatchRequest { Nickname = "aaa" }); } [Fact] public async Task Patch_User_Forbid() { using var client = await CreateClientAsUser(); - await client.TestPatchAssertForbiddenAsync("users/admin", new UserPatchRequest { Nickname = "aaa" }); + await client.TestPatchAssertForbiddenAsync("users/admin", new HttpUserPatchRequest { Nickname = "aaa" }); } [Fact] public async Task Patch_Username_Forbid() { using var client = await CreateClientAsUser(); - await client.TestPatchAssertForbiddenAsync("users/user1", new UserPatchRequest { Username = "aaa" }); + await client.TestPatchAssertForbiddenAsync("users/user1", new HttpUserPatchRequest { Username = "aaa" }); } [Fact] public async Task Patch_Password_Forbid() { using var client = await CreateClientAsUser(); - await client.TestPatchAssertForbiddenAsync("users/user1", new UserPatchRequest { Password = "aaa" }); + await client.TestPatchAssertForbiddenAsync("users/user1", new HttpUserPatchRequest { Password = "aaa" }); } [Fact] @@ -214,7 +214,7 @@ namespace Timeline.Tests.IntegratedTests { using var client = await CreateClientAsAdministrator(); { - var body = await client.TestPostAsync(createUserUrl, new CreateUserRequest + var body = await client.TestPostAsync(createUserUrl, new HttpCreateUserRequest { Username = "aaa", Password = "bbb", @@ -233,15 +233,15 @@ namespace Timeline.Tests.IntegratedTests public static IEnumerable Op_CreateUser_InvalidModel_Data() { - yield return new[] { new CreateUserRequest { Username = "aaa" } }; - yield return new[] { new CreateUserRequest { Password = "bbb" } }; - yield return new[] { new CreateUserRequest { Username = "a!a", Password = "bbb" } }; - yield return new[] { new CreateUserRequest { Username = "aaa", Password = "" } }; + 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 = "" } }; } [Theory] [MemberData(nameof(Op_CreateUser_InvalidModel_Data))] - public async Task Op_CreateUser_InvalidModel(CreateUserRequest body) + public async Task Op_CreateUser_InvalidModel(HttpCreateUserRequest 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 CreateUserRequest + await client.TestPostAssertErrorAsync(createUserUrl, new HttpCreateUserRequest { 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 CreateUserRequest + await client.TestPostAssertUnauthorizedAsync(createUserUrl, new HttpCreateUserRequest { 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 CreateUserRequest + await client.TestPostAssertForbiddenAsync(createUserUrl, new HttpCreateUserRequest { Username = "aaa", Password = "bbb", @@ -286,8 +286,8 @@ namespace Timeline.Tests.IntegratedTests public async Task Op_ChangePassword() { using var client = await CreateClientAsUser(); - await client.TestPostAsync(changePasswordUrl, new ChangePasswordRequest { OldPassword = "user1pw", NewPassword = "newpw" }); - await client.TestPatchAssertUnauthorizedAsync("users/user1", new UserPatchRequest { }); + await client.TestPostAsync(changePasswordUrl, new HttpChangePasswordRequest { OldPassword = "user1pw", NewPassword = "newpw" }); + await client.TestPatchAssertUnauthorizedAsync("users/user1", new HttpUserPatchRequest { }); (await CreateClientWithCredential("user1", "newpw")).Dispose(); } @@ -303,21 +303,21 @@ namespace Timeline.Tests.IntegratedTests { using var client = await CreateClientAsUser(); await client.TestPostAssertInvalidModelAsync(changePasswordUrl, - new ChangePasswordRequest { OldPassword = oldPassword, NewPassword = newPassword }); + new HttpChangePasswordRequest { OldPassword = oldPassword, NewPassword = newPassword }); } [Fact] public async Task Op_ChangePassword_BadOldPassword() { using var client = await CreateClientAsUser(); - await client.TestPostAssertErrorAsync(changePasswordUrl, new ChangePasswordRequest { OldPassword = "???", NewPassword = "???" }, errorCode: ErrorCodes.UserController.ChangePassword_BadOldPassword); + await client.TestPostAssertErrorAsync(changePasswordUrl, new HttpChangePasswordRequest { OldPassword = "???", NewPassword = "???" }, errorCode: ErrorCodes.UserController.ChangePassword_BadOldPassword); } [Fact] public async Task Op_ChangePassword_NoAuth_Unauthorized() { using var client = await CreateDefaultClient(); - await client.TestPostAssertUnauthorizedAsync(changePasswordUrl, new ChangePasswordRequest { OldPassword = "???", NewPassword = "???" }); + await client.TestPostAssertUnauthorizedAsync(changePasswordUrl, new HttpChangePasswordRequest { OldPassword = "???", NewPassword = "???" }); } } } -- cgit v1.2.3