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.

177 lines
6.8 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 UpdateAsync()
  77. {
  78. using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true))
  79. {
  80. var entity = await _repository.GetAsync(o => o.PersonId == new Guid("3a12d72c-19d9-e8b2-71f6-cf283103e191"));
  81. //var newEntity = await _appService.UpdateAsync(entity);
  82. await unitOfWork.CompleteAsync();
  83. }
  84. }
  85. [Fact]
  86. public async Task GetPersonKinshipList()
  87. {
  88. using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true))
  89. {
  90. var entityList = await _appService.GetPersonKinshipList();
  91. foreach (var entity in entityList)
  92. {
  93. _output.WriteLine(entity.PersonName);
  94. }
  95. await unitOfWork.CompleteAsync();
  96. }
  97. }
  98. [Fact]
  99. public async Task GetPersonKinshipListByEfcore()
  100. {
  101. using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true))
  102. {
  103. var personId = new Guid("3a12d72c-19d9-e8b2-71f6-cf283103e191");
  104. var personKinshipIds = (await _personKinshipRepository.GetQueryableAsync())
  105. .Where(o => o.ParentPersonId == personId)
  106. .Select(o => o.PersonId).ToList();
  107. personKinshipIds.Add(personId);
  108. var personList = (from user in await _identityUserRepository.GetQueryableAsync()
  109. join person in await _repository.GetQueryableAsync()
  110. on user.Id equals person.PersonId
  111. join questionRegister in await _questionRegisterRepository.GetQueryableAsync()
  112. on person.PersonId equals questionRegister.PersonId into emptyQuestionRegister
  113. from haveQuestionRegister in emptyQuestionRegister.DefaultIfEmpty()
  114. where personKinshipIds.Contains(user.Id)
  115. orderby user.CreationTime
  116. select new PersonDto
  117. {
  118. PersonId = user.Id,
  119. PersonName = user.Name,
  120. SexId = person.SexId,
  121. MaritalStatusId = person.MaritalStatusId,
  122. IdNo = person.IdNo,
  123. MobileTelephone = user.PhoneNumber,
  124. IsHaveQuestionRegister = haveQuestionRegister == null? 'N' : 'Y'
  125. }).Distinct().ToList();
  126. foreach (var person in personList)
  127. {
  128. _output.WriteLine(person.PersonName + "," + person.IsHaveQuestionRegister );
  129. var cnt = (await _questionRegisterRepository.GetQueryableAsync()).Where(o=>o.PersonId == personId).Count();
  130. _output.WriteLine(cnt.ToString());
  131. }
  132. await unitOfWork.CompleteAsync();
  133. }
  134. }
  135. [Fact]
  136. public async Task SendVerifySms()
  137. {
  138. using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true))
  139. {
  140. var createSmsTaskDto = new CreateSmsTaskDto()
  141. {
  142. MobileTelephone = "18911254911",
  143. CountryCode = "86",
  144. PersonId = "0001",
  145. PersonName = "张三"
  146. };
  147. await _appService.SendVerifySms(createSmsTaskDto);
  148. }
  149. }
  150. }
  151. }