using EventFlow; using EventFlow.Aggregates; using Microsoft.Extensions.DependencyInjection; namespace Books.Api.Tests.Infrastructure; /// /// Base class for integration tests with isolated database per test class. /// Uses IClassFixture pattern - each test class gets its own database. /// public abstract class IntegrationTestBase : IClassFixture, IDisposable { protected readonly TestWebApplicationFactory Factory; protected readonly HttpClient Client; private readonly IServiceScope _scope; protected IntegrationTestBase(TestWebApplicationFactory factory) { Factory = factory; Client = factory.CreateGraphQLClient(); _scope = factory.Services.CreateScope(); } protected IServiceProvider Services => _scope.ServiceProvider; protected ICommandBus CommandBus => Services.GetRequiredService(); protected IAggregateStore AggregateStore => Services.GetRequiredService(); protected T GetService() where T : notnull => Services.GetRequiredService(); public void Dispose() { _scope?.Dispose(); GC.SuppressFinalize(this); } }