diff options
author | crupest <crupest@outlook.com> | 2020-08-31 22:22:57 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-08-31 22:22:57 +0800 |
commit | 4dda5d088330e76844010a4f89049ea207652318 (patch) | |
tree | 2734232fc25cce0cedc05570482015c8f6f01199 /Timeline.Tests/Helpers/HttpResponseExtensions.cs | |
parent | 315a5fa6eea7511618266877fca6aa1275caed1c (diff) | |
download | timeline-4dda5d088330e76844010a4f89049ea207652318.tar.gz timeline-4dda5d088330e76844010a4f89049ea207652318.tar.bz2 timeline-4dda5d088330e76844010a4f89049ea207652318.zip |
Now uesr avatar put api returns etag.
Diffstat (limited to 'Timeline.Tests/Helpers/HttpResponseExtensions.cs')
-rw-r--r-- | Timeline.Tests/Helpers/HttpResponseExtensions.cs | 35 |
1 files changed, 35 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>();
+ }
+ }
+}
|