@@ -11,6 +11,7 @@ namespace QueryKit.IntegrationTests;
1111using Microsoft . Extensions . DependencyInjection ;
1212using Microsoft . Extensions . DependencyInjection . Extensions ;
1313using Moq ;
14+ using Testcontainers . PostgreSql ;
1415using WebApiTestProject ;
1516using WebApiTestProject . Database ;
1617using Xunit ;
@@ -21,7 +22,7 @@ public class TestFixtureCollection : ICollectionFixture<TestFixture> {}
2122public class TestFixture : IAsyncLifetime
2223{
2324 public static IServiceScopeFactory BaseScopeFactory ;
24- private readonly TestcontainerDatabase _dbContainer = DbSetup ( ) ;
25+ private PostgreSqlContainer _dbContainer ;
2526
2627 public async Task InitializeAsync ( )
2728 {
@@ -30,9 +31,10 @@ public async Task InitializeAsync()
3031 EnvironmentName = Consts . Testing . IntegrationTestingEnvName
3132 } ) ;
3233
34+ _dbContainer = new PostgreSqlBuilder ( ) . Build ( ) ;
3335 await _dbContainer . StartAsync ( ) ;
34- builder . Configuration . GetSection ( ConnectionStringOptions . SectionName ) [ ConnectionStringOptions . RecipeManagementKey ] = _dbContainer . ConnectionString ;
35- await RunMigration ( _dbContainer . ConnectionString ) ;
36+ builder . Configuration . GetSection ( ConnectionStringOptions . SectionName ) [ ConnectionStringOptions . RecipeManagementKey ] = _dbContainer . GetConnectionString ( ) ;
37+ await RunMigration ( _dbContainer . GetConnectionString ( ) ) ;
3638
3739 builder . ConfigureServices ( ) ;
3840 var services = builder . Services ;
@@ -53,21 +55,7 @@ private static async Task RunMigration(string connectionString)
5355 var context = new TestingDbContext ( options ) ;
5456 await context ? . Database ? . MigrateAsync ( ) ;
5557 }
56-
57- private static TestcontainerDatabase DbSetup ( )
58- {
59- return new TestcontainersBuilder < PostgreSqlTestcontainer > ( )
60- . WithDatabase ( new PostgreSqlTestcontainerConfiguration
61- {
62- Database = "db" ,
63- Username = "postgres" ,
64- Password = "postgres"
65- } )
66- . WithName ( $ "IntegrationTesting_QueryKit_{ Guid . NewGuid ( ) } ")
67- . WithImage ( "postgres:latest" )
68- . Build ( ) ;
69- }
70-
58+
7159 public async Task DisposeAsync ( )
7260 {
7361 await _dbContainer . DisposeAsync ( ) ;
0 commit comments