using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
namespace MeterVault.Integration.Tests;
///
/// Boots the real ASP.NET Core app in-memory against the shared Timescale container.
/// Migrations are already applied by , so startup migration is off.
///
public sealed class MeterVaultAppFactory(string connectionString, bool configureApiKey = true) : WebApplicationFactory
{
public const string ApiKey = "test-api-key";
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.UseEnvironment("Testing");
builder.UseSetting("ConnectionStrings:Default", connectionString);
builder.UseSetting("MeterVault:RunMigrationsAtStartup", "false");
builder.UseSetting("MeterVault:EnableLiveIngestion", "false");
// No outbound calls from tests: the update check would otherwise hit the real Gitea on every
// page render, making the suite slow and dependent on that host being up.
builder.UseSetting("MeterVault:UpdateCheckEnabled", "false");
if (configureApiKey)
{
builder.UseSetting("MeterVault:ApiKeys:0", ApiKey);
}
}
}