mirror of https://github.com/abpframework/abp
				
				
				
			
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							102 lines
						
					
					
						
							3.2 KiB
						
					
					
				
			
		
		
	
	
							102 lines
						
					
					
						
							3.2 KiB
						
					
					
				| using System;
 | |
| using System.Threading.Tasks;
 | |
| using Microsoft.Extensions.DependencyInjection;
 | |
| using Volo.Abp;
 | |
| using Volo.Abp.Modularity;
 | |
| using Volo.Abp.Uow;
 | |
| using Volo.Abp.Testing;
 | |
| 
 | |
| namespace DashboardDemo
 | |
| {
 | |
|     /* All test classes are derived from this class, directly or indirectly.
 | |
|      */
 | |
|     public abstract class DashboardDemoTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule> 
 | |
|         where TStartupModule : IAbpModule
 | |
|     {
 | |
|         protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
 | |
|         {
 | |
|             options.UseAutofac();
 | |
|         }
 | |
| 
 | |
|         protected virtual void WithUnitOfWork(Action action)
 | |
|         {
 | |
|             WithUnitOfWork(new AbpUnitOfWorkOptions(), action);
 | |
|         }
 | |
| 
 | |
|         protected virtual void WithUnitOfWork(AbpUnitOfWorkOptions options, Action action)
 | |
|         {
 | |
|             using (var scope = ServiceProvider.CreateScope())
 | |
|             {
 | |
|                 var uowManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
 | |
| 
 | |
|                 using (var uow = uowManager.Begin(options))
 | |
|                 {
 | |
|                     action();
 | |
| 
 | |
|                     uow.Complete();
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         protected virtual Task WithUnitOfWorkAsync(Func<Task> func)
 | |
|         {
 | |
|             return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func);
 | |
|         }
 | |
| 
 | |
|         protected virtual async Task WithUnitOfWorkAsync(AbpUnitOfWorkOptions options, Func<Task> action)
 | |
|         {
 | |
|             using (var scope = ServiceProvider.CreateScope())
 | |
|             {
 | |
|                 var uowManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
 | |
| 
 | |
|                 using (var uow = uowManager.Begin(options))
 | |
|                 {
 | |
|                     await action();
 | |
| 
 | |
|                     await uow.CompleteAsync();
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         protected virtual TResult WithUnitOfWork<TResult>(Func<TResult> func)
 | |
|         {
 | |
|             return WithUnitOfWork(new AbpUnitOfWorkOptions(), func);
 | |
|         }
 | |
| 
 | |
|         protected virtual TResult WithUnitOfWork<TResult>(AbpUnitOfWorkOptions options, Func<TResult> func)
 | |
|         {
 | |
|             using (var scope = ServiceProvider.CreateScope())
 | |
|             {
 | |
|                 var uowManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
 | |
| 
 | |
|                 using (var uow = uowManager.Begin(options))
 | |
|                 {
 | |
|                     var result = func();
 | |
|                     uow.Complete();
 | |
|                     return result;
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         protected virtual Task<TResult> WithUnitOfWorkAsync<TResult>(Func<Task<TResult>> func)
 | |
|         {
 | |
|             return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func);
 | |
|         }
 | |
| 
 | |
|         protected virtual async Task<TResult> WithUnitOfWorkAsync<TResult>(AbpUnitOfWorkOptions options, Func<Task<TResult>> func)
 | |
|         {
 | |
|             using (var scope = ServiceProvider.CreateScope())
 | |
|             {
 | |
|                 var uowManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
 | |
| 
 | |
|                 using (var uow = uowManager.Begin(options))
 | |
|                 {
 | |
|                     var result = await func();
 | |
|                     await uow.CompleteAsync();
 | |
|                     return result;
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| }
 |