aboutsummaryrefslogtreecommitdiff
path: root/Timeline.Tests
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-08-31 22:22:57 +0800
committercrupest <crupest@outlook.com>2020-08-31 22:22:57 +0800
commitc73388256aad039239cf3977d7b079e3f9323258 (patch)
treec8f4b17ebb6623a6bafc03a2417d18b8615f94a0 /Timeline.Tests
parent12410a51fb2e5f55e8d83415bc3c4053a146ce3b (diff)
downloadtimeline-c73388256aad039239cf3977d7b079e3f9323258.tar.gz
timeline-c73388256aad039239cf3977d7b079e3f9323258.tar.bz2
timeline-c73388256aad039239cf3977d7b079e3f9323258.zip
Now uesr avatar put api returns etag.
Diffstat (limited to 'Timeline.Tests')
-rw-r--r--Timeline.Tests/Helpers/HttpResponseExtensions.cs35
-rw-r--r--Timeline.Tests/IntegratedTests/UserAvatarTest.cs25
2 files changed, 60 insertions, 0 deletions
diff --git a/Timeline.Tests/Helpers/HttpResponseExtensions.cs b/Timeline.Tests/Helpers/HttpResponseExtensions.cs
new file mode 100644
index 00000000..2bd497f1
--- /dev/null
+++ b/Timeline.Tests/Helpers/HttpResponseExtensions.cs
@@ -0,0 +1,35 @@
+using System.Net.Http;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+using System.Threading.Tasks;
+using Timeline.Models.Converters;
+using Timeline.Models.Http;
+
+namespace Timeline.Tests.Helpers
+{
+ public static class HttpResponseExtensions
+ {
+ public static JsonSerializerOptions JsonSerializerOptions { get; }
+
+ static HttpResponseExtensions()
+ {
+ JsonSerializerOptions = new JsonSerializerOptions
+ {
+ PropertyNamingPolicy = JsonNamingPolicy.CamelCase
+ };
+ JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
+ JsonSerializerOptions.Converters.Add(new JsonDateTimeConverter());
+ }
+
+ public static async Task<T> ReadBodyAsJsonAsync<T>(this HttpResponseMessage response)
+ {
+ var stream = await response.Content.ReadAsStreamAsync();
+ return await JsonSerializer.DeserializeAsync<T>(stream, JsonSerializerOptions);
+ }
+
+ public static Task<CommonResponse> ReadBodyAsCommonResponseAsync(this HttpResponseMessage response)
+ {
+ return response.ReadBodyAsJsonAsync<CommonResponse>();
+ }
+ }
+}
diff --git a/Timeline.Tests/IntegratedTests/UserAvatarTest.cs b/Timeline.Tests/IntegratedTests/UserAvatarTest.cs
index 507b05ba..f2796005 100644
--- a/Timeline.Tests/IntegratedTests/UserAvatarTest.cs
+++ b/Timeline.Tests/IntegratedTests/UserAvatarTest.cs
@@ -10,6 +10,7 @@ using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
+using System.Net.Mime;
using System.Threading.Tasks;
using Timeline.Models.Http;
using Timeline.Services;
@@ -222,5 +223,29 @@ namespace Timeline.Tests.IntegratedTests
}
}
}
+
+ [Fact]
+ public async Task AvatarPutReturnETag()
+ {
+ using var client = await CreateClientAsUser();
+
+ EntityTagHeaderValue etag;
+
+ {
+ var image = ImageHelper.CreatePngWithSize(100, 100);
+ var res = await client.PutByteArrayAsync("users/user1/avatar", image, PngFormat.Instance.DefaultMimeType);
+ res.Should().HaveStatusCode(200);
+ etag = res.Headers.ETag;
+ etag.Should().NotBeNull();
+ etag.Tag.Should().NotBeNullOrEmpty();
+ }
+
+ {
+ var res = await client.GetAsync("users/user1/avatar");
+ res.Should().HaveStatusCode(200);
+ res.Headers.ETag.Should().Be(etag);
+ res.Headers.ETag.Tag.Should().Be(etag.Tag);
+ }
+ }
}
} \ No newline at end of file