namespace FiscalOS.API.Tests.Integration; public abstract class IntegrationTest(TestApi testApi) : IClassFixture, IAsyncLifetime { public HttpClient Client => testApi.CreateClient(); public async ValueTask InitializeAsync() { await ExecuteDbContextAsync(static async context => { await context.Database.EnsureCreatedAsync(); }); } protected async Task ExecuteDbContextAsync(Func action) { await using var scope = testApi.Services.CreateAsyncScope(); var context = scope.ServiceProvider.GetRequiredService(); await action(context); } protected async Task ExecuteDbContextAsync(Func action) { await using var scope = testApi.Services.CreateAsyncScope(); var context = scope.ServiceProvider.GetRequiredService(); await action(context, scope.ServiceProvider); } protected async Task ExecuteDbContextAsync(Func> action) { await using var scope = testApi.Services.CreateAsyncScope(); var context = scope.ServiceProvider.GetRequiredService(); return await action(context); } protected async Task ExecuteDbContextAsync(Func> action) { await using var scope = testApi.Services.CreateAsyncScope(); var context = scope.ServiceProvider.GetRequiredService(); return await action(context, scope.ServiceProvider); } public async ValueTask DisposeAsync() { await ExecuteDbContextAsync(static async context => { await context.Database.EnsureDeletedAsync(); }); GC.SuppressFinalize(this); } }