diff options
author | crupest <crupest@outlook.com> | 2022-12-20 18:50:28 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-12-20 20:32:53 +0800 |
commit | ea6afcf68bd10d5dbae5b99e590794dd219ea413 (patch) | |
tree | fed671901f8e25ba2ce38a3bb52f3a70d6f6801a /docker/crupest-api | |
parent | ec16e4673a6050c1daa451c6dcfe94bdf36c27f3 (diff) | |
download | crupest-ea6afcf68bd10d5dbae5b99e590794dd219ea413.tar.gz crupest-ea6afcf68bd10d5dbae5b99e590794dd219ea413.tar.bz2 crupest-ea6afcf68bd10d5dbae5b99e590794dd219ea413.zip |
Develop secret api. v48
Diffstat (limited to 'docker/crupest-api')
-rw-r--r-- | docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/CrudTestBase.cs | 44 | ||||
-rw-r--r-- | docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/CrupestApi.Commons.Tests.csproj | 3 |
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">
|