12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- 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<TStartupmodule> : AbpIntegratedTest<TStartupmodule> where TStartupmodule : IAbpModule
- {
- protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
- {
- options.UseAutofac();
- }
- protected virtual async Task WithUnitOfWorkAsync(AbpUnitOfWorkOptions options, Func<Task> action)
- {
- using (var scope = ServiceProvider.CreateScope())
- {
- var uomManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
- using (var uow = uomManager.Begin(options))
- {
- await action();
- await uow.CompleteAsync();
- }
- }
- }
- protected virtual async Task<TResult> WithUnitOfWorkAsync<TResult>(AbpUnitOfWorkOptions options, Func<Task<TResult>> func)
- {
- using (var scope = ServiceProvider.CreateScope())
- {
- var uomManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
- using (var uow = uomManager.Begin(options))
- {
- var result = await func();
- await uow.CompleteAsync();
- return result;
- }
- }
- }
- protected virtual Task WithUnitOfWorkAsync(Func<Task> func)
- {
- return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func);
- }
- protected virtual Task<TResult> WithUnitOfWorkAsync<TResult>(Func<Task<TResult>> func)
- {
- return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func);
- }
- }
- }
|