Fix Multiple DbContext Registration (#703)

Hi, i noticed that in the WebTestFixture used for FunctionalTests the DbContexts were registered without removing the existing ones in Program.cs
which leads to duplication
This commit is contained in:
Said Haouaouchi
2023-02-28 21:16:39 +01:00
committed by GitHub
parent 0542c52d79
commit 4304545f19

View File

@@ -23,6 +23,16 @@ public class TestApplication : WebApplicationFactory<IBasketViewModelService>
// Add mock/test services to the builder here
builder.ConfigureServices(services =>
{
var descriptors = services.Where(d =>
d.ServiceType == typeof(DbContextOptions<CatalogContext>) ||
d.ServiceType == typeof(DbContextOptions<AppIdentityDbContext>))
.ToList();
foreach (var descriptor in descriptors)
{
services.Remove(descriptor);
}
services.AddScoped(sp =>
{
// Replace SQLite with in-memory database for tests