fix(backend): Fix Integration Test database provider conflict with environment-aware DI
Implement environment-aware dependency injection to resolve EF Core provider conflict in Integration Tests. The issue was caused by both PostgreSQL and InMemory providers being registered in the same service provider. Changes: - Modified Identity Module DependencyInjection to skip PostgreSQL DbContext registration in Testing environment - Modified ProjectManagement Module ModuleExtensions with same environment check - Updated Program.cs to pass IHostEnvironment to both module registration methods - Added Microsoft.Extensions.Hosting.Abstractions package to Identity.Infrastructure project - Updated ColaFlowWebApplicationFactory to set Testing environment and register InMemory databases - Simplified WebApplicationFactory by removing complex RemoveAll logic Results: - All 31 Integration Tests now run (previously only 1 ran) - No EF Core provider conflict errors - 23 tests pass, 8 tests fail (failures are business logic issues, not infrastructure) - Production environment still uses PostgreSQL as expected 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -10,11 +10,11 @@ using System.Text;
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Register ProjectManagement Module
|
||||
builder.Services.AddProjectManagementModule(builder.Configuration);
|
||||
builder.Services.AddProjectManagementModule(builder.Configuration, builder.Environment);
|
||||
|
||||
// Register Identity Module
|
||||
builder.Services.AddIdentityApplication();
|
||||
builder.Services.AddIdentityInfrastructure(builder.Configuration);
|
||||
builder.Services.AddIdentityInfrastructure(builder.Configuration, builder.Environment);
|
||||
|
||||
// Add controllers
|
||||
builder.Services.AddControllers();
|
||||
@@ -107,3 +107,6 @@ app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
|
||||
// Make the implicit Program class public for integration tests
|
||||
public partial class Program { }
|
||||
|
||||
Reference in New Issue
Block a user