"Test-infrastructure-fixes"
This commit is contained in:
parent
6e5f5ae279
commit
c5c56ec3d8
@ -27,19 +27,25 @@ public class TestWebApplicationFactory : WebApplicationFactory<Program>
|
||||
builder.ConfigureServices(services =>
|
||||
{
|
||||
// Remove the existing DbContext registration
|
||||
var descriptor = services.SingleOrDefault(d => d.ServiceType == typeof(DbContextOptions<LittleShopContext>));
|
||||
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<LittleShopContext>));
|
||||
if (optionsDescriptor != null)
|
||||
services.Remove(optionsDescriptor);
|
||||
|
||||
// Add InMemory database for testing with unique name per test run
|
||||
var databaseName = $"InMemoryDbForTesting_{Guid.NewGuid()}";
|
||||
services.AddDbContext<LittleShopContext>(options =>
|
||||
options.UseInMemoryDatabase("InMemoryDbForTesting")
|
||||
options.UseInMemoryDatabase(databaseName)
|
||||
.ConfigureWarnings(warnings => warnings.Default(WarningBehavior.Ignore)));
|
||||
|
||||
// Add test configuration
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddInMemoryCollection(new Dictionary<string, string>
|
||||
{
|
||||
{"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"},
|
||||
|
||||
@ -18,7 +18,7 @@ public class AdminPanelTests : IClassFixture<TestWebApplicationFactory>, 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()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user