@@ -13,54 +13,54 @@ namespace Cookbook.API.IntegrationTests.Fixtures;
1313
1414public class APiWebApplicationFactory : WebApplicationFactory < Program > , IAsyncLifetime
1515{
16- private readonly PostgreSqlContainer _dbContainer = new PostgreSqlBuilder ( )
17- . WithImage ( "postgres" )
18- . WithDatabase ( "cookbooktest" )
19- . WithUsername ( "postgres" )
20- . WithPassword ( "password" )
21- . WithCleanUp ( true )
22- . Build ( ) ;
16+ private readonly PostgreSqlContainer _dbContainer = new PostgreSqlBuilder ( )
17+ . WithImage ( "postgres" )
18+ . WithDatabase ( "cookbooktest" )
19+ . WithUsername ( "postgres" )
20+ . WithPassword ( "password" )
21+ . WithCleanUp ( true )
22+ . Build ( ) ;
2323
24- public IConfiguration Configuration { get ; private set ; } = null ! ;
24+ public IConfiguration Configuration { get ; private set ; } = null ! ;
2525
26- public async Task InitializeAsync ( )
27- {
28- await _dbContainer . StartAsync ( ) ;
26+ public async Task InitializeAsync ( )
27+ {
28+ await _dbContainer . StartAsync ( ) ;
2929
30- using var scope = Services . CreateScope ( ) ;
31- var context = scope . ServiceProvider . GetRequiredService < CookbookContext > ( ) ;
32- await context . Database . EnsureDeletedAsync ( ) ;
33- await context . Database . EnsureCreatedAsync ( ) ;
34- }
30+ using var scope = Services . CreateScope ( ) ;
31+ var context = scope . ServiceProvider . GetRequiredService < CookbookContext > ( ) ;
32+ await context . Database . EnsureDeletedAsync ( ) ;
33+ await context . Database . EnsureCreatedAsync ( ) ;
34+ }
3535
36- public new async Task DisposeAsync ( )
37- {
38- await _dbContainer . DisposeAsync ( ) ;
39- await base . DisposeAsync ( ) ;
40- }
36+ public new async Task DisposeAsync ( )
37+ {
38+ await _dbContainer . DisposeAsync ( ) ;
39+ await base . DisposeAsync ( ) ;
40+ }
4141
42- protected override void ConfigureWebHost ( IWebHostBuilder builder )
43- {
44- builder . ConfigureAppConfiguration ( config =>
45- {
46- Configuration = new ConfigurationBuilder ( )
47- . AddJsonFile ( "appsettings.Integration.json" )
48- . Build ( ) ;
49- config . AddConfiguration ( Configuration ) ;
50- } ) ;
42+ protected override void ConfigureWebHost ( IWebHostBuilder builder )
43+ {
44+ builder . ConfigureAppConfiguration ( config =>
45+ {
46+ Configuration = new ConfigurationBuilder ( )
47+ . AddJsonFile ( "appsettings.Integration.json" )
48+ . Build ( ) ;
49+ config . AddConfiguration ( Configuration ) ;
50+ } ) ;
5151
52- builder . ConfigureTestServices ( services =>
53- {
54- services . RemoveAll < DbContextOptions < CookbookContext > > ( ) ;
55- services . RemoveAll < CookbookContext > ( ) ;
52+ builder . ConfigureTestServices ( services =>
53+ {
54+ services . RemoveAll < DbContextOptions < CookbookContext > > ( ) ;
55+ services . RemoveAll < CookbookContext > ( ) ;
5656
57- services . AddDbContext < CookbookContext > ( options => options
58- . UseNpgsql ( _dbContainer . GetConnectionString ( ) + ";Include Error Detail=true" )
59- . UseAsyncSeeding ( async ( dbContext , _ , cancellationToken ) =>
60- {
61- var context = ( CookbookContext ) dbContext ;
62- await context . SeedAsync ( context , cancellationToken ) ;
63- } ) ) ;
64- } ) ;
65- }
57+ services . AddDbContext < CookbookContext > ( options => options
58+ . UseNpgsql ( _dbContainer . GetConnectionString ( ) + ";Include Error Detail=true" )
59+ . UseAsyncSeeding ( async ( dbContext , _ , cancellationToken ) =>
60+ {
61+ var context = ( CookbookContext ) dbContext ;
62+ await context . SeedAsync ( context , cancellationToken ) ;
63+ } ) ) ;
64+ } ) ;
65+ }
6666}
0 commit comments