diff options
author | crupest <crupest@outlook.com> | 2020-11-15 17:27:18 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-11-15 17:27:18 +0800 |
commit | 68ace2c77bffb2e35422d4ca5d878962475ae765 (patch) | |
tree | 03bdb92126b716daab2fe7a4ab74d4a86c7c8aa4 | |
parent | a2e196289834d1a9566013b1043eee4535a2369f (diff) | |
download | timeline-68ace2c77bffb2e35422d4ca5d878962475ae765.tar.gz timeline-68ace2c77bffb2e35422d4ca5d878962475ae765.tar.bz2 timeline-68ace2c77bffb2e35422d4ca5d878962475ae765.zip |
...
8 files changed, 29 insertions, 25 deletions
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/HttpClientTestExtensions.cs b/BackEnd/Timeline.Tests/IntegratedTests/HttpClientTestExtensions.cs index 9abe4b6b..7cff0c39 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/HttpClientTestExtensions.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/HttpClientTestExtensions.cs @@ -85,9 +85,15 @@ namespace Timeline.Tests.IntegratedTests public static async Task TestDeleteAsync(this HttpClient client, string url, bool? delete = null, HttpStatusCode expectedStatusCode = HttpStatusCode.OK)
{
- var body = await client.TestJsonSendAsync<CommonDeleteResponse>(HttpMethod.Delete, url, expectedStatusCode: expectedStatusCode);
if (delete.HasValue)
+ {
+ var body = await client.TestJsonSendAsync<CommonDeleteResponse>(HttpMethod.Delete, url, expectedStatusCode: expectedStatusCode);
body.Data.Delete.Should().Be(delete.Value);
+ }
+ else
+ {
+ await client.TestJsonSendAsync(HttpMethod.Delete, url, expectedStatusCode: expectedStatusCode);
+ }
}
public static async Task TestSendAssertErrorAsync(this HttpClient client, HttpMethod method, string url, HttpContent? body = null, HttpStatusCode expectedStatusCode = HttpStatusCode.BadRequest, int? errorCode = null, HeaderSetup? headerSetup = null)
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs index 1b7ed616..9845e1b1 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs @@ -651,11 +651,11 @@ namespace Timeline.Tests.IntegratedTests }
await CacheTestHelper.TestCache(client, $"timelines/{generator(1)}/posts/{postId}/data");
- await client.TestDeleteAsync($"timelines/{generator(1)}/posts/{postId}/data", true);
- await client.TestDeleteAsync($"timelines/{generator(1)}/posts/{postId}/data", false);
+ await client.TestDeleteAsync($"timelines/{generator(1)}/posts/{postId}", true);
+ await client.TestDeleteAsync($"timelines/{generator(1)}/posts/{postId}", false);
{
- var body = await client.TestGetAsync<List<TimelinePostInfo>>($"timelines/{generator(1)}/posts/{postId}/data");
+ var body = await client.TestGetAsync<List<TimelinePostInfo>>($"timelines/{generator(1)}/posts");
body.Should().BeEmpty();
}
@@ -673,7 +673,7 @@ namespace Timeline.Tests.IntegratedTests {
using var client = await CreateClientAsUser();
- await client.TestGetAssertErrorAsync($"timelines/{generator(1)}/posts/11234/data", errorCode: ErrorCodes.TimelineController.PostNotExist);
+ await client.TestGetAssertNotFoundAsync($"timelines/{generator(1)}/posts/11234/data", errorCode: ErrorCodes.TimelineController.PostNotExist);
long postId;
{
@@ -804,7 +804,7 @@ namespace Timeline.Tests.IntegratedTests [Theory]
[MemberData(nameof(TimelineNameGeneratorTestData))]
- public async Task Timeline_Get_IfModifiedSince_And_CheckUniqueId(TimelineNameGenerator urlGenerator)
+ public async Task Timeline_Get_IfModifiedSince_And_CheckUniqueId(TimelineNameGenerator generator)
{
using var client = await CreateClientAsUser();
@@ -813,14 +813,14 @@ namespace Timeline.Tests.IntegratedTests string uniqueId;
{
- var body = await client.GetTimelineAsync(urlGenerator(1));
+ var body = await client.GetTimelineAsync(generator(1));
timeline = body;
lastModifiedTime = body.LastModified;
uniqueId = body.UniqueId;
}
{
- await client.TestGetAsync($"timelines/{urlGenerator(1)}",
+ await client.TestGetAsync($"timelines/{generator(1)}",
expectedStatusCode: HttpStatusCode.NotModified,
headerSetup: (headers, _) =>
{
@@ -830,8 +830,7 @@ namespace Timeline.Tests.IntegratedTests {
- var body = await client.TestGetAsync<TimelineInfo>($"timelines/{urlGenerator(1)}",
- expectedStatusCode: HttpStatusCode.NotModified,
+ var body = await client.TestGetAsync<TimelineInfo>($"timelines/{generator(1)}",
headerSetup: (headers, _) =>
{
headers.IfModifiedSince = lastModifiedTime.AddSeconds(-1);
@@ -840,21 +839,21 @@ namespace Timeline.Tests.IntegratedTests }
{
- await client.TestGetAsync($"timelines/{urlGenerator(1)}?ifModifiedSince={lastModifiedTime.AddSeconds(1).ToString("s", CultureInfo.InvariantCulture) }", expectedStatusCode: HttpStatusCode.NotModified);
+ await client.TestGetAsync($"timelines/{generator(1)}?ifModifiedSince={lastModifiedTime.AddSeconds(1).ToString("s", CultureInfo.InvariantCulture) }", expectedStatusCode: HttpStatusCode.NotModified);
}
{
- var body = await client.TestGetAsync<TimelineInfo>($"timelines/{urlGenerator(1)}?ifModifiedSince={lastModifiedTime.AddSeconds(-1).ToString("s", CultureInfo.InvariantCulture) }");
+ var body = await client.TestGetAsync<TimelineInfo>($"timelines/{generator(1)}?ifModifiedSince={lastModifiedTime.AddSeconds(-1).ToString("s", CultureInfo.InvariantCulture) }");
body.Should().BeEquivalentTo(timeline);
}
{
- await client.TestGetAsync($"timelines/{urlGenerator(1)}?ifModifiedSince={lastModifiedTime.AddSeconds(1).ToString("s", CultureInfo.InvariantCulture) }&checkUniqueId={uniqueId}", expectedStatusCode: HttpStatusCode.NotModified);
+ await client.TestGetAsync($"timelines/{generator(1)}?ifModifiedSince={lastModifiedTime.AddSeconds(1).ToString("s", CultureInfo.InvariantCulture) }&checkUniqueId={uniqueId}", expectedStatusCode: HttpStatusCode.NotModified);
}
{
var testUniqueId = (uniqueId[0] == 'a' ? "b" : "a") + uniqueId[1..];
- var body = await client.TestGetAsync<TimelineInfo>($"timelines/{urlGenerator(1)}?ifModifiedSince={lastModifiedTime.AddSeconds(1).ToString("s", CultureInfo.InvariantCulture) }&checkUniqueId={testUniqueId}", expectedStatusCode: HttpStatusCode.NotModified);
+ var body = await client.TestGetAsync<TimelineInfo>($"timelines/{generator(1)}?ifModifiedSince={lastModifiedTime.AddSeconds(1).ToString("s", CultureInfo.InvariantCulture) }&checkUniqueId={testUniqueId}");
body.Should().BeEquivalentTo(timeline);
}
}
@@ -897,11 +896,10 @@ namespace Timeline.Tests.IntegratedTests 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 TimelineChangeNameRequest { OldName = "ttttt", NewName = "tttttttt" });
- await client.TestPostAssertInvalidModelAsync("timelineop/changename", new TimelineChangeNameRequest { OldName = "t1", NewName = "newt" });
+ await client.TestPostAsync("timelineop/changename", new TimelineChangeNameRequest { OldName = "t1", NewName = "newt" });
await client.TestGetAsync("timelines/t1", expectedStatusCode: HttpStatusCode.NotFound);
@@ -937,7 +935,7 @@ namespace Timeline.Tests.IntegratedTests }
{
- var res = await client.GetAsync($"timelines/{generator(1)}/posts{id}/data");
+ var res = await client.GetAsync($"timelines/{generator(1)}/posts/{id}/data");
res.StatusCode.Should().Be(HttpStatusCode.OK);
res.Headers.ETag.Should().NotBeNull();
res.Headers.ETag!.ToString().Should().Be(etag);
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/TokenTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/TokenTest.cs index 3c4a595d..c2f91eb1 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/TokenTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/TokenTest.cs @@ -144,7 +144,7 @@ namespace Timeline.Tests.IntegratedTests var createTokenResult = await CreateUserTokenAsync(client, "user1", "user1pw");
var body = await client.TestPostAsync<VerifyTokenResponse>(VerifyTokenUrl,
new VerifyTokenRequest { Token = createTokenResult.Token });
- body.Should().BeEquivalentTo(await client.GetUserAsync("user1"));
+ body.User.Should().BeEquivalentTo(await client.GetUserAsync("user1"));
}
}
}
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/UserAvatarTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/UserAvatarTest.cs index 79a3c2fa..893a5d28 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/UserAvatarTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/UserAvatarTest.cs @@ -101,7 +101,7 @@ 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/png", errorCode: ErrorCodes.UserAvatar.BadFormat_UnmatchedFormat);
+ 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);
}
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/UserPermissionTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/UserPermissionTest.cs index 418dd0f9..77cae590 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/UserPermissionTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/UserPermissionTest.cs @@ -50,7 +50,7 @@ namespace Timeline.Tests.IntegratedTests await client.TestPutAsync($"users/admin/permissions/{permission}");
{
- var body = await client.GetUserAsync("users/admin");
+ var body = await client.GetUserAsync("admin");
body.Permissions.Should().BeEquivalentTo(Enum.GetNames<UserPermission>());
}
}
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/UserTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/UserTest.cs index d13f6579..0d65478b 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/UserTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/UserTest.cs @@ -84,7 +84,7 @@ namespace Timeline.Tests.IntegratedTests }
{
- var body = await client.GetUserAsync("users/newuser");
+ var body = await client.GetUserAsync("newuser");
body.Nickname.Should().Be("aaa");
}
@@ -215,7 +215,7 @@ namespace Timeline.Tests.IntegratedTests body.Username.Should().Be("aaa");
}
{
- var body = await client.GetUserAsync("users/aaa");
+ var body = await client.GetUserAsync("aaa");
body.Username.Should().Be("aaa");
}
{
diff --git a/BackEnd/Timeline.Tests/Services/DatabaseBasedTest.cs b/BackEnd/Timeline.Tests/Services/DatabaseBasedTest.cs index 7c97158c..3bb6ebb5 100644 --- a/BackEnd/Timeline.Tests/Services/DatabaseBasedTest.cs +++ b/BackEnd/Timeline.Tests/Services/DatabaseBasedTest.cs @@ -8,7 +8,7 @@ namespace Timeline.Tests.Services public abstract class DatabaseBasedTest : IAsyncLifetime
{
protected TestDatabase TestDatabase { get; }
- protected DatabaseContext Database { get; private set; }
+ protected DatabaseContext Database { get; private set; } = default!;
protected DatabaseBasedTest(bool databaseCreateUsers = true)
{
diff --git a/BackEnd/Timeline.Tests/Services/UserPermissionServiceTest.cs b/BackEnd/Timeline.Tests/Services/UserPermissionServiceTest.cs index cea11b34..5a4e4954 100644 --- a/BackEnd/Timeline.Tests/Services/UserPermissionServiceTest.cs +++ b/BackEnd/Timeline.Tests/Services/UserPermissionServiceTest.cs @@ -9,7 +9,7 @@ namespace Timeline.Tests.Services {
public class UserPermissionServiceTest : DatabaseBasedTest
{
- private UserPermissionService _service;
+ private UserPermissionService _service = default!;
public UserPermissionServiceTest()
{
|