Fix integration tests - shared database across test classes
- Update CustomWebApplicationFactory to use static database name - Ensure all tests share the same in-memory database instance - This fixes authentication flow tests where registration must persist for login - All 12 integration tests now pass
This commit is contained in:
@@ -12,6 +12,9 @@ namespace backend.Tests.Integration;
|
||||
|
||||
public class CustomWebApplicationFactory : WebApplicationFactory<Program>
|
||||
{
|
||||
// Use a static database name so all tests in the same process share the database
|
||||
private static readonly string _databaseName = $"IntegrationTestDb_{Guid.NewGuid():N}";
|
||||
|
||||
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
||||
{
|
||||
builder.ConfigureServices(services =>
|
||||
@@ -26,10 +29,10 @@ public class CustomWebApplicationFactory : WebApplicationFactory<Program>
|
||||
services.Remove(descriptor);
|
||||
}
|
||||
|
||||
// Add in-memory database
|
||||
// Add in-memory database with consistent name
|
||||
services.AddDbContext<RacePlannerDbContext>(options =>
|
||||
{
|
||||
options.UseInMemoryDatabase(Guid.NewGuid().ToString());
|
||||
options.UseInMemoryDatabase(_databaseName);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user