From 4304545f19bc404562e16a693e20bbcbdb878d43 Mon Sep 17 00:00:00 2001 From: Said Haouaouchi <54531034+linkprada@users.noreply.github.com> Date: Tue, 28 Feb 2023 21:16:39 +0100 Subject: [PATCH] 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 --- tests/FunctionalTests/Web/WebTestFixture.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/FunctionalTests/Web/WebTestFixture.cs b/tests/FunctionalTests/Web/WebTestFixture.cs index 55b2e74..d9bb491 100644 --- a/tests/FunctionalTests/Web/WebTestFixture.cs +++ b/tests/FunctionalTests/Web/WebTestFixture.cs @@ -23,6 +23,16 @@ public class TestApplication : WebApplicationFactory // Add mock/test services to the builder here builder.ConfigureServices(services => { + var descriptors = services.Where(d => + d.ServiceType == typeof(DbContextOptions) || + d.ServiceType == typeof(DbContextOptions)) + .ToList(); + + foreach (var descriptor in descriptors) + { + services.Remove(descriptor); + } + services.AddScoped(sp => { // Replace SQLite with in-memory database for tests