using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.Configuration;

namespace Freman.Sample.Web.IntegrationTests.TestHost;

public sealed class SampleWebFactory(string connectionString) : WebApplicationFactory<Program>
{
    protected override void ConfigureWebHost(IWebHostBuilder builder)
    {
        builder.UseEnvironment("Testing");

        builder.ConfigureAppConfiguration((_, config) =>
        {
            var overrides = new Dictionary<string, string?>
            {
                ["ConnectionStrings:AppDb"] = connectionString,
                ["ApplyMigrationsOnStartup"] = "false"
            };

            config.AddInMemoryCollection(overrides);
        });
    }
}