public async Task ContainerLifecyle() { const string containerName = "ContainerLifecyle"; using (var testDatabaseThatDoesntStop = new SqlServerDockerDatabase( new SqlServerDockerDatabaseOptions(stopDockerInstanceOnDispose: false, dockerSqlServerHostPort: 1457, dockerContainerName: containerName), _logger)) { await _dockerClient.ShouldReportRunningContainerNamedAsync(containerName); await using var connection = new SqlConnection(testDatabaseThatDoesntStop.GetConnectionString()); await connection.OpenAsync(); await connection.ShouldReportVersionAsync("Microsoft SQL Server 2019"); } var firstContainersId = await _dockerClient.ShouldReportRunningContainerNamedAsync(containerName); using (var testDatabaseThatDoesntRemove = new SqlServerDockerDatabase( new SqlServerDockerDatabaseOptions(removeDockerContainerOnDispose: false, dockerSqlServerHostPort: 1457, dockerContainerName: containerName), _logger)) { var secondContainersId = await _dockerClient.ShouldReportRunningContainerNamedAsync(containerName); firstContainersId.Should().NotBe(secondContainersId, "because a new container should be created each time"); await using var connection = new SqlConnection(testDatabaseThatDoesntRemove.GetConnectionString()); await connection.OpenAsync(); await connection.ShouldReportVersionAsync("Microsoft SQL Server 2019"); } await _dockerClient.ShouldReportStoppedContainerNamedAsync(containerName); using (var testDatabaseThatRemoves = new SqlServerDockerDatabase( new SqlServerDockerDatabaseOptions(dockerSqlServerHostPort: 1457, dockerContainerName: containerName), _logger)) { await _dockerClient.ShouldReportRunningContainerNamedAsync(containerName); await using var connection = new SqlConnection(testDatabaseThatRemoves.GetConnectionString()); await connection.OpenAsync(); await connection.ShouldReportVersionAsync("Microsoft SQL Server 2019"); } await _dockerClient.ShouldReportNoContainerNamedAsync(containerName); }