Initial import

This commit is contained in:
Stein Helge Riise
2025-11-17 08:32:46 +01:00
commit ede31fbb7e
129 changed files with 9514 additions and 0 deletions
@@ -0,0 +1,22 @@
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using MinAttest.Infrastructure.Data;
namespace MinAttest.Tests.Integration.Server;
public class ApiWebAppFactory : WebApplicationFactory<Program>
{
protected override void ConfigureWebHost(Microsoft.AspNetCore.Hosting.IWebHostBuilder builder)
{
builder.ConfigureServices(services =>
{
var descriptor = services.SingleOrDefault(d => d.ServiceType == typeof(DbContextOptions<AppDbContext>));
if (descriptor is not null)
{
services.Remove(descriptor);
}
services.AddDbContext<AppDbContext>(options => options.UseSqlServer(TestDb.ConnectionString));
});
}
}
@@ -0,0 +1,42 @@
using Testcontainers.MsSql;
namespace MinAttest.Tests.Integration.Server;
public static class TestDb
{
private static MsSqlContainer? _container;
private static readonly object _lock = new();
private static bool _started;
public static string ConnectionString { get; private set; } = string.Empty;
public static async Task StartAsync()
{
if (_started) return;
lock (_lock)
{
if (_container == null)
{
_container = new MsSqlBuilder()
.WithImage("mcr.microsoft.com/mssql/server:2022-latest")
.WithPassword("Your_password123")
.WithPortBinding(14333, 1433)
.Build();
}
}
await _container!.StartAsync();
ConnectionString = _container.GetConnectionString() + ";Database=MinAttest_Integration";
_started = true;
}
public static async Task StopAsync()
{
if (_container is null) return;
await _container.StopAsync();
await _container.DisposeAsync();
_container = null;
_started = false;
ConnectionString = string.Empty;
}
}