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
177 lines
6.8 KiB
using Shentun.Sms.Client;
|
|
using Shentun.WebPeis.Enums;
|
|
using Shentun.WebPeis.Models;
|
|
using Shentun.WebPeis.Persons;
|
|
using Shentun.WebPeis.Wechats;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Volo.Abp.Domain.Repositories;
|
|
using Volo.Abp.Identity;
|
|
using Volo.Abp.Modularity;
|
|
using Volo.Abp.Uow;
|
|
using Volo.Abp.Users;
|
|
using Xunit;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace Shentun.WebPeis
|
|
{
|
|
public abstract class PersonAppServiceTest<TStartupModule> : WebPeisApplicationTestBase<TStartupModule>
|
|
where TStartupModule : IAbpModule
|
|
{
|
|
private readonly IRepository<Person> _repository;
|
|
private readonly PersonAppService _appService;
|
|
private readonly ITestOutputHelper _output;
|
|
private readonly IUnitOfWorkManager _unitOfWorkManager;
|
|
private readonly IRepository<IdentityUser, Guid> _identityUserRepository;
|
|
private readonly IRepository<QuestionRegister> _questionRegisterRepository;
|
|
private readonly IRepository<PersonKinship> _personKinshipRepository;
|
|
public PersonAppServiceTest(ITestOutputHelper output)
|
|
{
|
|
//ITestOutputHelper testOutputHelper
|
|
//_output = testOutputHelper;
|
|
_unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>();
|
|
_repository = GetRequiredService<IRepository<Person>>();
|
|
//_appService = GetRequiredService<PersonAppService>();
|
|
|
|
_identityUserRepository = GetRequiredService<IRepository<IdentityUser, Guid>>();
|
|
_questionRegisterRepository = GetRequiredService<IRepository<QuestionRegister>>();
|
|
_personKinshipRepository = GetRequiredService<IRepository<PersonKinship>>();
|
|
|
|
_output = output;
|
|
}
|
|
[Fact]
|
|
public async Task GetWechatUserTokenAsync()
|
|
{
|
|
using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true))
|
|
{
|
|
|
|
var entity = new WechatUserJsCodeInputDto()
|
|
{
|
|
JsCode = "0c1yTa0w3mErQ23eot3w3ocsxw4yTa0P"
|
|
};
|
|
|
|
var newEntity = await _appService.WeChatUserLoginAsync(entity);
|
|
await unitOfWork.CompleteAsync();
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CreateAsync()
|
|
{
|
|
using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true))
|
|
{
|
|
|
|
var entity = new CreatePersonDto()
|
|
{
|
|
JsCode = "0f1XjtHa1yzivH0rmsHa1FuJf32XjtHL",
|
|
PersonName = "张三",
|
|
MobileTelephone = "18911254911",
|
|
MedicalCenterId = new Guid("150da355-dfbf-466b-9697-355836a862c4"),
|
|
IdNo = "43062419790909931X",
|
|
SexId = SexFlag.Male,
|
|
WechatOpenId = "obZGv5RhSNxxpkDwT0Xaf9Fzn8NM",
|
|
MaritalStatusId = MaritalStatusFlag.Married,
|
|
|
|
|
|
};
|
|
|
|
var newEntity = await _appService.CreateAsync(entity);
|
|
await unitOfWork.CompleteAsync();
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public async Task UpdateAsync()
|
|
{
|
|
using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true))
|
|
{
|
|
|
|
var entity = await _repository.GetAsync(o => o.PersonId == new Guid("3a12d72c-19d9-e8b2-71f6-cf283103e191"));
|
|
|
|
|
|
//var newEntity = await _appService.UpdateAsync(entity);
|
|
await unitOfWork.CompleteAsync();
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetPersonKinshipList()
|
|
{
|
|
using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true))
|
|
{
|
|
|
|
var entityList = await _appService.GetPersonKinshipList();
|
|
foreach (var entity in entityList)
|
|
{
|
|
_output.WriteLine(entity.PersonName);
|
|
}
|
|
await unitOfWork.CompleteAsync();
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetPersonKinshipListByEfcore()
|
|
{
|
|
using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true))
|
|
{
|
|
var personId = new Guid("3a12d72c-19d9-e8b2-71f6-cf283103e191");
|
|
var personKinshipIds = (await _personKinshipRepository.GetQueryableAsync())
|
|
.Where(o => o.ParentPersonId == personId)
|
|
.Select(o => o.PersonId).ToList();
|
|
personKinshipIds.Add(personId);
|
|
|
|
var personList = (from user in await _identityUserRepository.GetQueryableAsync()
|
|
join person in await _repository.GetQueryableAsync()
|
|
on user.Id equals person.PersonId
|
|
join questionRegister in await _questionRegisterRepository.GetQueryableAsync()
|
|
on person.PersonId equals questionRegister.PersonId into emptyQuestionRegister
|
|
from haveQuestionRegister in emptyQuestionRegister.DefaultIfEmpty()
|
|
where personKinshipIds.Contains(user.Id)
|
|
orderby user.CreationTime
|
|
select new PersonDto
|
|
{
|
|
PersonId = user.Id,
|
|
PersonName = user.Name,
|
|
SexId = person.SexId,
|
|
|
|
MaritalStatusId = person.MaritalStatusId,
|
|
|
|
IdNo = person.IdNo,
|
|
MobileTelephone = user.PhoneNumber,
|
|
IsHaveQuestionRegister = haveQuestionRegister == null? 'N' : 'Y'
|
|
|
|
|
|
}).Distinct().ToList();
|
|
|
|
foreach (var person in personList)
|
|
{
|
|
_output.WriteLine(person.PersonName + "," + person.IsHaveQuestionRegister );
|
|
var cnt = (await _questionRegisterRepository.GetQueryableAsync()).Where(o=>o.PersonId == personId).Count();
|
|
_output.WriteLine(cnt.ToString());
|
|
}
|
|
|
|
await unitOfWork.CompleteAsync();
|
|
}
|
|
|
|
}
|
|
[Fact]
|
|
public async Task SendVerifySms()
|
|
{
|
|
using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true))
|
|
{
|
|
var createSmsTaskDto = new CreateSmsTaskDto()
|
|
{
|
|
MobileTelephone = "18911254911",
|
|
CountryCode = "86",
|
|
PersonId = "0001",
|
|
PersonName = "张三"
|
|
};
|
|
await _appService.SendVerifySms(createSmsTaskDto);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|