11using System ;
2+ using System . Data ;
23using System . Threading ;
34using System . Threading . Tasks ;
45using DotNetProjects . Migrator . Framework ;
1314using Migrator . Tests . Settings ;
1415using Migrator . Tests . Settings . Config ;
1516using Migrator . Tests . Settings . Models ;
17+ using Npgsql ;
1618using NUnit . Framework ;
1719
1820namespace Migrator . Tests . Providers . Base ;
@@ -22,13 +24,24 @@ namespace Migrator.Tests.Providers.Base;
2224/// </summary>
2325public abstract class TransformationProviderBase
2426{
27+ private IDbConnection _dbConnection ;
28+
2529 [ TearDown ]
2630 public virtual void TearDown ( )
2731 {
2832 DropTestTables ( ) ;
2933
3034 Provider ? . Rollback ( ) ;
31- Provider ? . Dispose ( ) ;
35+
36+ if ( _dbConnection != null )
37+ {
38+ if ( _dbConnection . State == ConnectionState . Open )
39+ {
40+ _dbConnection . Close ( ) ;
41+ }
42+
43+ _dbConnection . Dispose ( ) ;
44+ }
3245 }
3346
3447 protected void DropTestTables ( )
@@ -109,7 +122,10 @@ protected async Task BeginPostgreSQLTransactionAsync()
109122 var postgreIntegrationTestService = databaseIntegrationTestServiceFactory . Create ( DatabaseProviderType . Postgres ) ;
110123 var databaseInfo = await postgreIntegrationTestService . CreateTestDatabaseAsync ( databaseConnectionConfig , cts . Token ) ;
111124
112- Provider = new PostgreSQLTransformationProvider ( new PostgreSQLDialect ( ) , databaseInfo . DatabaseConnectionConfig . ConnectionString , null , "default" , "Npgsql" ) ;
125+
126+ _dbConnection = new NpgsqlConnection ( databaseInfo . DatabaseConnectionConfig . ConnectionString ) ;
127+
128+ Provider = new PostgreSQLTransformationProvider ( new PostgreSQLDialect ( ) , _dbConnection , null , "default" , "Npgsql" ) ;
113129 Provider . BeginTransaction ( ) ;
114130
115131 await Task . CompletedTask ;
0 commit comments