From 09af59ea133d01bbbeba76a448563189fa39e440 Mon Sep 17 00:00:00 2001 From: 杨宇千 Date: Mon, 19 Aug 2019 01:44:29 +0800 Subject: Add integrated tests. --- Timeline.Tests/Helpers/HttpClientExtensions.cs | 9 +++++++++ Timeline.Tests/Helpers/ImageHelper.cs | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 Timeline.Tests/Helpers/ImageHelper.cs (limited to 'Timeline.Tests/Helpers') diff --git a/Timeline.Tests/Helpers/HttpClientExtensions.cs b/Timeline.Tests/Helpers/HttpClientExtensions.cs index cd40d91e..b9204fcc 100644 --- a/Timeline.Tests/Helpers/HttpClientExtensions.cs +++ b/Timeline.Tests/Helpers/HttpClientExtensions.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using System.Net.Http; +using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; @@ -11,5 +12,13 @@ namespace Timeline.Tests.Helpers { return client.PatchAsync(url, new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json")); } + + public static Task PutByteArrayAsync(this HttpClient client, string url, byte[] body, string mimeType) + { + var content = new ByteArrayContent(body); + content.Headers.ContentLength = body.Length; + content.Headers.ContentType = new MediaTypeHeaderValue(mimeType); + return client.PutAsync(url, content); + } } } diff --git a/Timeline.Tests/Helpers/ImageHelper.cs b/Timeline.Tests/Helpers/ImageHelper.cs new file mode 100644 index 00000000..c5a9cf17 --- /dev/null +++ b/Timeline.Tests/Helpers/ImageHelper.cs @@ -0,0 +1,21 @@ +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.PixelFormats; +using System.IO; + +namespace Timeline.Tests.Helpers +{ + public static class ImageHelper + { + public static byte[] CreatePngWithSize(int width, int height) + { + using (var image = new Image(width, height)) + { + using (var stream = new MemoryStream()) + { + image.SaveAsPng(stream); + return stream.ToArray(); + } + } + } + } +} -- cgit v1.2.3