Skip to content

Commit f5cd684

Browse files
fixing integration tests
1 parent 9bfbe11 commit f5cd684

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

ECommerceApp.IntegrationTests/CustomWebApplicationFactory.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,42 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
3535
{
3636
options.UseInMemoryDatabase("InMemoryProductsTestDb");
3737
});
38-
// Repeat for other module DbContexts as needed
38+
39+
// Remove and add in-memory for CustomerDbContext
40+
var customerDescriptor = services.SingleOrDefault(
41+
d => d.ServiceType == typeof(DbContextOptions<ECommerce.Modules.Customers.Persistence.CustomerDbContext>));
42+
if (customerDescriptor != null)
43+
{
44+
services.Remove(customerDescriptor);
45+
}
46+
services.AddDbContext<ECommerce.Modules.Customers.Persistence.CustomerDbContext>(options =>
47+
{
48+
options.UseInMemoryDatabase("InMemoryCustomersTestDb");
49+
});
50+
51+
// Remove and add in-memory for OrderDbContext
52+
var orderDescriptor = services.SingleOrDefault(
53+
d => d.ServiceType == typeof(DbContextOptions<ECommerce.Modules.Orders.Persistence.OrderDbContext>));
54+
if (orderDescriptor != null)
55+
{
56+
services.Remove(orderDescriptor);
57+
}
58+
services.AddDbContext<ECommerce.Modules.Orders.Persistence.OrderDbContext>(options =>
59+
{
60+
options.UseInMemoryDatabase("InMemoryOrdersTestDb");
61+
});
62+
63+
// Remove and add in-memory for BusinessEventDbContext
64+
var businessEventDescriptor = services.SingleOrDefault(
65+
d => d.ServiceType == typeof(DbContextOptions<ECommerce.BusinessEvents.Persistence.BusinessEventDbContext>));
66+
if (businessEventDescriptor != null)
67+
{
68+
services.Remove(businessEventDescriptor);
69+
}
70+
services.AddDbContext<ECommerce.BusinessEvents.Persistence.BusinessEventDbContext>(options =>
71+
{
72+
options.UseInMemoryDatabase("InMemoryBusinessEventsTestDb");
73+
});
3974
});
4075
builder.ConfigureAppConfiguration((context, configBuilder) =>
4176
{

0 commit comments

Comments
 (0)