I have an API REST .NET 7 and I want to build integrations tests using a sql server container database. I've tried to follow the example in the documentation (https://dotnet.testcontainers.org/examples/aspnet/):
const string weatherForecastStorage = "weatherForecastStorage";
var mssqlConfiguration = new MsSqlTestcontainerConfiguration();
mssqlConfiguration.Password = Guid.NewGuid().ToString("D");
mssqlConfiguration.Database = Guid.NewGuid().ToString("D");
var connectionString = $"server={weatherForecastStorage};user id=sa;password={mssqlConfiguration.Password};database={mssqlConfiguration.Database}";
_weatherForecastNetwork = new NetworkBuilder()
.WithName(Guid.NewGuid().ToString("D"))
.Build();
_mssqlContainer = new ContainerBuilder<MsSqlTestcontainer>()
.WithDatabase(mssqlConfiguration)
.WithNetwork(_weatherForecastNetwork)
.WithNetworkAliases(weatherForecastStorage)
.Build();
But the MsSqlTestcontainer and MsSqlTestcontainerConfiguration classes don't exist.
The nugget package version is 3.0.0 but the official documentation seems to be outdated because the constructor ContainerBuilder<> is also obsolete.
What I'm looking for is to create a container with a SQL SERVER image, then create a database/tables and use it with entity framework core (I don't know how to create them or even if this is necessary).
On the other hand, I tried something like this:
private readonly IContainer _dbContainer = new ContainerBuilder()
.WithImage("mcr.microsoft.com/mssql/server")
.WithEnvironment("MSSQL_SA_PASSWORD", "MyStrongPassword")
.WithEnvironment("ACCEPT_EULA", "Y")
.WithEnvironment("MSSQL_DATA_DIR", "/var/opt/sqlserver/data")
.WithEnvironment("MSSQL_LOG_DIR", "/var/opt/sqlserver/log")
.WithEnvironment("MSSQL_BACKUP_DIR", "/var/opt/sqlserver/backup")
.WithPortBinding(49401, 1433)
.WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(1433).UntilCommandIsCompleted("/bin/bash", "/opt/mssql-tools/bin/sqlcmd -S 127.0.0.1,1433 -U sa -P MyStrongPassword -d master -Q\"CREATE DATABASE Local_test"))
//.WithBindMount(Path.GetFullPath("sql"), "/scripts/")
//.WithCommand()
.Build();
But this doesn't work (Error: Docker.DotNet.DockerApiException : Docker API responded with status code=Conflict, response={"message":"Container 63d8dbd9c73f924b54ecddea5febc82589ccea452a3543eebb2aa3aa8b6bc408 is not running"} ).