This commit is contained in:
2024-12-30 21:25:35 +01:00
parent fba9aa9349
commit a46961cf80
19 changed files with 406 additions and 11 deletions

View File

@@ -0,0 +1,30 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace Solar.Api.Tests;
public class DefaultWebApplicationFactory : WebApplicationFactory<Program>
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.ConfigureTestServices(services =>
{
services.AddDbContext<DatabaseContext>(options =>
{
options.UseSqlite("Data Source=test.db");
});
});
builder.ConfigureServices(services =>
{
using var provider = services.BuildServiceProvider();
using var scope = provider.CreateScope();
using var databaseContext = scope.ServiceProvider.GetRequiredService<DatabaseContext>();
databaseContext.Database.EnsureCreated();
});
}
}