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