using ColaFlow.Modules.Identity.Application.Services; using ColaFlow.Modules.Identity.Infrastructure.Services; using Microsoft.Extensions.DependencyInjection; namespace ColaFlow.Modules.Identity.IntegrationTests.Infrastructure; /// /// Database Fixture for In-Memory Database Tests /// Implements IClassFixture for xUnit test lifecycle management /// Each test class gets its own isolated database instance /// public class DatabaseFixture : IDisposable { public ColaFlowWebApplicationFactory Factory { get; } = new(useInMemoryDatabase: true); // Note: Client property is kept for backward compatibility but creates new instances // Tests should call CreateClient() for isolation to avoid shared state issues public HttpClient Client => CreateClient(); // Use In-Memory Database for fast, isolated tests /// /// Creates a new HttpClient for each test to ensure test isolation /// Prevents Authorization header sharing between tests /// public HttpClient CreateClient() { return Factory.CreateClient(); } /// /// Gets the MockEmailService from the DI container for testing /// public MockEmailService GetEmailService() { var scope = Factory.Services.CreateScope(); var emailService = scope.ServiceProvider.GetRequiredService(); return (MockEmailService)emailService; } public void Dispose() { Factory?.Dispose(); GC.SuppressFinalize(this); } }