| 1 | using Microsoft.AspNetCore.Hosting; |
| 2 | using Microsoft.AspNetCore.Mvc.Testing; |
| 3 | using Microsoft.Extensions.Configuration; |
| 4 | |
| 5 | namespace IntercomService.Tests; |
| 6 | |
| 7 | public sealed class IntercomWebApplicationFactory : WebApplicationFactory<Program> |
| 8 | { |
| 9 | private readonly string _dataDir = Path.Combine(Path.GetTempPath(), "intercom-service-tests", Guid.NewGuid().ToString("N")); |
| 10 | |
| 11 | protected override void ConfigureWebHost(IWebHostBuilder builder) |
| 12 | { |
| 13 | builder.UseEnvironment("Development"); |
| 14 | builder.ConfigureAppConfiguration(config => |
| 15 | { |
| 16 | config.AddInMemoryCollection(new Dictionary<string, string?> |
| 17 | { |
| 18 | ["Intercom:DataDirectory"] = _dataDir, |
| 19 | ["Intercom:RecreateDatabaseOnStart"] = "true", |
| 20 | ["DevAuth:TeamToken"] = "dev-intercom-local-change-me", |
| 21 | }); |
| 22 | }); |
| 23 | } |
| 24 | |
| 25 | protected override void Dispose(bool disposing) |
| 26 | { |
| 27 | if (disposing && Directory.Exists(_dataDir)) |
| 28 | { |
| 29 | try { Directory.Delete(_dataDir, recursive: true); } |
| 30 | catch { /* best effort */ } |
| 31 | } |
| 32 | |
| 33 | base.Dispose(disposing); |
| 34 | } |
| 35 | } |
| 36 | |
View only · write via MCP/CIDE