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.

96 lines
3.4 KiB

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