Hospital Management internal project. Build with Abp.io architecture.
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.

60 lines
1.8 KiB

3 weeks ago
  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 HospitalManagementSystem;
  9. /* All test classes are derived from this class, directly or indirectly.
  10. */
  11. public abstract class HospitalManagementSystemTestBase<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. }