99
1010namespace JsonApiDotNetCoreTests . IntegrationTests . AtomicOperations . Transactions ;
1111
12- public sealed class AtomicTransactionConsistencyTests : IClassFixture < IntegrationTestContext < TestableStartup < OperationsDbContext > , OperationsDbContext > >
12+ public sealed class AtomicTransactionConsistencyTests
13+ : IClassFixture < IntegrationTestContext < TestableStartup < OperationsDbContext > , OperationsDbContext > > , IAsyncLifetime
1314{
1415 private readonly IntegrationTestContext < TestableStartup < OperationsDbContext > , OperationsDbContext > _testContext ;
1516 private readonly OperationsFakers _fakers = new ( ) ;
@@ -27,7 +28,7 @@ public AtomicTransactionConsistencyTests(IntegrationTestContext<TestableStartup<
2728 services . AddResourceRepository < LyricRepository > ( ) ;
2829
2930 string postgresPassword = Environment . GetEnvironmentVariable ( "PGPASSWORD" ) ?? "postgres" ;
30- string dbConnectionString = $ "Host=localhost;Port=5432;Database=JsonApiTest-{ Guid . NewGuid ( ) : N} ;User ID=postgres;Password={ postgresPassword } ";
31+ string dbConnectionString = $ "Host=localhost;Port=5432;Database=JsonApiTest-Extra- { Guid . NewGuid ( ) : N} ;User ID=postgres;Password={ postgresPassword } ";
3132
3233 services . AddDbContext < ExtraDbContext > ( options => options . UseNpgsql ( dbConnectionString ) ) ;
3334 } ) ;
@@ -158,4 +159,22 @@ public async Task Cannot_use_distributed_transaction()
158159 error . Source . ShouldNotBeNull ( ) ;
159160 error . Source . Pointer . Should ( ) . Be ( "/atomic:operations[0]" ) ;
160161 }
162+
163+ public Task InitializeAsync ( )
164+ {
165+ return Task . CompletedTask ;
166+ }
167+
168+ Task IAsyncLifetime . DisposeAsync ( )
169+ {
170+ return DeleteExtraDatabaseAsync ( ) ;
171+ }
172+
173+ private async Task DeleteExtraDatabaseAsync ( )
174+ {
175+ await using AsyncServiceScope scope = _testContext . Factory . Services . CreateAsyncScope ( ) ;
176+ var dbContext = scope . ServiceProvider . GetRequiredService < ExtraDbContext > ( ) ;
177+
178+ await dbContext . Database . EnsureDeletedAsync ( ) ;
179+ }
161180}
0 commit comments