using Microsoft.Extensions.DependencyInjection; using System; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.Modularity; using Volo.Abp.Testing; using Volo.Abp.Uow; namespace OrBit.MESInterface.TestBase { public abstract class MESInterfaceTestBase : AbpIntegratedTest where TStartupmodule : IAbpModule { protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) { options.UseAutofac(); } protected virtual async Task WithUnitOfWorkAsync(AbpUnitOfWorkOptions options, Func action) { using (var scope = ServiceProvider.CreateScope()) { var uomManager = scope.ServiceProvider.GetRequiredService(); using (var uow = uomManager.Begin(options)) { await action(); await uow.CompleteAsync(); } } } protected virtual async Task WithUnitOfWorkAsync(AbpUnitOfWorkOptions options, Func> func) { using (var scope = ServiceProvider.CreateScope()) { var uomManager = scope.ServiceProvider.GetRequiredService(); using (var uow = uomManager.Begin(options)) { var result = await func(); await uow.CompleteAsync(); return result; } } } protected virtual Task WithUnitOfWorkAsync(Func func) { return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func); } protected virtual Task WithUnitOfWorkAsync(Func> func) { return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func); } } }