| 1 | using Microsoft.AspNetCore.Hosting; |
| 2 | using Microsoft.AspNetCore.Mvc.Testing; |
| 3 | using Microsoft.Data.Sqlite; |
| 4 | |
| 5 | namespace OpenAgentRegistry.Tests; |
| 6 | |
| 7 | public sealed class RegistryWebApplicationFactory : WebApplicationFactory<Program> |
| 8 | { |
| 9 | public string DatabasePath { get; } = Path.Combine(Path.GetTempPath(), $"oar-test-{Guid.NewGuid():N}.db"); |
| 10 | |
| 11 | public bool Require2Fa { get; init; } |
| 12 | |
| 13 | protected override void ConfigureWebHost(IWebHostBuilder builder) |
| 14 | { |
| 15 | Environment.SetEnvironmentVariable("OAR_DATABASE_PATH", DatabasePath); |
| 16 | Environment.SetEnvironmentVariable("OAR_PUBLIC_BASE_URL", "http://test.local"); |
| 17 | Environment.SetEnvironmentVariable("OAR_DEV_EXPOSE_CLAIM_CODES", "true"); |
| 18 | Environment.SetEnvironmentVariable("OAR_DEV_EXPOSE_TOTP_SECRET", "true"); |
| 19 | Environment.SetEnvironmentVariable("OAR_CLAIM_REQUIRE_2FA", Require2Fa ? "true" : "false"); |
| 20 | } |
| 21 | |
| 22 | protected override void Dispose(bool disposing) |
| 23 | { |
| 24 | base.Dispose(disposing); |
| 25 | SqliteConnection.ClearAllPools(); |
| 26 | if (File.Exists(DatabasePath)) |
| 27 | File.Delete(DatabasePath); |
| 28 | } |
| 29 | } |
| 30 | |
View only · write via MCP/CIDE