"Test-infrastructure-fixes"
This commit is contained in:
parent
6e5f5ae279
commit
c5c56ec3d8
@ -27,19 +27,25 @@ public class TestWebApplicationFactory : WebApplicationFactory<Program>
|
|||||||
builder.ConfigureServices(services =>
|
builder.ConfigureServices(services =>
|
||||||
{
|
{
|
||||||
// Remove the existing DbContext registration
|
// Remove the existing DbContext registration
|
||||||
var descriptor = services.SingleOrDefault(d => d.ServiceType == typeof(DbContextOptions<LittleShopContext>));
|
var contextDescriptor = services.SingleOrDefault(d => d.ServiceType == typeof(LittleShopContext));
|
||||||
if (descriptor != null)
|
if (contextDescriptor != null)
|
||||||
services.Remove(descriptor);
|
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 =>
|
services.AddDbContext<LittleShopContext>(options =>
|
||||||
options.UseInMemoryDatabase("InMemoryDbForTesting")
|
options.UseInMemoryDatabase(databaseName)
|
||||||
.ConfigureWarnings(warnings => warnings.Default(WarningBehavior.Ignore)));
|
.ConfigureWarnings(warnings => warnings.Default(WarningBehavior.Ignore)));
|
||||||
|
|
||||||
// Add test configuration
|
// Add test configuration
|
||||||
var configuration = new ConfigurationBuilder()
|
var configuration = new ConfigurationBuilder()
|
||||||
.AddInMemoryCollection(new Dictionary<string, string>
|
.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:Key", "test-key-that-is-at-least-32-characters-long-for-security"},
|
||||||
{"Jwt:Issuer", "LittleShop"},
|
{"Jwt:Issuer", "LittleShop"},
|
||||||
{"Jwt:Audience", "LittleShop"},
|
{"Jwt:Audience", "LittleShop"},
|
||||||
|
|||||||
@ -18,7 +18,7 @@ public class AdminPanelTests : IClassFixture<TestWebApplicationFactory>, IAsyncL
|
|||||||
public AdminPanelTests(TestWebApplicationFactory factory)
|
public AdminPanelTests(TestWebApplicationFactory factory)
|
||||||
{
|
{
|
||||||
_factory = 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()
|
public async Task InitializeAsync()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user