如何在ABP中使用XUnit集合夹具?

我们有一个使用ASP.NET Boilerplate 4.10.1的.NET Core 2.2项目。

这个项目有一个巨大的数据库上下文,对于我们正在运行的每个集成测试而言,加载它花费的时间都太长了,因此我们想看看如何在测试之间使用共享上下文。

不幸的是,我们无法弄清楚如何将XUnit collection fixtures与ABP结合使用,并且找不到有关此事的文档。

我们的一些代码(如果有帮助的话):

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;
        }
    }

集成测试:

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();
            });
        }
aijelun917 回答:如何在ABP中使用XUnit集合夹具?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2906166.html

大家都在问