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.

97 lines
3.5 KiB

2 years ago
  1. using Shentun.Peis.CardRegisters;
  2. using Shentun.Peis.Enums;
  3. using Shentun.Peis.IncludeDetails;
  4. using Shentun.Peis.Models;
  5. using Shentun.Peis.Patients;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using TencentCloud.Soe.V20180724.Models;
  12. using Volo.Abp.Domain.Repositories;
  13. using Volo.Abp.Uow;
  14. using Xunit;
  15. using Xunit.Abstractions;
  16. namespace Shentun.Peis
  17. {
  18. public class PatientManagerTest : PeisDomainTestBase
  19. {
  20. private readonly IRepository<Patient, Guid> _repository;
  21. private readonly PatientManager _manager;
  22. private readonly ITestOutputHelper _output;
  23. private readonly IUnitOfWorkManager _unitOfWorkManager;
  24. public PatientManagerTest(ITestOutputHelper output)
  25. {
  26. _output = output;
  27. _repository = GetRequiredService<IRepository<Patient, Guid>>();
  28. _manager = GetRequiredService<PatientManager>();
  29. _unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>();
  30. }
  31. [Fact]
  32. public async Task CreateAsync()
  33. {
  34. using(var unitOfWork = _unitOfWorkManager.Begin())
  35. {
  36. var patient = new Patient()
  37. {
  38. MedicalCenterId = new Guid("68f2d834-2bf0-4978-ad54-d2133c12a333"),
  39. DisplayName = "Test",
  40. SexId = SexFlag.UnKnown,
  41. MaritalStatusId = MaritalStatusFlag.UnKnown,
  42. IdNo = "43062419790909931X"
  43. };
  44. var newPatient = await _manager.CreateAsync(patient);
  45. await _repository.InsertAsync(newPatient);
  46. await unitOfWork.CompleteAsync();
  47. }
  48. }
  49. /// <summary>
  50. /// 测试事务回滚
  51. /// </summary>
  52. /// <returns></returns>
  53. /// <exception cref="Exception"></exception>
  54. [Fact]
  55. public async Task CreateFaildAsync()
  56. {
  57. using (var unitOfWork = _unitOfWorkManager.Begin())
  58. {
  59. var patient = new Patient()
  60. {
  61. MedicalCenterId = new Guid("68f2d834-2bf0-4978-ad54-d2133c12a333"),
  62. DisplayName = "Test",
  63. SexId = SexFlag.UnKnown,
  64. MaritalStatusId = MaritalStatusFlag.UnKnown,
  65. IdNo = "43062419790909920X"
  66. };
  67. var newPatient = await _manager.CreateAsync(patient);
  68. throw new Exception("中断");
  69. await _repository.InsertAsync(newPatient);
  70. await unitOfWork.CompleteAsync();
  71. }
  72. }
  73. [Fact]
  74. public async Task UpdateAsync()
  75. {
  76. using (var unitOfWork = _unitOfWorkManager.Begin())
  77. {
  78. var sourcePatient = new Patient()
  79. {
  80. MedicalCenterId = new Guid("68f2d834-2bf0-4978-ad54-d2133c12a333"),
  81. DisplayName = "Test2",
  82. SexId = SexFlag.Female,
  83. MaritalStatusId = MaritalStatusFlag.Married,
  84. IdNo = "43062419790909920X"
  85. };
  86. var targetPatient = await _repository.GetAsync(new Guid("3a119be6-d9aa-2e13-a764-0b363c60169d"));
  87. await _manager.UpdateAsync(sourcePatient,targetPatient);
  88. await _repository.UpdateAsync(targetPatient);
  89. await unitOfWork.CompleteAsync();
  90. }
  91. }
  92. }
  93. }