From d37936cdea3e257388506dd055194a0b752263a3 Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 21 Dec 2022 11:51:25 +0800 Subject: Develop secret api. v51 --- .../CrupestApi.Commons.Tests/Crud/CrudTestBase.cs | 74 ---------------------- 1 file changed, 74 deletions(-) delete mode 100644 docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/CrudTestBase.cs (limited to 'docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/CrudTestBase.cs') diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/CrudTestBase.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/CrudTestBase.cs deleted file mode 100644 index 98c0dfd..0000000 --- a/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/CrudTestBase.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System.Net; -using CrupestApi.Commons.Secrets; -using Microsoft.AspNetCore.TestHost; - -namespace CrupestApi.Commons.Crud.Tests; - -public abstract class CrudTestBase : IAsyncDisposable where TEntity : class -{ - 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.AddCrud(); - ConfigureApplication(builder); - _app = builder.Build(); - - if (authKey is not null) - { - using (var scope = _app.Services.CreateScope()) - { - var secretService = scope.ServiceProvider.GetRequiredService(); - secretService.CreateTestSecret(authKey, "test-secret"); - } - } - - _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(); - } - - public async Task TestAuth() - { - if (_authKey is null) - { - return; - } - - { - using var response = await _client.GetAsync(_path); - Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); - } - - { - var entity = Activator.CreateInstance(); - using var response = await _client.PostAsJsonAsync(_path, entity); - Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); - } - } -} -- cgit v1.2.3