@@ -13,6 +13,11 @@ public class CustomWebApplicationFactory<TStartup> : WebApplicationFactory<TStar
1313 where TStartup : class
1414{
1515 private readonly string _connectionString ;
16+ // Create static names for in-memory databases to ensure they persist across requests within the same test
17+ private static readonly string ProductsDbName = $ "InMemoryProductsTestDb_{ Guid . NewGuid ( ) } ";
18+ private static readonly string CustomersDbName = $ "InMemoryCustomersTestDb_{ Guid . NewGuid ( ) } ";
19+ private static readonly string OrdersDbName = $ "InMemoryOrdersTestDb_{ Guid . NewGuid ( ) } ";
20+ private static readonly string BusinessEventsDbName = $ "InMemoryBusinessEventsTestDb_{ Guid . NewGuid ( ) } ";
1621
1722 public CustomWebApplicationFactory ( string connectionString )
1823 {
@@ -33,7 +38,7 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
3338 // Add in-memory database for ProductDbContext
3439 services . AddDbContext < ECommerce . Modules . Products . Persistence . ProductDbContext > ( options =>
3540 {
36- options . UseInMemoryDatabase ( "InMemoryProductsTestDb" ) ;
41+ options . UseInMemoryDatabase ( ProductsDbName ) ;
3742 } ) ;
3843
3944 // Remove and add in-memory for CustomerDbContext
@@ -45,7 +50,7 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
4550 }
4651 services . AddDbContext < ECommerce . Modules . Customers . Persistence . CustomerDbContext > ( options =>
4752 {
48- options . UseInMemoryDatabase ( "InMemoryCustomersTestDb" ) ;
53+ options . UseInMemoryDatabase ( CustomersDbName ) ;
4954 } ) ;
5055
5156 // Remove and add in-memory for OrderDbContext
@@ -57,7 +62,7 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
5762 }
5863 services . AddDbContext < ECommerce . Modules . Orders . Persistence . OrderDbContext > ( options =>
5964 {
60- options . UseInMemoryDatabase ( "InMemoryOrdersTestDb" ) ;
65+ options . UseInMemoryDatabase ( OrdersDbName ) ;
6166 } ) ;
6267
6368 // Remove and add in-memory for BusinessEventDbContext
@@ -69,7 +74,7 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
6974 }
7075 services . AddDbContext < ECommerce . BusinessEvents . Persistence . BusinessEventDbContext > ( options =>
7176 {
72- options . UseInMemoryDatabase ( "InMemoryBusinessEventsTestDb" ) ;
77+ options . UseInMemoryDatabase ( BusinessEventsDbName ) ;
7378 } ) ;
7479 } ) ;
7580 builder . ConfigureAppConfiguration ( ( context , configBuilder ) =>
0 commit comments