refactor: replace isTesting hacks with appsettings.Testing.json
The entire 'if (isTesting)' pattern is removed. Instead:
- Add appsettings.Testing.json: Database:Provider=InMemory,
DataProtection:Mode=Ephemeral, Hangfire:Enabled=false,
Database:MigrateOnStartup=false
- DependencyInjection reads configuration keys instead of
environment name
- Program.cs uses Hangfire:Enabled and Database:MigrateOnStartup
config booleans instead of IsEnvironment("Testing") checks
- Test fixture persists (UseEnvironment + UseSetting for
unique InMemoryDbName per instance)
No functional change — still 54/61 integration tests passing.
The 7 remaining failures are pre-existing 'expected 401 got 400'
auth middleware differences.
This commit is contained in:
1 parent
501da8dd0d
commit
81b8e6aacf
3 files changed
+23
-11
No files matched your search
@@ -175,11 +175,11 @@ builder.Services.AddOpenApi();
|
||||
builder.Services.AddApplication();
|
||||
|
||||
// ── Infrastructure layer ──────────────────────────────────────────
|
||||
builder.Services.AddInfrastructure(builder.Configuration,
|
||||
builder.Environment.EnvironmentName);
|
||||
builder.Services.AddInfrastructure(builder.Configuration);
|
||||
|
||||
// ── Database connection string (for Hangfire) ─────────────────────
|
||||
if (!builder.Environment.IsEnvironment("Testing"))
|
||||
var hangfireEnabled = builder.Configuration.GetValue<bool>("Hangfire:Enabled");
|
||||
if (hangfireEnabled)
|
||||
{
|
||||
var connectionString = Environment.GetEnvironmentVariable("DATABASE_URL")
|
||||
?? builder.Configuration.GetConnectionString("Default")
|
||||
@@ -388,8 +388,9 @@ app.MapPost("/_auth/signout", async (HttpContext httpContext, ILogger<Program> l
|
||||
// ── Apply pending database migrations ────────────────────────────────
|
||||
// Retry with exponential backoff to handle container startup races where
|
||||
// PostgreSQL accepts TCP connections but isn't ready to serve queries yet.
|
||||
// Skipped in Testing — integration tests use InMemory database.
|
||||
if (!app.Environment.IsEnvironment("Testing"))
|
||||
// Controlled by Database:MigrateOnStartup config (false in Testing).
|
||||
var migrateOnStartup = builder.Configuration.GetValue<bool>("Database:MigrateOnStartup");
|
||||
if (migrateOnStartup)
|
||||
{
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user