autobus-api_old/AutobusApi.IntegrationTests/Tests/TestsBase.cs
2023-11-15 19:00:34 +02:00

29 lines
1.0 KiB
C#

using AutobusApi.Infrastructure.Identity;
using AutoubsApi.Infrastructure.Data;
using Microsoft.AspNetCore.Mvc.Testing;
namespace AutobusApi.IntegrationTests.Tests;
public class TestsBase : IClassFixture<CustomWebApplicationFactory<Program>>
{
protected readonly HttpClient _httpClient;
private readonly CustomWebApplicationFactory<Program> _factory;
public TestsBase(CustomWebApplicationFactory<Program> factory)
{
_factory = factory;
_httpClient = factory.CreateClient(new WebApplicationFactoryClientOptions
{
AllowAutoRedirect = false
});
var scope = _factory.Services.CreateScope();
var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
var identityDbContext = scope.ServiceProvider.GetRequiredService<ApplicationIdentityDbContext>();
dbContext.Database.EnsureDeleted();
identityDbContext.Database.EnsureDeleted();
AutobusApi.IntegrationTests.DbInitializer.Initialize(dbContext, identityDbContext);
}
}