2026-07-16 21:19:16 +00:00
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Testing;
|
|
|
|
|
|
|
|
|
|
namespace Heimdall.IntegrationTests.Factories;
|
|
|
|
|
|
2026-07-17 13:15:25 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// WebApplicationFactory for integration tests.
|
2026-07-21 12:19:43 +00:00
|
|
|
/// Requires a PostgreSQL connection string from <see cref="PostgreSqlContainerFixture"/>.
|
2026-07-17 13:15:25 +00:00
|
|
|
/// </summary>
|
2026-07-16 21:19:16 +00:00
|
|
|
public class HeimdallWebApplicationFactory : WebApplicationFactory<Program>
|
|
|
|
|
{
|
2026-07-21 12:19:43 +00:00
|
|
|
private readonly string _connectionString;
|
2026-07-21 10:24:11 +00:00
|
|
|
|
2026-07-21 12:19:43 +00:00
|
|
|
/// <summary>Creates a factory connected to a real PostgreSQL instance via Testcontainers.</summary>
|
2026-07-21 10:24:11 +00:00
|
|
|
public HeimdallWebApplicationFactory(string connectionString)
|
|
|
|
|
{
|
|
|
|
|
_connectionString = connectionString;
|
|
|
|
|
}
|
2026-07-16 21:19:16 +00:00
|
|
|
|
|
|
|
|
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
builder.UseEnvironment("Testing");
|
|
|
|
|
builder.UseSetting("Cors:AllowedOrigins", "*");
|
2026-07-21 10:24:11 +00:00
|
|
|
|
2026-07-21 12:19:43 +00:00
|
|
|
builder.UseSetting("ConnectionStrings:Default", _connectionString);
|
|
|
|
|
builder.UseSetting("Database:MigrateOnStartup", "true");
|
2026-07-21 10:24:11 +00:00
|
|
|
|
2026-07-17 13:15:25 +00:00
|
|
|
// JWT config
|
|
|
|
|
builder.UseSetting("Jwt:Key", "ThisIsATestKeyThatIsAtLeast32BytesLong!");
|
2026-07-21 08:57:53 +00:00
|
|
|
builder.UseSetting("Jwt:RefreshKey", "ThisIsATestRefreshKeyThatIsAlso32Bytes!");
|
2026-07-17 13:15:25 +00:00
|
|
|
builder.UseSetting("Jwt:Issuer", "heimdall-test");
|
|
|
|
|
builder.UseSetting("Jwt:Audience", "heimdall-test");
|
2026-07-16 21:19:16 +00:00
|
|
|
}
|
|
|
|
|
}
|