We have a .NET Core 2.2 project using ASP.NET Boilerplate 4.10.1.
This project has a huge db context that takes way too long to load for each integration test we're running, so we'd like to see how it'd go with a shared context between tests.
Unfortunately, we're unable to figure out how to combine XUnit collection fixtures with ABP, and found no documentation on the matter.
Some of our code, if it helps:
public abstract class EcfTestBase : AbpIntegratedTestBase<EcfTestBaseModule>
{
protected EcfTestBase()
{
AbpSession.TenantId = null;
UsingDbContext(context =>
{
NormalizeDbContext(context);
// Seed initial data for host
SeedHelper.SeedHostDb(context);
});
// Seed initial data for default tenant
AbpSession.TenantId = 1;
UsingDbContext(context =>
{
NormalizeDbContext(context);
});
LoginAsDefaultTenantAdmin();
void NormalizeDbContext(EcfDbContext context)
{
context.EntityChangeEventHelper = NullEntityChangeEventHelper.Instance;
context.EventBus = NullEventBus.Instance;
context.SuppressAutoSetTenantId = true;
}
}
Integration test:
public class Reg0000Controller_Tests : EcfTestBase
{
private readonly Reg0000AppService _Reg0000AppService;
public Reg0000Controller_Tests()
{
_Reg0000AppService = Resolve<Reg0000AppService>();
}
[Fact]
public async Task Reg0000_Create()
{
using (var controller = new Reg0000Controller(_Reg0000AppService))
{
var result = await controller.Create(new Reg0000Dto
{
CenarioId = 1,
Nome = "Empresa Teste"
});
result.Nome.ShouldBe("Empresa Teste");
await UsingDbContextAsync(async context =>
{
var reg0000 = await context.Reg0000.FirstOrDefaultAsync(u => u.Nome == "Empresa Teste");
reg0000.ShouldNotBeNull();
reg0000.CreatorUserId.ShouldNotBeNull();
reg0000.CreationTime.ShouldNotBeNull();
reg0000.LastModifierUserId.ShouldBeNull();
});
}