aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-02-12 18:27:41 +0800
committercrupest <crupest@outlook.com>2021-02-12 18:27:41 +0800
commit0ecc55b0deba68cd2ff923a7a14d1d50502fd976 (patch)
treefb05389a427f28fb5fefa6e84a10999a58afaee3
parentdeb706418d0a312ca7bc468b973af5b25edd4b0d (diff)
downloadtimeline-0ecc55b0deba68cd2ff923a7a14d1d50502fd976.tar.gz
timeline-0ecc55b0deba68cd2ff923a7a14d1d50502fd976.tar.bz2
timeline-0ecc55b0deba68cd2ff923a7a14d1d50502fd976.zip
test: Add multiple data post test.
-rw-r--r--BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs78
1 files changed, 78 insertions, 0 deletions
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs
index 4563db3a..c5ff507f 100644
--- a/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs
+++ b/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs
@@ -488,5 +488,83 @@ namespace Timeline.Tests.IntegratedTests
body.Should().Equal(data.Data);
}
}
+
+ [Theory]
+ [MemberData(nameof(TimelineNameGeneratorTestData))]
+ public async Task CreatePost_MultipleData_ShouldWork(TimelineNameGenerator generator)
+ {
+ using var client = await CreateClientAsUser();
+
+ var textData = Encoding.UTF8.GetBytes("aaa");
+ var imageData = ImageHelper.CreatePngWithSize(100, 50);
+
+ var post = await client.TestPostAsync<HttpTimelinePost>(
+ $"timelines/{generator(1)}/posts",
+ new HttpTimelinePostCreateRequest
+ {
+ DataList = new List<HttpTimelinePostCreateRequestData>
+ {
+ new HttpTimelinePostCreateRequestData
+ {
+ ContentType = MimeTypes.TextMarkdown,
+ Data = Convert.ToBase64String(textData)
+ },
+ new HttpTimelinePostCreateRequestData
+ {
+ ContentType = MimeTypes.ImagePng,
+ Data = Convert.ToBase64String(imageData)
+ }
+ }
+ }
+ );
+
+ post.DataList.Should().NotBeNull().And.HaveCount(2);
+
+ var postData0 = post.DataList[0];
+ postData0.Should().NotBeNull();
+ var postDataEtag0 = postData0.ETag;
+ postDataEtag0.Should().NotBeNullOrEmpty();
+
+ var postData1 = post.DataList[1];
+ postData1.Should().NotBeNull();
+ var postDataEtag1 = postData1.ETag;
+ postDataEtag1.Should().NotBeNullOrEmpty();
+
+ {
+ var response = await client.GetAsync($"timelines/{generator(1)}/posts/{post.Id}/data");
+ response.StatusCode.Should().Be(HttpStatusCode.OK);
+ response.Headers.ETag.Should().NotBeNull();
+ response.Headers.ETag!.Tag.Should().Be(postDataEtag0);
+ response.Content.Headers.ContentType.Should().NotBeNull();
+ response.Content.Headers.ContentType!.MediaType.Should().Be(MimeTypes.TextMarkdown);
+
+ var body = await response.Content.ReadAsByteArrayAsync();
+ body.Should().Equal(textData);
+ }
+
+ {
+ var response = await client.GetAsync($"timelines/{generator(1)}/posts/{post.Id}/data/0");
+ response.StatusCode.Should().Be(HttpStatusCode.OK);
+ response.Headers.ETag.Should().NotBeNull();
+ response.Headers.ETag!.Tag.Should().Be(postDataEtag0);
+ response.Content.Headers.ContentType.Should().NotBeNull();
+ response.Content.Headers.ContentType!.MediaType.Should().Be(MimeTypes.TextMarkdown);
+
+ var body = await response.Content.ReadAsByteArrayAsync();
+ body.Should().Equal(textData);
+ }
+
+ {
+ var response = await client.GetAsync($"timelines/{generator(1)}/posts/{post.Id}/data/1");
+ response.StatusCode.Should().Be(HttpStatusCode.OK);
+ response.Headers.ETag.Should().NotBeNull();
+ response.Headers.ETag!.Tag.Should().Be(postDataEtag1);
+ response.Content.Headers.ContentType.Should().NotBeNull();
+ response.Content.Headers.ContentType!.MediaType.Should().Be(MimeTypes.ImagePng);
+
+ var body = await response.Content.ReadAsByteArrayAsync();
+ body.Should().Equal(imageData);
+ }
+ }
}
}