diff --git a/tests/SimpleModule.Tests.Shared/Fixtures/SimpleModuleWebApplicationFactory.cs b/tests/SimpleModule.Tests.Shared/Fixtures/SimpleModuleWebApplicationFactory.cs index a4f6af3c..56fa4904 100644 --- a/tests/SimpleModule.Tests.Shared/Fixtures/SimpleModuleWebApplicationFactory.cs +++ b/tests/SimpleModule.Tests.Shared/Fixtures/SimpleModuleWebApplicationFactory.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.DependencyInjection; using SimpleModule.AuditLogs; using SimpleModule.BackgroundJobs; +using SimpleModule.Core.Maintenance; using SimpleModule.Database; using SimpleModule.Email; using SimpleModule.FeatureFlags; @@ -92,6 +93,19 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) services ); + // Replace the file-based maintenance state provider with a no-op so that + // a leftover .maintenance sentinel on the developer's machine (or a CI + // agent that ran `sm down`) cannot block API requests and cause spurious + // test failures with 503 responses. + var maintenanceDescriptor = services.SingleOrDefault(d => + d.ServiceType == typeof(IMaintenanceStateProvider) + ); + if (maintenanceDescriptor is not null) + { + services.Remove(maintenanceDescriptor); + } + services.AddSingleton(); + // Add test authentication scheme that bypasses OpenIddict validation services.AddTestAuthentication(); @@ -182,4 +196,14 @@ private static void TryDeleteWolverineDb() } #pragma warning restore CA1031 } + + /// + /// Always reports the application as live. Prevents a stale .maintenance + /// sentinel on the developer's machine from returning 503 for every test request. + /// + private sealed class NullMaintenanceStateProvider : IMaintenanceStateProvider + { + public ValueTask GetAsync(CancellationToken cancellationToken = default) => + ValueTask.FromResult(null); + } }