WIP
This commit is contained in:
30
tests/Solar.Api.Tests/DefaultWebApplicationFactory.cs
Normal file
30
tests/Solar.Api.Tests/DefaultWebApplicationFactory.cs
Normal 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();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user