aboutsummaryrefslogtreecommitdiff
path: root/docker/crupest-api
diff options
context:
space:
mode:
Diffstat (limited to 'docker/crupest-api')
-rw-r--r--docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/CrudTestBase.cs44
-rw-r--r--docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/CrupestApi.Commons.Tests.csproj3
2 files changed, 46 insertions, 1 deletions
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/CrudTestBase.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/CrudTestBase.cs
new file mode 100644
index 0000000..117d0cf
--- /dev/null
+++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/CrudTestBase.cs
@@ -0,0 +1,44 @@
+using Microsoft.AspNetCore.TestHost;
+
+namespace CrupestApi.Commons.Crud.Tests;
+
+public abstract class CrudTestBase : IAsyncDisposable
+{
+ protected readonly WebApplication _app;
+
+ protected readonly string _path;
+ protected readonly string? _authKey;
+
+ protected readonly HttpClient _client;
+
+ public CrudTestBase(string path, string? authKey = null)
+ {
+ _path = path;
+ _authKey = authKey;
+
+ var builder = WebApplication.CreateBuilder();
+ builder.WebHost.UseTestServer();
+ builder.Services.AddCrudCore();
+ ConfigureApplication(builder);
+ _app = builder.Build();
+
+ _client = CreateHttpClient();
+ }
+
+ protected abstract void ConfigureApplication(WebApplicationBuilder builder);
+
+ public virtual async ValueTask DisposeAsync()
+ {
+ await _app.DisposeAsync();
+ }
+
+ public TestServer GetTestServer()
+ {
+ return _app.GetTestServer();
+ }
+
+ public HttpClient CreateHttpClient()
+ {
+ return GetTestServer().CreateClient();
+ }
+}
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/CrupestApi.Commons.Tests.csproj b/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/CrupestApi.Commons.Tests.csproj
index 59edf0d..0360ee1 100644
--- a/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/CrupestApi.Commons.Tests.csproj
+++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/CrupestApi.Commons.Tests.csproj
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
@@ -9,6 +9,7 @@
</PropertyGroup>
<ItemGroup>
+ <PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">