From 2ffc07756ca7d50533e90fdac37d62a6c33a8a00 Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 30 May 2020 23:16:49 +0800 Subject: Just get everything works! --- .../IntegratedTests/IntegratedTestBase.cs | 8 +-- Timeline.Tests/IntegratedTests/TimelineTest.cs | 74 +++++++++++----------- Timeline.Tests/IntegratedTests/UserTest.cs | 62 +++++++++--------- 3 files changed, 72 insertions(+), 72 deletions(-) (limited to 'Timeline.Tests') diff --git a/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs b/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs index 6c349ffb..e42483bd 100644 --- a/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs +++ b/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs @@ -100,7 +100,7 @@ namespace Timeline.Tests.IntegratedTests options.Converters.Add(new JsonDateTimeConverter()); foreach (var user in users) { - var s = await client.GetStringAsync($"/users/{user.Username}"); + var s = await client.GetStringAsync($"users/{user.Username}"); userInfoList.Add(JsonSerializer.Deserialize(s, options)); } @@ -120,15 +120,15 @@ namespace Timeline.Tests.IntegratedTests public Task CreateDefaultClient() { var client = Factory.CreateDefaultClient(); - client.BaseAddress = new Uri(client.BaseAddress, "api"); + client.BaseAddress = new Uri(client.BaseAddress, "api/"); return Task.FromResult(client); } public async Task CreateClientWithCredential(string username, string password) { var client = Factory.CreateDefaultClient(); - client.BaseAddress = new Uri(client.BaseAddress, "api"); - var response = await client.PostAsJsonAsync("/token/create", + client.BaseAddress = new Uri(client.BaseAddress, "api/"); + var response = await client.PostAsJsonAsync("token/create", new CreateTokenRequest { Username = username, Password = password }); var token = response.Should().HaveStatusCode(200) .And.HaveJsonBody().Which.Token; diff --git a/Timeline.Tests/IntegratedTests/TimelineTest.cs b/Timeline.Tests/IntegratedTests/TimelineTest.cs index 845208e8..d8017b8a 100644 --- a/Timeline.Tests/IntegratedTests/TimelineTest.cs +++ b/Timeline.Tests/IntegratedTests/TimelineTest.cs @@ -72,12 +72,12 @@ namespace Timeline.Tests.IntegratedTests private static string GeneratePersonalTimelineUrl(int id, string subpath = null) { - return $"timelines/@{(id == 0 ? "admin" : ("user" + id))}{(subpath == null ? "" : ("/" + subpath))}"; + return $"timelines/@{(id == 0 ? "admin" : ("user" + id))}/{(subpath ?? "")}"; } private static string GenerateOrdinaryTimelineUrl(int id, string subpath = null) { - return $"timelines/t{id}{(subpath == null ? "" : ("/" + subpath))}"; + return $"timelines/t{id}/{(subpath ?? "")}"; } public static IEnumerable TimelineUrlGeneratorData() @@ -88,12 +88,12 @@ namespace Timeline.Tests.IntegratedTests private static string GeneratePersonalTimelineUrlByName(string name, string subpath = null) { - return $"timelines/@{name}{(subpath == null ? "" : ("/" + subpath))}"; + return $"timelines/@{name}/{(subpath ?? "")}"; } private static string GenerateOrdinaryTimelineUrlByName(string name, string subpath = null) { - return $"timelines/{name}{(subpath == null ? "" : ("/" + subpath))}"; + return $"timelines/{name}/{(subpath ?? "")}"; } public static IEnumerable TimelineUrlByNameGeneratorData() @@ -116,8 +116,8 @@ namespace Timeline.Tests.IntegratedTests body.Members.Should().NotBeNull().And.BeEmpty(); var links = body._links; links.Should().NotBeNull(); - links.Self.Should().EndWith("/timelines/@user1"); - links.Posts.Should().EndWith("/timelines/@user1/posts"); + links.Self.Should().EndWith("timelines/@user1"); + links.Posts.Should().EndWith("timelines/@user1/posts"); } { @@ -130,8 +130,8 @@ namespace Timeline.Tests.IntegratedTests body.Members.Should().NotBeNull().And.BeEmpty(); var links = body._links; links.Should().NotBeNull(); - links.Self.Should().EndWith("/timelines/t1"); - links.Posts.Should().EndWith("/timelines/t1/posts"); + links.Self.Should().EndWith("timelines/t1"); + links.Posts.Should().EndWith("timelines/t1/posts"); } } @@ -143,7 +143,7 @@ namespace Timeline.Tests.IntegratedTests var client = await CreateDefaultClient(); { - var res = await client.GetAsync("/timelines/@user1"); + var res = await client.GetAsync("timelines/@user1"); user1Timeline = res.Should().HaveStatusCode(200) .And.HaveJsonBody().Which; } @@ -153,7 +153,7 @@ namespace Timeline.Tests.IntegratedTests testResult.Add(user1Timeline); testResult.AddRange(_testTimelines); - var res = await client.GetAsync("/timelines"); + var res = await client.GetAsync("timelines"); res.Should().HaveStatusCode(200) .And.HaveJsonBody>() .Which.Should().BeEquivalentTo(testResult); @@ -176,27 +176,27 @@ namespace Timeline.Tests.IntegratedTests var client = await CreateClientAsUser(); { - var res = await client.PutAsync("/timelines/@user1/members/user3", null); + var res = await client.PutAsync("timelines/@user1/members/user3", null); res.Should().HaveStatusCode(200); } { - var res = await client.PutAsync("/timelines/t1/members/user3", null); + var res = await client.PutAsync("timelines/t1/members/user3", null); res.Should().HaveStatusCode(200); } { - var res = await client.PatchAsJsonAsync("/timelines/@user1", new TimelinePatchRequest { Visibility = TimelineVisibility.Public }); + var res = await client.PatchAsJsonAsync("timelines/@user1", new TimelinePatchRequest { Visibility = TimelineVisibility.Public }); res.Should().HaveStatusCode(200); } { - var res = await client.PatchAsJsonAsync("/timelines/t1", new TimelinePatchRequest { Visibility = TimelineVisibility.Register }); + var res = await client.PatchAsJsonAsync("timelines/t1", new TimelinePatchRequest { Visibility = TimelineVisibility.Register }); res.Should().HaveStatusCode(200); } { - var res = await client.GetAsync("/timelines/@user1"); + var res = await client.GetAsync("timelines/@user1"); var timeline = res.Should().HaveStatusCode(200) .And.HaveJsonBody().Which; testResultRelate.Add(timeline); @@ -206,7 +206,7 @@ namespace Timeline.Tests.IntegratedTests } { - var res = await client.GetAsync("/timelines/t1"); + var res = await client.GetAsync("timelines/t1"); var timeline = res.Should().HaveStatusCode(200) .And.HaveJsonBody().Which; testResultRelate.Add(timeline); @@ -219,27 +219,27 @@ namespace Timeline.Tests.IntegratedTests var client = await CreateClientAs(2); { - var res = await client.PutAsync("/timelines/@user2/members/user3", null); + var res = await client.PutAsync("timelines/@user2/members/user3", null); res.Should().HaveStatusCode(200); } { - var res = await client.PutAsync("/timelines/t2/members/user3", null); + var res = await client.PutAsync("timelines/t2/members/user3", null); res.Should().HaveStatusCode(200); } { - var res = await client.PatchAsJsonAsync("/timelines/@user2", new TimelinePatchRequest { Visibility = TimelineVisibility.Register }); + var res = await client.PatchAsJsonAsync("timelines/@user2", new TimelinePatchRequest { Visibility = TimelineVisibility.Register }); res.Should().HaveStatusCode(200); } { - var res = await client.PatchAsJsonAsync("/timelines/t2", new TimelinePatchRequest { Visibility = TimelineVisibility.Private }); + var res = await client.PatchAsJsonAsync("timelines/t2", new TimelinePatchRequest { Visibility = TimelineVisibility.Private }); res.Should().HaveStatusCode(200); } { - var res = await client.GetAsync("/timelines/@user2"); + var res = await client.GetAsync("timelines/@user2"); var timeline = res.Should().HaveStatusCode(200) .And.HaveJsonBody().Which; testResultRelate.Add(timeline); @@ -248,7 +248,7 @@ namespace Timeline.Tests.IntegratedTests } { - var res = await client.GetAsync("/timelines/t2"); + var res = await client.GetAsync("timelines/t2"); var timeline = res.Should().HaveStatusCode(200) .And.HaveJsonBody().Which; testResultRelate.Add(timeline); @@ -261,17 +261,17 @@ namespace Timeline.Tests.IntegratedTests var client = await CreateClientAs(3); { - var res = await client.PatchAsJsonAsync("/timelines/@user3", new TimelinePatchRequest { Visibility = TimelineVisibility.Private }); + var res = await client.PatchAsJsonAsync("timelines/@user3", new TimelinePatchRequest { Visibility = TimelineVisibility.Private }); res.Should().HaveStatusCode(200); } { - var res = await client.PatchAsJsonAsync("/timelines/t3", new TimelinePatchRequest { Visibility = TimelineVisibility.Register }); + var res = await client.PatchAsJsonAsync("timelines/t3", new TimelinePatchRequest { Visibility = TimelineVisibility.Register }); res.Should().HaveStatusCode(200); } { - var res = await client.GetAsync("/timelines/@user3"); + var res = await client.GetAsync("timelines/@user3"); var timeline = res.Should().HaveStatusCode(200) .And.HaveJsonBody().Which; testResultRelate.Add(timeline); @@ -280,7 +280,7 @@ namespace Timeline.Tests.IntegratedTests } { - var res = await client.GetAsync("/timelines/t3"); + var res = await client.GetAsync("timelines/t3"); var timeline = res.Should().HaveStatusCode(200) .And.HaveJsonBody().Which; testResultRelate.Add(timeline); @@ -292,7 +292,7 @@ namespace Timeline.Tests.IntegratedTests { var client = await CreateClientAs(3); { - var res = await client.GetAsync("/timelines?relate=user3"); + var res = await client.GetAsync("timelines?relate=user3"); var body = res.Should().HaveStatusCode(200) .And.HaveJsonBody>() .Which; @@ -300,7 +300,7 @@ namespace Timeline.Tests.IntegratedTests } { - var res = await client.GetAsync("/timelines?relate=user3&relateType=own"); + var res = await client.GetAsync("timelines?relate=user3&relateType=own"); var body = res.Should().HaveStatusCode(200) .And.HaveJsonBody>() .Which; @@ -308,7 +308,7 @@ namespace Timeline.Tests.IntegratedTests } { - var res = await client.GetAsync("/timelines?relate=user3&visibility=public"); + var res = await client.GetAsync("timelines?relate=user3&visibility=public"); var body = res.Should().HaveStatusCode(200) .And.HaveJsonBody>() .Which; @@ -316,7 +316,7 @@ namespace Timeline.Tests.IntegratedTests } { - var res = await client.GetAsync("/timelines?relate=user3&visibility=register"); + var res = await client.GetAsync("timelines?relate=user3&visibility=register"); var body = res.Should().HaveStatusCode(200) .And.HaveJsonBody>() .Which; @@ -324,7 +324,7 @@ namespace Timeline.Tests.IntegratedTests } { - var res = await client.GetAsync("/timelines?relate=user3&relateType=join&visibility=private"); + var res = await client.GetAsync("timelines?relate=user3&relateType=join&visibility=private"); var body = res.Should().HaveStatusCode(200) .And.HaveJsonBody>() .Which; @@ -332,7 +332,7 @@ namespace Timeline.Tests.IntegratedTests } { - var res = await client.GetAsync("/timelines?relate=user3&relateType=own&visibility=private"); + var res = await client.GetAsync("timelines?relate=user3&relateType=own&visibility=private"); var body = res.Should().HaveStatusCode(200) .And.HaveJsonBody>() .Which; @@ -343,7 +343,7 @@ namespace Timeline.Tests.IntegratedTests { var client = await CreateDefaultClient(); { - var res = await client.GetAsync("/timelines?visibility=public"); + var res = await client.GetAsync("timelines?visibility=public"); var body = res.Should().HaveStatusCode(200) .And.HaveJsonBody>() .Which; @@ -358,17 +358,17 @@ namespace Timeline.Tests.IntegratedTests var client = await CreateClientAsUser(); { - var res = await client.GetAsync("/timelines?relate=us!!"); + var res = await client.GetAsync("timelines?relate=us!!"); res.Should().BeInvalidModel(); } { - var res = await client.GetAsync("/timelines?relateType=aaa"); + var res = await client.GetAsync("timelines?relateType=aaa"); res.Should().BeInvalidModel(); } { - var res = await client.GetAsync("/timelines?visibility=aaa"); + var res = await client.GetAsync("timelines?visibility=aaa"); res.Should().BeInvalidModel(); } } @@ -483,7 +483,7 @@ namespace Timeline.Tests.IntegratedTests res.Should().BeInvalidModel(); } { - var res = await client.DeleteAsync(generator("aaa!!!/members", "user1")); + var res = await client.DeleteAsync(generator("aaa!!!", "members/user1")); res.Should().BeInvalidModel(); } { diff --git a/Timeline.Tests/IntegratedTests/UserTest.cs b/Timeline.Tests/IntegratedTests/UserTest.cs index 8ce76299..e226d084 100644 --- a/Timeline.Tests/IntegratedTests/UserTest.cs +++ b/Timeline.Tests/IntegratedTests/UserTest.cs @@ -22,7 +22,7 @@ namespace Timeline.Tests.IntegratedTests public async Task GetList_NoAuth() { using var client = await CreateDefaultClient(); - var res = await client.GetAsync("/users"); + var res = await client.GetAsync("users"); res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which.Should().BeEquivalentTo(UserInfos); @@ -32,7 +32,7 @@ namespace Timeline.Tests.IntegratedTests public async Task GetList_User() { using var client = await CreateClientAsUser(); - var res = await client.GetAsync("/users"); + var res = await client.GetAsync("users"); res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which.Should().BeEquivalentTo(UserInfos); @@ -42,7 +42,7 @@ namespace Timeline.Tests.IntegratedTests public async Task GetList_Admin() { using var client = await CreateClientAsAdministrator(); - var res = await client.GetAsync("/users"); + var res = await client.GetAsync("users"); res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which.Should().BeEquivalentTo(UserInfos); @@ -52,7 +52,7 @@ namespace Timeline.Tests.IntegratedTests public async Task Get_NoAuth() { using var client = await CreateDefaultClient(); - var res = await client.GetAsync($"/users/admin"); + var res = await client.GetAsync($"users/admin"); res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which.Should().BeEquivalentTo(UserInfos[0]); @@ -62,7 +62,7 @@ namespace Timeline.Tests.IntegratedTests public async Task Get_User() { using var client = await CreateClientAsUser(); - var res = await client.GetAsync($"/users/admin"); + var res = await client.GetAsync($"users/admin"); res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which.Should().BeEquivalentTo(UserInfos[0]); @@ -72,7 +72,7 @@ namespace Timeline.Tests.IntegratedTests public async Task Get_Admin() { using var client = await CreateClientAsAdministrator(); - var res = await client.GetAsync($"/users/user1"); + var res = await client.GetAsync($"users/user1"); res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which.Should().BeEquivalentTo(UserInfos[1]); @@ -82,7 +82,7 @@ namespace Timeline.Tests.IntegratedTests public async Task Get_InvalidModel() { using var client = await CreateClientAsUser(); - var res = await client.GetAsync("/users/aaa!a"); + var res = await client.GetAsync("users/aaa!a"); res.Should().BeInvalidModel(); } @@ -90,7 +90,7 @@ namespace Timeline.Tests.IntegratedTests public async Task Get_404() { using var client = await CreateClientAsUser(); - var res = await client.GetAsync("/users/usernotexist"); + var res = await client.GetAsync("users/usernotexist"); res.Should().HaveStatusCode(404) .And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); } @@ -100,7 +100,7 @@ namespace Timeline.Tests.IntegratedTests { using var client = await CreateClientAsUser(); { - var res = await client.PatchAsJsonAsync("/users/user1", + var res = await client.PatchAsJsonAsync("users/user1", new UserPatchRequest { Nickname = "aaa" }); res.Should().HaveStatusCode(200) .And.HaveJsonBody() @@ -108,7 +108,7 @@ namespace Timeline.Tests.IntegratedTests } { - var res = await client.GetAsync("/users/user1"); + var res = await client.GetAsync("users/user1"); res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which.Nickname.Should().Be("aaa"); @@ -122,7 +122,7 @@ namespace Timeline.Tests.IntegratedTests using var userClient = await CreateClientAsUser(); { - var res = await client.PatchAsJsonAsync("/users/user1", + var res = await client.PatchAsJsonAsync("users/user1", new UserPatchRequest { Username = "newuser", @@ -138,7 +138,7 @@ namespace Timeline.Tests.IntegratedTests } { - var res = await client.GetAsync("/users/newuser"); + var res = await client.GetAsync("users/newuser"); var body = res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which; @@ -148,7 +148,7 @@ namespace Timeline.Tests.IntegratedTests { // Token should expire. - var res = await userClient.GetAsync("/testing/auth/Authorize"); + var res = await userClient.GetAsync("testing/auth/Authorize"); res.Should().HaveStatusCode(HttpStatusCode.Unauthorized); } @@ -162,7 +162,7 @@ namespace Timeline.Tests.IntegratedTests public async Task Patch_NotExist() { using var client = await CreateClientAsAdministrator(); - var res = await client.PatchAsJsonAsync("/users/usernotexist", new UserPatchRequest { }); + var res = await client.PatchAsJsonAsync("users/usernotexist", new UserPatchRequest { }); res.Should().HaveStatusCode(404) .And.HaveCommonBody() .Which.Code.Should().Be(ErrorCodes.UserCommon.NotExist); @@ -172,7 +172,7 @@ namespace Timeline.Tests.IntegratedTests public async Task Patch_InvalidModel() { using var client = await CreateClientAsAdministrator(); - var res = await client.PatchAsJsonAsync("/users/aaa!a", new UserPatchRequest { }); + var res = await client.PatchAsJsonAsync("users/aaa!a", new UserPatchRequest { }); res.Should().BeInvalidModel(); } @@ -188,7 +188,7 @@ namespace Timeline.Tests.IntegratedTests public async Task Patch_InvalidModel_Body(UserPatchRequest body) { using var client = await CreateClientAsAdministrator(); - var res = await client.PatchAsJsonAsync("/users/user1", body); + var res = await client.PatchAsJsonAsync("users/user1", body); res.Should().BeInvalidModel(); } @@ -196,7 +196,7 @@ namespace Timeline.Tests.IntegratedTests public async Task Patch_UsernameConflict() { using var client = await CreateClientAsAdministrator(); - var res = await client.PatchAsJsonAsync("/users/user1", new UserPatchRequest { Username = "admin" }); + var res = await client.PatchAsJsonAsync("users/user1", new UserPatchRequest { Username = "admin" }); res.Should().HaveStatusCode(400) .And.HaveCommonBody(ErrorCodes.UserController.UsernameConflict); } @@ -205,7 +205,7 @@ namespace Timeline.Tests.IntegratedTests public async Task Patch_NoAuth_Unauthorized() { using var client = await CreateDefaultClient(); - var res = await client.PatchAsJsonAsync("/users/user1", new UserPatchRequest { Nickname = "aaa" }); + var res = await client.PatchAsJsonAsync("users/user1", new UserPatchRequest { Nickname = "aaa" }); res.Should().HaveStatusCode(HttpStatusCode.Unauthorized); } @@ -213,7 +213,7 @@ namespace Timeline.Tests.IntegratedTests public async Task Patch_User_Forbid() { using var client = await CreateClientAsUser(); - var res = await client.PatchAsJsonAsync("/users/admin", new UserPatchRequest { Nickname = "aaa" }); + var res = await client.PatchAsJsonAsync("users/admin", new UserPatchRequest { Nickname = "aaa" }); res.Should().HaveStatusCode(HttpStatusCode.Forbidden); } @@ -221,7 +221,7 @@ namespace Timeline.Tests.IntegratedTests public async Task Patch_Username_Forbid() { using var client = await CreateClientAsUser(); - var res = await client.PatchAsJsonAsync("/users/user1", new UserPatchRequest { Username = "aaa" }); + var res = await client.PatchAsJsonAsync("users/user1", new UserPatchRequest { Username = "aaa" }); res.Should().HaveStatusCode(HttpStatusCode.Forbidden); } @@ -229,7 +229,7 @@ namespace Timeline.Tests.IntegratedTests public async Task Patch_Password_Forbid() { using var client = await CreateClientAsUser(); - var res = await client.PatchAsJsonAsync("/users/user1", new UserPatchRequest { Password = "aaa" }); + var res = await client.PatchAsJsonAsync("users/user1", new UserPatchRequest { Password = "aaa" }); res.Should().HaveStatusCode(HttpStatusCode.Forbidden); } @@ -237,7 +237,7 @@ namespace Timeline.Tests.IntegratedTests public async Task Patch_Administrator_Forbid() { using var client = await CreateClientAsUser(); - var res = await client.PatchAsJsonAsync("/users/user1", new UserPatchRequest { Administrator = true }); + var res = await client.PatchAsJsonAsync("users/user1", new UserPatchRequest { Administrator = true }); res.Should().HaveStatusCode(HttpStatusCode.Forbidden); } @@ -246,12 +246,12 @@ namespace Timeline.Tests.IntegratedTests { using var client = await CreateClientAsAdministrator(); { - var res = await client.DeleteAsync("/users/user1"); + var res = await client.DeleteAsync("users/user1"); res.Should().BeDelete(true); } { - var res = await client.GetAsync("/users/user1"); + var res = await client.GetAsync("users/user1"); res.Should().HaveStatusCode(404); } } @@ -260,7 +260,7 @@ namespace Timeline.Tests.IntegratedTests public async Task Delete_NotExist() { using var client = await CreateClientAsAdministrator(); - var res = await client.DeleteAsync("/users/usernotexist"); + var res = await client.DeleteAsync("users/usernotexist"); res.Should().BeDelete(false); } @@ -268,7 +268,7 @@ namespace Timeline.Tests.IntegratedTests public async Task Delete_InvalidModel() { using var client = await CreateClientAsAdministrator(); - var res = await client.DeleteAsync("/users/aaa!a"); + var res = await client.DeleteAsync("users/aaa!a"); res.Should().BeInvalidModel(); } @@ -276,7 +276,7 @@ namespace Timeline.Tests.IntegratedTests public async Task Delete_NoAuth_Unauthorized() { using var client = await CreateDefaultClient(); - var res = await client.DeleteAsync("/users/aaa!a"); + var res = await client.DeleteAsync("users/aaa!a"); res.Should().HaveStatusCode(HttpStatusCode.Unauthorized); } @@ -284,11 +284,11 @@ namespace Timeline.Tests.IntegratedTests public async Task Delete_User_Forbid() { using var client = await CreateClientAsUser(); - var res = await client.DeleteAsync("/users/aaa!a"); + var res = await client.DeleteAsync("users/aaa!a"); res.Should().HaveStatusCode(HttpStatusCode.Forbidden); } - private const string createUserUrl = "/userop/createuser"; + private const string createUserUrl = "userop/createuser"; [Fact] public async Task Op_CreateUser() @@ -389,7 +389,7 @@ namespace Timeline.Tests.IntegratedTests } } - private const string changePasswordUrl = "/userop/changepassword"; + private const string changePasswordUrl = "userop/changepassword"; [Fact] public async Task Op_ChangePassword() @@ -401,7 +401,7 @@ namespace Timeline.Tests.IntegratedTests res.Should().HaveStatusCode(200); } { - var res = await client.PatchAsJsonAsync("/users/user1", new UserPatchRequest { }); + var res = await client.PatchAsJsonAsync("users/user1", new UserPatchRequest { }); res.Should().HaveStatusCode(HttpStatusCode.Unauthorized); } { -- cgit v1.2.3