aboutsummaryrefslogtreecommitdiff
path: root/Timeline.Tests/Helpers
diff options
context:
space:
mode:
Diffstat (limited to 'Timeline.Tests/Helpers')
-rw-r--r--Timeline.Tests/Helpers/HttpClientExtensions.cs9
-rw-r--r--Timeline.Tests/Helpers/ImageHelper.cs21
-rw-r--r--Timeline.Tests/Helpers/MyTestLoggerFactory.cs14
-rw-r--r--Timeline.Tests/Helpers/MyWebApplicationFactory.cs5
4 files changed, 49 insertions, 0 deletions
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<HttpResponseMessage> 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<Rgba32>(width, height))
+ {
+ using (var stream = new MemoryStream())
+ {
+ image.SaveAsPng(stream);
+ return stream.ToArray();
+ }
+ }
+ }
+ }
+}
diff --git a/Timeline.Tests/Helpers/MyTestLoggerFactory.cs b/Timeline.Tests/Helpers/MyTestLoggerFactory.cs
new file mode 100644
index 00000000..40c6a77e
--- /dev/null
+++ b/Timeline.Tests/Helpers/MyTestLoggerFactory.cs
@@ -0,0 +1,14 @@
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Logging.Testing;
+using Xunit.Abstractions;
+
+namespace Timeline.Tests.Helpers
+{
+ public static class MyTestLoggerFactory
+ {
+ public static LoggerFactory Create(ITestOutputHelper outputHelper)
+ {
+ return new LoggerFactory(new[] { new XunitLoggerProvider(outputHelper) });
+ }
+ }
+}
diff --git a/Timeline.Tests/Helpers/MyWebApplicationFactory.cs b/Timeline.Tests/Helpers/MyWebApplicationFactory.cs
index dfadd1ae..e96d11fe 100644
--- a/Timeline.Tests/Helpers/MyWebApplicationFactory.cs
+++ b/Timeline.Tests/Helpers/MyWebApplicationFactory.cs
@@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
@@ -37,6 +38,10 @@ namespace Timeline.Tests.Helpers
{
var options = new DbContextOptionsBuilder<DatabaseContext>()
.UseSqlite(_databaseConnection)
+ .ConfigureWarnings(builder =>
+ {
+ builder.Throw(RelationalEventId.QueryClientEvaluationWarning);
+ })
.Options;
using (var context = new DatabaseContext(options))