diff --git a/LittleShop.Tests/Infrastructure/TestWebApplicationFactory.cs b/LittleShop.Tests/Infrastructure/TestWebApplicationFactory.cs index c629670..5d6ff97 100644 --- a/LittleShop.Tests/Infrastructure/TestWebApplicationFactory.cs +++ b/LittleShop.Tests/Infrastructure/TestWebApplicationFactory.cs @@ -27,19 +27,25 @@ public class TestWebApplicationFactory : WebApplicationFactory builder.ConfigureServices(services => { // Remove the existing DbContext registration - var descriptor = services.SingleOrDefault(d => d.ServiceType == typeof(DbContextOptions)); - if (descriptor != null) - services.Remove(descriptor); + var contextDescriptor = services.SingleOrDefault(d => d.ServiceType == typeof(LittleShopContext)); + if (contextDescriptor != null) + services.Remove(contextDescriptor); - // Add InMemory database for testing + var optionsDescriptor = services.SingleOrDefault(d => d.ServiceType == typeof(DbContextOptions)); + if (optionsDescriptor != null) + services.Remove(optionsDescriptor); + + // Add InMemory database for testing with unique name per test run + var databaseName = $"InMemoryDbForTesting_{Guid.NewGuid()}"; services.AddDbContext(options => - options.UseInMemoryDatabase("InMemoryDbForTesting") + options.UseInMemoryDatabase(databaseName) .ConfigureWarnings(warnings => warnings.Default(WarningBehavior.Ignore))); // Add test configuration var configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { + {"ConnectionStrings:DefaultConnection", $"Data Source={databaseName}.db"}, {"Jwt:Key", "test-key-that-is-at-least-32-characters-long-for-security"}, {"Jwt:Issuer", "LittleShop"}, {"Jwt:Audience", "LittleShop"}, diff --git a/LittleShop.Tests/UI/AdminPanelTests.cs b/LittleShop.Tests/UI/AdminPanelTests.cs index cc4bf2f..271ad69 100644 --- a/LittleShop.Tests/UI/AdminPanelTests.cs +++ b/LittleShop.Tests/UI/AdminPanelTests.cs @@ -18,7 +18,7 @@ public class AdminPanelTests : IClassFixture, IAsyncL public AdminPanelTests(TestWebApplicationFactory factory) { _factory = factory; - _baseUrl = "https://localhost:5001"; // Adjust based on your test configuration + _baseUrl = _factory.Server.BaseAddress.ToString().TrimEnd('/'); // Use the test server's URL } public async Task InitializeAsync()