using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.Modularity;
using Volo.Abp.Testing;
using Volo.Abp.Uow;
namespace CMS.Plugin.HIAWms.TestBase
{
///
/// MyProjectName TestBase
///
/// IAbpModule
public class HIAWmsTestBase : AbpIntegratedTest
where TStartupModule : IAbpModule
{
///
/// SetAbpApplicationCreationOptions
///
/// AbpApplicationCreationOptions
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
{
options.UseAutofac();
}
///
/// WithUnitOfWorkAsync
///
/// func
/// Task
protected virtual Task WithUnitOfWorkAsync(Func func)
{
return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func);
}
///
/// WithUnitOfWorkAsync
///
/// AbpUnitOfWorkOptions
/// action
/// Task
protected virtual async Task WithUnitOfWorkAsync(AbpUnitOfWorkOptions options, Func action)
{
using (var scope = ServiceProvider.CreateScope())
{
var uowManager = scope.ServiceProvider.GetRequiredService();
using (var uow = uowManager.Begin(options))
{
await action();
await uow.CompleteAsync();
}
}
}
///
/// WithUnitOfWorkAsync
///
/// t
/// TResult
/// TResult
protected virtual Task WithUnitOfWorkAsync(Func> func)
{
return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func);
}
///
/// WithUnitOfWorkAsync
///
/// T
/// AbpUnitOfWorkOptions
/// Func
/// TResult
protected virtual async Task WithUnitOfWorkAsync(AbpUnitOfWorkOptions options, Func> func)
{
using (var scope = ServiceProvider.CreateScope())
{
var uowManager = scope.ServiceProvider.GetRequiredService();
using (var uow = uowManager.Begin(options))
{
var result = await func();
await uow.CompleteAsync();
return result;
}
}
}
}
}