Initial import
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user