123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- using AutoFixture;
- using DocumentFormat.OpenXml.Wordprocessing;
- using Hotline.Api.Controllers;
- using Hotline.Application.Identity;
- using Hotline.Application.Snapshot;
- using Hotline.Application.Tests.Mock;
- using Hotline.File;
- using Hotline.Identity.Accounts;
- using Hotline.Identity.Roles;
- using Hotline.Orders;
- using Hotline.Share.Dtos.Article;
- using Hotline.Share.Dtos.Snapshot;
- using Hotline.Share.Enums;
- using Hotline.Share.Enums.Order;
- using Hotline.Share.Enums.Snapshot;
- using Hotline.Share.Tools;
- using Hotline.Snapshot;
- using Hotline.Snapshot.Interfaces;
- using Hotline.Users;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.DependencyInjection;
- using Shouldly;
- using System;
- using XF.Domain.Authentications;
- using XF.Domain.Repository;
- using XF.Utility.EnumExtensions;
- namespace Hotline.Application.Tests.Application;
- public class SnapshotApplicationTest : TestBase
- {
- private readonly ISnapshotApplication _snapshotApplication;
- private readonly IIdentityAppService _identityAppService;
- private readonly IRepository<RedPackRecord> _redPackRecordRepository;
- private readonly IIndustryApplication _industryApplication;
- private readonly IIndustryRepository _industryRepository;
- private readonly IFileRepository _fileRepository;
- private readonly OrderServiceMock _orderServiceMock;
- private readonly IOrderRepository _orderRepository;
- private readonly IOrderSnapshotRepository _orderSnapshotRepository;
- private readonly ISessionContext _sessionContext;
- public SnapshotApplicationTest(IAccountRepository accountRepository, IRepository<Role> roleRepository, UserController userController, IServiceScopeFactory scopeFactory, IRepository<User> userRepository, IHttpContextAccessor httpContextAccessor, ISnapshotApplication snapshotApplication, IIdentityAppService identityAppService, IRepository<RedPackRecord> redPackRecordRepository, IIndustryApplication industryApplication, IIndustryRepository industryRepository, IFileRepository fileRepository, OrderServiceMock orderServiceMock, IOrderRepository orderRepository, IOrderSnapshotRepository orderSnapshotRepository, IThirdIdentiyService thirdService, IThirdAccountRepository thirdAccount, ISessionContext sessionContext) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdService, thirdAccount)
- {
- _snapshotApplication = snapshotApplication;
- _identityAppService = identityAppService;
- _redPackRecordRepository = redPackRecordRepository;
- _industryApplication = industryApplication;
- _industryRepository = industryRepository;
- _fileRepository = fileRepository;
- _orderServiceMock = orderServiceMock;
- _orderRepository = orderRepository;
- _orderSnapshotRepository = orderSnapshotRepository;
- SetWeiXin();
- _sessionContext = sessionContext;
- }
- [Fact]
- public async Task GetHomePage_Test()
- {
- var result = await _snapshotApplication.GetHomePageAsync();
- result.Industrys.Any().ShouldBe(true, "首页数据为空");
- result.Industrys.First().DisplayOrder.ShouldBe(1, "排序异常");
- }
- /// <summary>
- /// 添加随手拍公告
- /// </summary>
- /// <returns></returns>
- [Fact]
- public async Task AddBulletin_Test()
- {
- var industry = await _industryRepository.Queryable()
- .OrderBy(m => m.DisplayOrder)
- .FirstAsync();
- if (industry == null)
- {
- return;
- }
- var inDto = new AddSnapshotBulletinInDto
- {
- Title = "单元测试" + DateTime.Now.ToLongDateTimeString(),
- Content = "测试内容" + DateTime.Now.ToLongDateTimeString(),
- SnapshotBulletinTypeId = industry.BulletinTypeGuideId!,
- SnapshotBulletinTypeName = industry.BulletinTypeGuideName!
- };
- var bulletinId = await _snapshotApplication.AddBulletinAsync(inDto);
- inDto = new AddSnapshotBulletinInDto
- {
- Title = "单元测试" + DateTime.Now.ToLongDateTimeString(),
- Content = "测试内容" + DateTime.Now.ToLongDateTimeString(),
- SnapshotBulletinTypeId = industry.BulletinTypePublicityId!,
- SnapshotBulletinTypeName = industry.BulletinTypePublicityName!
- };
- bulletinId = await _snapshotApplication.AddBulletinAsync(inDto);
- await _snapshotApplication.AuditBulletinAsync(new ExamineBulletinDto { Id = bulletinId, IsPass = true, Reason = "测试审核通过"});
- var items = await _snapshotApplication.GetBulletinsAsync(new BulletinInDto { IndustryId = industry.Id }, CancellationToken.None);
- items.Count.ShouldNotBe(0, "公告数量为0");
- }
- /// <summary>
- /// 获取公开工单集合
- /// </summary>
- /// <returns></returns>
- [Fact]
- public async Task GetPublishOrder_Test()
- {
- var industry = await _industryRepository.Queryable()
- .OrderBy(m => m.DisplayOrder)
- .FirstAsync();
- SetWeiXin();
- var order = _orderServiceMock.CreateSnapshotOrder()
- .办理到派单员(SetZuoXi)
- .办理到归档(SetPaiDanYuan)
- .GetCreateResult();
- SetWeiXin();
- var orderEntity = await _orderRepository.GetAsync(order.Id);
- var orderSnapshot = await _orderSnapshotRepository.GetAsync(order.Id);
- var inDto = new AddSnapshotOrderPublishInDto
- {
- ArrangeContent = orderEntity.Content,
- ArrangeOpinion = orderEntity.ActualOpinion,
- ArrangeTitle = orderEntity.Title,
- OrderId = orderEntity.Id,
- Address = orderEntity.FullAddress,
- HandleTime = DateTime.Now
- };
- await _snapshotApplication.AddOrderPublishAsync(inDto, CancellationToken.None);
- var items = await _snapshotApplication.GetOrderPublishAsync(new OrderPublishInDto { IndustryId = industry.Id }, CancellationToken.None);
- items.Count.ShouldNotBe(0);
- var orderPublishDetail = await _snapshotApplication.GetOrderPublishDetailAsync(items.OrderByDescending(m => m.HandleTime).First().Id, CancellationToken.None);
- orderPublishDetail.ShouldNotBeNull();
- orderPublishDetail.Workflow.Any(m => m.Name.IsNullOrEmpty()).ShouldBeFalse();
- }
- [Fact]
- public async Task GetOrderPublishDetail_Test()
- {
- }
- [Fact]
- public async Task GetBulletins_Test()
- {
- var homePage = await _snapshotApplication.GetHomePageAsync();
- var inDto = new BulletinInDto
- {
- IndustryId = homePage.Industrys.First(m => m.Name == "文化旅游").Id,
- };
- var items = await _snapshotApplication.GetBulletinsAsync(inDto, CancellationToken.None);
- items.ShouldNotBeNull();
- items.Any().ShouldBe(true, "公告数据为空");
- items.Any(m => m.Title.IsNullOrEmpty()).ShouldBe(false, "标题错误");
- items.Any(m => m.Content.IsNullOrEmpty()).ShouldBe(false, "内容错误");
- items.Any(m => m.Id.IsNullOrEmpty()).ShouldBe(false, "Id错误");
- }
- [Fact]
- public async Task GetSnapshotUserInfo_Test()
- {
- await _identityAppService.GetThredTokenAsync(new ThirdTokenInDto());
- var result = await _snapshotApplication.GetSnapshotUserInfoAsync();
- result.ShouldNotBeNull();
- result.PhoneNumber.ShouldNotBeNullOrEmpty();
- result.PhoneNumberMask.Contains("***").ShouldBeTrue();
- }
- [Fact]
- public async Task RefreshTokenAsync()
- {
- var token = await _identityAppService.GetThredTokenAsync(new ThirdTokenInDto());
- var newToken = await _identityAppService.RefreshTokenAsync(token.OpenId);
- newToken.ShouldNotBeNull();
- newToken.OpenId.ShouldBe(token.OpenId);
- newToken.PhoneNumber.ShouldNotBeNullOrEmpty();
- }
- [Fact]
- public async Task GetThirdToken_Test()
- {
- var result = await _identityAppService.GetThredTokenAsync(new ThirdTokenInDto { LoginCode = "0c3Adhll2zDMBe413rnl2KvEym2AdhlH" });
- result.PhoneNumber.ShouldNotBeNullOrEmpty();
- }
- [Theory]
- [InlineData("")]
- [InlineData("测")]
- public async Task SnapshotOrder_Test(string key)
- {
- var dto = new OrderInDto();
- dto.KeyWords = key;
- var page = await _snapshotApplication.GetSnapshotOrdersAsync(dto, CancellationToken.None);
- page.Count.ShouldNotBe(0);
- page.FirstOrDefault()?.IndustryName.ShouldNotBeNullOrEmpty();
- page.FirstOrDefault()?.OrderNo.ShouldNotBeNullOrEmpty();
- page.FirstOrDefault()?.StatusText.ShouldNotBeNullOrEmpty();
- page.FirstOrDefault()?.Area.ShouldNotBeNullOrEmpty();
- }
- [Theory]
- [InlineData(EOrderQueryStatus.All, 3)]
- [InlineData(EOrderQueryStatus.Reply, 2)]
- [InlineData(EOrderQueryStatus.NoReply, 1)]
- [InlineData(EOrderQueryStatus.Appraise, 1)]
- public async Task SnapshotOrderStatus_Test(EOrderQueryStatus status, int count)
- {
- var dto = new OrderInDto { Status = status };
- var page = await _snapshotApplication.GetSnapshotOrdersAsync(dto, CancellationToken.None);
- page.Count.ShouldNotBe(0, $"状态:{status.GetDescription()} 数据为空");
- }
- [Fact]
- public async Task GetSnapshotOrderDetail_Test()
- {
- var page = await _snapshotApplication.GetSnapshotOrdersAsync(new OrderInDto(), CancellationToken.None);
- var id = page.First().Id;
- var detail = await _snapshotApplication.GetSnapshotOrderDetailAsync(id, CancellationToken.None);
- detail.Id.ShouldBe(id);
- detail.Title.ShouldNotBeNullOrEmpty();
- detail.Opinion.ShouldNotBeNullOrEmpty();
- detail.Content.ShouldNotBeNullOrEmpty();
- }
- [Theory]
- [InlineData(2, 2)]
- [InlineData(12, 12)]
- public async Task GetRedPackDateAsync(int count, int exp)
- {
- var items = await _snapshotApplication.GetRedPackDateAsync(new RedPackDateInDto { QueryCount = count }, CancellationToken.None);
- items.Count.ShouldNotBe(0, "0数据");
- items.Count.ShouldBe(exp, $"应该:{exp}, 实际 {items.Count}");
- }
- [Fact]
- public async Task GetRedPackReceivedTotal_Test()
- {
- var amount = await _snapshotApplication.GetRedPackReceivedTotalAsync(CancellationToken.None);
- amount.ShouldNotBe("0.00");
- amount.ShouldNotBe("0");
- }
- [Fact]
- public async Task AddVolunteerReport_Test()
- {
- await _snapshotApplication.AddVolunteerAsync(new AddVolunteerInDto { Name = _sessionContext.UserName, PhoneNumber = _sessionContext.Phone }, CancellationToken.None);
- var inDto = _fixture.Create<AddVolunteerReportInDto>();
- foreach (var item in inDto.Files)
- {
- item.FileName = DateTime.Now.ToShortTimeString() + "文件.doc";
- }
- var result = await _snapshotApplication.AddVolunteerReportAsync(inDto, CancellationToken.None);
- result.Id.ShouldNotBeNull();
- }
- [Fact]
- public async Task SaveInvitationCode_Test()
- {
- var code = DateTime.Now.ToShortTimeString();
- await _snapshotApplication.SaveInvitationCodeAsync(new SaveInvitationCodeInDto { InvitationCode = code });
- var third = await _thirdAccountRepository.GetByOpenIdAsync(_sessionContext.OpenId);
- third.InvitationCode.ShouldBe(code);
- }
- [Fact]
- public async Task GetPractitionerItems_Test()
- {
- var items = await _snapshotApplication.GetPractitionerItemsAsync(new PractitionerItemInDto { AreaId = "510399" }, CancellationToken.None);
- items.Count.ShouldNotBe(0);
- var item = await _snapshotApplication.GetPractitionerDetailAsync(items.First().Id, CancellationToken.None);
- item.Street.ShouldNotBeNullOrEmpty();
- item.Name.ShouldNotBeNullOrEmpty();
- item.SystemAreaName.ShouldNotBeNullOrEmpty();
- item.SystemAreaName.ShouldNotBeNullOrEmpty();
- item.Gender.ShouldNotBe(EGender.Unknown);
- item.GenderTxt.ShouldNotBeNullOrEmpty();
- item.PhoneNumber.ShouldNotBeNullOrEmpty();
- }
- [Theory]
- [InlineData(ERedPackPickupStatus.Unreceived)]
- [InlineData(ERedPackPickupStatus.Received)]
- public async Task GetRedPacksAsync(ERedPackPickupStatus status)
- {
- for (int i = 0;i < 12;i++)
- {
- var now = DateTime.Now;
- var entity = new RedPackRecord
- {
- OrderId = "111111111",
- Amount = 10 * 10,
- CreationTime = new DateTime(2024, i + 1, 02, now.Hour, now.Minute, now.Second),
- WXOpenId = "测试生成的OpenId",
- PickupStatus = status,
- };
- await _redPackRecordRepository.AddAsync(entity);
- }
- var page = await _snapshotApplication.GetRedPacksAsync(new RedPacksInDto { Status = status }, CancellationToken.None);
- page.Count.ShouldNotBe(0, "数据不应该为空");
- }
- [Fact]
- public async Task GetBulletinsDetail_Test()
- {
- var detail = await _snapshotApplication.GetBulletinsDetailAsync("08dc788f-20f4-4bf1-83d3-b5a8a4f395b0");
- detail.Id.ShouldNotBeNullOrEmpty();
- detail.Title.ShouldNotBeNullOrEmpty();
- detail.Content.ShouldNotBeNullOrEmpty();
- }
- [Fact]
- public async Task InitRedPackDataAsync()
- {
-
- }
- /// <summary>
- /// 测试行业
- /// 测试添加数据是否和获取的数据一致
- /// </summary>
- /// <returns></returns>
- [Fact]
- public async Task Industry_Test()
- {
- var industry = new AddIndustryDto
- {
- Name = "测试行业",
- TitleSuffix = "测试标题",
- ApproveOrgId = "测试审批部门Id",
- ApproveOrgName = "测试审批部门名字",
- AcceptType = "测试受理类型",
- AcceptTypeCode = "测试受理类型代码",
- CitizenReadPackAmount = 100,
- GuiderReadPackAmount = 200,
- IsEnable = true,
- Files = new List<IndustryFileDto>
- {
- new IndustryFileDto
- {
- Name = "测试文件" + DateTime.Now.ToShortDateString(),
- Path = "测试文件地址" + DateTime.Now.ToShortTimeString(),
- FileName ="测试文件" + DateTime.Now.ToShortDateString() + ".doc",
- AdditionId = DateTime.Now.ToLongDateString()
- }
- }
- };
- var industryId = await _industryApplication.AddIndustryAsync(industry, CancellationToken.None);
- var pageDto = await _snapshotApplication.GetIndustryBaseAsync(industryId, CancellationToken.None);
- try
- {
- pageDto.ShouldNotBeNull();
- pageDto.Files.ShouldNotBeNull();
- foreach (var file in pageDto.Files)
- {
- file.Id.ShouldNotBeNullOrEmpty();
- file.Name.ShouldNotBeNullOrEmpty();
- file.Path.ShouldNotBeNullOrEmpty();
- file.FileName.ShouldNotBeNullOrEmpty();
- file.AdditionId.ShouldNotBeNullOrEmpty();
- file.Key.ShouldBe(industryId);
- }
- pageDto.Workplace.ShouldNotBeNull();
- pageDto.WorkplaceName.ShouldNotBeNull();
- }
- catch (Exception e)
- {
- // ignore
- }
- finally
- {
- await _industryRepository.Removeable().Where(m => m.Id == industryId).ExecuteCommandAsync();
- await _fileRepository.Removeable().Where(m => m.Id == pageDto.Files.First().Id).ExecuteCommandAsync();
- }
- }
- }
|