Skip to content

Commit e982134

Browse files
0xcedHofmeisterAn
andauthoredDec 1, 2024··
fix: Postpone exception in DbContainerFixture to match the behavior of ContainerFixture (#1310)
Co-authored-by: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com>
1 parent 1f78b90 commit e982134

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed
 

‎src/Testcontainers.Xunit/DbContainerFixture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected override async LifetimeTask InitializeAsync()
2121
await base.InitializeAsync()
2222
.ConfigureAwait(false);
2323

24-
_testMethods = new DbContainerTestMethods(DbProviderFactory, ConnectionString);
24+
_testMethods = new DbContainerTestMethods(DbProviderFactory, new Lazy<string>(() => ConnectionString));
2525
}
2626

2727
/// <inheritdoc />

‎src/Testcontainers.Xunit/DbContainerTest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ protected override async LifetimeTask InitializeAsync()
2020
await base.InitializeAsync()
2121
.ConfigureAwait(false);
2222

23-
_testMethods = new DbContainerTestMethods(DbProviderFactory, ConnectionString);
23+
_testMethods = new DbContainerTestMethods(DbProviderFactory, new Lazy<string>(() => ConnectionString));
2424
}
2525

2626
/// <inheritdoc />

‎src/Testcontainers.Xunit/DbContainerTestMethods.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
namespace Testcontainers.Xunit;
22

3-
internal sealed class DbContainerTestMethods(DbProviderFactory dbProviderFactory, string connectionString) : IDbContainerTestMethods, IAsyncDisposable
3+
internal sealed class DbContainerTestMethods(DbProviderFactory dbProviderFactory, Lazy<string> connectionString) : IDbContainerTestMethods, IAsyncDisposable
44
{
55
private readonly DbProviderFactory _dbProviderFactory = dbProviderFactory ?? throw new ArgumentNullException(nameof(dbProviderFactory));
6-
private readonly string _connectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
6+
private readonly Lazy<string> _connectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
77

88
#if NET8_0_OR_GREATER
99
[CanBeNull]
@@ -12,7 +12,7 @@ private DbDataSource DbDataSource
1212
{
1313
get
1414
{
15-
_dbDataSource ??= _dbProviderFactory.CreateDataSource(_connectionString);
15+
_dbDataSource ??= _dbProviderFactory.CreateDataSource(_connectionString.Value);
1616
return _dbDataSource;
1717
}
1818
}
@@ -32,7 +32,7 @@ private DbDataSource DbDataSource
3232
public DbConnection CreateConnection()
3333
{
3434
var connection = _dbProviderFactory.CreateConnection() ?? throw new InvalidOperationException($"DbProviderFactory.CreateConnection() returned null for {_dbProviderFactory}");
35-
connection.ConnectionString = _connectionString;
35+
connection.ConnectionString = _connectionString.Value;
3636
return connection;
3737
}
3838

0 commit comments

Comments
 (0)