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.

163 lines
6.4 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. using Shentun.Sms.Client;
  2. using Shentun.WebPeis.Enums;
  3. using Shentun.WebPeis.Models;
  4. using Shentun.WebPeis.Persons;
  5. using Shentun.WebPeis.Wechats;
  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.Identity;
  13. using Volo.Abp.Modularity;
  14. using Volo.Abp.Uow;
  15. using Volo.Abp.Users;
  16. using Xunit;
  17. using Xunit.Abstractions;
  18. namespace Shentun.WebPeis
  19. {
  20. public abstract class PersonAppServiceTest<TStartupModule> : WebPeisApplicationTestBase<TStartupModule>
  21. where TStartupModule : IAbpModule
  22. {
  23. private readonly IRepository<Person> _repository;
  24. private readonly PersonAppService _appService;
  25. private readonly ITestOutputHelper _output;
  26. private readonly IUnitOfWorkManager _unitOfWorkManager;
  27. private readonly IRepository<IdentityUser, Guid> _identityUserRepository;
  28. private readonly IRepository<QuestionRegister> _questionRegisterRepository;
  29. private readonly IRepository<PersonKinship> _personKinshipRepository;
  30. public PersonAppServiceTest(ITestOutputHelper output)
  31. {
  32. //ITestOutputHelper testOutputHelper
  33. //_output = testOutputHelper;
  34. _unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>();
  35. _repository = GetRequiredService<IRepository<Person>>();
  36. //_appService = GetRequiredService<PersonAppService>();
  37. _identityUserRepository = GetRequiredService<IRepository<IdentityUser, Guid>>();
  38. _questionRegisterRepository = GetRequiredService<IRepository<QuestionRegister>>();
  39. _personKinshipRepository = GetRequiredService<IRepository<PersonKinship>>();
  40. _output = output;
  41. }
  42. [Fact]
  43. public async Task GetWechatUserTokenAsync()
  44. {
  45. using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true))
  46. {
  47. var entity = new WechatUserJsCodeInputDto()
  48. {
  49. JsCode = "0c1yTa0w3mErQ23eot3w3ocsxw4yTa0P"
  50. };
  51. var newEntity = await _appService.WeChatUserLoginAsync(entity);
  52. await unitOfWork.CompleteAsync();
  53. }
  54. }
  55. [Fact]
  56. public async Task CreateAsync()
  57. {
  58. using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true))
  59. {
  60. var entity = new CreatePersonDto()
  61. {
  62. JsCode = "0f1XjtHa1yzivH0rmsHa1FuJf32XjtHL",
  63. PersonName = "张三",
  64. MobileTelephone = "18911254911",
  65. MedicalCenterId = new Guid("150da355-dfbf-466b-9697-355836a862c4"),
  66. IdNo = "43062419790909931X",
  67. SexId = SexFlag.Male,
  68. WechatOpenId = "obZGv5RhSNxxpkDwT0Xaf9Fzn8NM",
  69. MaritalStatusId = MaritalStatusFlag.Married,
  70. };
  71. var newEntity = await _appService.CreateAsync(entity);
  72. await unitOfWork.CompleteAsync();
  73. }
  74. }
  75. [Fact]
  76. public async Task GetPersonKinshipList()
  77. {
  78. using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true))
  79. {
  80. var entityList = await _appService.GetPersonKinshipList();
  81. foreach (var entity in entityList)
  82. {
  83. _output.WriteLine(entity.PersonName);
  84. }
  85. await unitOfWork.CompleteAsync();
  86. }
  87. }
  88. [Fact]
  89. public async Task GetPersonKinshipListByEfcore()
  90. {
  91. using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true))
  92. {
  93. var personId = new Guid("3a12d72c-19d9-e8b2-71f6-cf283103e191");
  94. var personKinshipIds = (await _personKinshipRepository.GetQueryableAsync())
  95. .Where(o => o.ParentPersonId == personId)
  96. .Select(o => o.PersonId).ToList();
  97. personKinshipIds.Add(personId);
  98. var personList = (from user in await _identityUserRepository.GetQueryableAsync()
  99. join person in await _repository.GetQueryableAsync()
  100. on user.Id equals person.PersonId
  101. join questionRegister in await _questionRegisterRepository.GetQueryableAsync()
  102. on person.PersonId equals questionRegister.PersonId into emptyQuestionRegister
  103. from haveQuestionRegister in emptyQuestionRegister.DefaultIfEmpty()
  104. where personKinshipIds.Contains(user.Id)
  105. orderby user.CreationTime
  106. select new PersonDto
  107. {
  108. PersonId = user.Id,
  109. PersonName = user.Name,
  110. SexId = person.SexId,
  111. MaritalStatusId = person.MaritalStatusId,
  112. IdNo = person.IdNo,
  113. MobileTelephone = user.PhoneNumber,
  114. IsHaveQuestionRegister = haveQuestionRegister == null? 'N' : 'Y'
  115. }).Distinct().ToList();
  116. foreach (var person in personList)
  117. {
  118. _output.WriteLine(person.PersonName + "," + person.IsHaveQuestionRegister );
  119. var cnt = (await _questionRegisterRepository.GetQueryableAsync()).Where(o=>o.PersonId == personId).Count();
  120. _output.WriteLine(cnt.ToString());
  121. }
  122. await unitOfWork.CompleteAsync();
  123. }
  124. }
  125. [Fact]
  126. public async Task SendVerifySms()
  127. {
  128. using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true))
  129. {
  130. var createSmsTaskDto = new CreateSmsTaskDto()
  131. {
  132. MobileTelephone = "18911254911",
  133. CountryCode = "86",
  134. PersonId = "0001",
  135. PersonName = "张三"
  136. };
  137. await _appService.SendVerifySms(createSmsTaskDto);
  138. }
  139. }
  140. }
  141. }