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

61 行
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 Acme.BookStore;
  9. /* All test classes are derived from this class, directly or indirectly.
  10. */
  11. public abstract class BookStoreTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule>
  12. where TStartupModule : IAbpModule
  13. {
  14. protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
  15. {
  16. options.UseAutofac();
  17. }
  18. protected virtual Task WithUnitOfWorkAsync(Func<Task> func)
  19. {
  20. return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func);
  21. }
  22. protected virtual async Task WithUnitOfWorkAsync(AbpUnitOfWorkOptions options, Func<Task> action)
  23. {
  24. using (var scope = ServiceProvider.CreateScope())
  25. {
  26. var uowManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
  27. using (var uow = uowManager.Begin(options))
  28. {
  29. await action();
  30. await uow.CompleteAsync();
  31. }
  32. }
  33. }
  34. protected virtual Task<TResult> WithUnitOfWorkAsync<TResult>(Func<Task<TResult>> func)
  35. {
  36. return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func);
  37. }
  38. protected virtual async Task<TResult> WithUnitOfWorkAsync<TResult>(AbpUnitOfWorkOptions options, Func<Task<TResult>> func)
  39. {
  40. using (var scope = ServiceProvider.CreateScope())
  41. {
  42. var uowManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
  43. using (var uow = uowManager.Begin(options))
  44. {
  45. var result = await func();
  46. await uow.CompleteAsync();
  47. return result;
  48. }
  49. }
  50. }
  51. }