临河任务调度
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

60 行
1.8KB

  1. using System;
  2. using System.Threading.Tasks;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using Volo.Abp;
  5. using Volo.Abp.Modularity;
  6. using Volo.Abp.Uow;
  7. using Volo.Abp.Testing;
  8. namespace Himp.TaskScheduling;
  9. /* All test classes are derived from this class, directly or indirectly. */
  10. public abstract class TaskSchedulingTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule>
  11. where TStartupModule : IAbpModule
  12. {
  13. protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
  14. {
  15. options.UseAutofac();
  16. }
  17. protected virtual Task WithUnitOfWorkAsync(Func<Task> func)
  18. {
  19. return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func);
  20. }
  21. protected virtual async Task WithUnitOfWorkAsync(AbpUnitOfWorkOptions options, Func<Task> action)
  22. {
  23. using (var scope = ServiceProvider.CreateScope())
  24. {
  25. var uowManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
  26. using (var uow = uowManager.Begin(options))
  27. {
  28. await action();
  29. await uow.CompleteAsync();
  30. }
  31. }
  32. }
  33. protected virtual Task<TResult> WithUnitOfWorkAsync<TResult>(Func<Task<TResult>> func)
  34. {
  35. return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func);
  36. }
  37. protected virtual async Task<TResult> WithUnitOfWorkAsync<TResult>(AbpUnitOfWorkOptions options, Func<Task<TResult>> func)
  38. {
  39. using (var scope = ServiceProvider.CreateScope())
  40. {
  41. var uowManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
  42. using (var uow = uowManager.Begin(options))
  43. {
  44. var result = await func();
  45. await uow.CompleteAsync();
  46. return result;
  47. }
  48. }
  49. }
  50. }