9
9
10
10
namespace JsonApiDotNetCoreTests . IntegrationTests . AtomicOperations . Transactions ;
11
11
12
- public sealed class AtomicTransactionConsistencyTests : IClassFixture < IntegrationTestContext < TestableStartup < OperationsDbContext > , OperationsDbContext > >
12
+ public sealed class AtomicTransactionConsistencyTests
13
+ : IClassFixture < IntegrationTestContext < TestableStartup < OperationsDbContext > , OperationsDbContext > > , IAsyncLifetime
13
14
{
14
15
private readonly IntegrationTestContext < TestableStartup < OperationsDbContext > , OperationsDbContext > _testContext ;
15
16
private readonly OperationsFakers _fakers = new ( ) ;
@@ -27,7 +28,7 @@ public AtomicTransactionConsistencyTests(IntegrationTestContext<TestableStartup<
27
28
services . AddResourceRepository < LyricRepository > ( ) ;
28
29
29
30
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 } ";
31
32
32
33
services . AddDbContext < ExtraDbContext > ( options => options . UseNpgsql ( dbConnectionString ) ) ;
33
34
} ) ;
@@ -158,4 +159,22 @@ public async Task Cannot_use_distributed_transaction()
158
159
error . Source . ShouldNotBeNull ( ) ;
159
160
error . Source . Pointer . Should ( ) . Be ( "/atomic:operations[0]" ) ;
160
161
}
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
+ }
161
180
}
0 commit comments