diff options
author | crupest <crupest@outlook.com> | 2021-02-12 18:27:41 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-02-12 18:27:41 +0800 |
commit | 65c2c772d6625d8a793b6174b554b6c6943f41ad (patch) | |
tree | ba85f6afbf57b9bcfb2653bf94861594d8aa2815 | |
parent | b5b758c41a01ab7f78f0711debe92f6add470c64 (diff) | |
download | timeline-65c2c772d6625d8a793b6174b554b6c6943f41ad.tar.gz timeline-65c2c772d6625d8a793b6174b554b6c6943f41ad.tar.bz2 timeline-65c2c772d6625d8a793b6174b554b6c6943f41ad.zip |
test: Add multiple data post test.
-rw-r--r-- | BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs | 78 |
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);
+ }
+ }
}
}
|