SnapshotApplicationTest.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. using DocumentFormat.OpenXml.Wordprocessing;
  2. using Hotline.Api.Controllers;
  3. using Hotline.Application.Identity;
  4. using Hotline.Application.Snapshot;
  5. using Hotline.Application.Tests.Mock;
  6. using Hotline.File;
  7. using Hotline.Identity.Accounts;
  8. using Hotline.Identity.Roles;
  9. using Hotline.Orders;
  10. using Hotline.Share.Dtos.Article;
  11. using Hotline.Share.Dtos.Snapshot;
  12. using Hotline.Share.Enums;
  13. using Hotline.Share.Enums.Snapshot;
  14. using Hotline.Share.Tools;
  15. using Hotline.Snapshot;
  16. using Hotline.Snapshot.Interfaces;
  17. using Hotline.Users;
  18. using Microsoft.AspNetCore.Http;
  19. using Microsoft.Extensions.DependencyInjection;
  20. using Shouldly;
  21. using System;
  22. using XF.Domain.Repository;
  23. using XF.Utility.EnumExtensions;
  24. namespace Hotline.Application.Tests.Application;
  25. public class SnapshotApplicationTest : TestBase
  26. {
  27. private readonly ISnapshotApplication _snapshotApplication;
  28. private readonly IIdentityAppService _identityAppService;
  29. private readonly IRepository<RedPackRecord> _redPackRecordRepository;
  30. private readonly IIndustryApplication _industryApplication;
  31. private readonly IIndustryRepository _industryRepository;
  32. private readonly IFileRepository _fileRepository;
  33. private readonly OrderServiceMock _orderServiceMock;
  34. private readonly IOrderRepository _orderRepository;
  35. private readonly IOrderSnapshotRepository _orderSnapshotRepository;
  36. 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) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdService, thirdAccount)
  37. {
  38. _snapshotApplication = snapshotApplication;
  39. _identityAppService = identityAppService;
  40. _redPackRecordRepository = redPackRecordRepository;
  41. _industryApplication = industryApplication;
  42. _industryRepository = industryRepository;
  43. _fileRepository = fileRepository;
  44. _orderServiceMock = orderServiceMock;
  45. _orderRepository = orderRepository;
  46. _orderSnapshotRepository = orderSnapshotRepository;
  47. SetWeiXin();
  48. }
  49. [Fact]
  50. public async Task GetHomePage_Test()
  51. {
  52. var result = await _snapshotApplication.GetHomePageAsync();
  53. result.Industrys.Any().ShouldBe(true, "首页数据为空");
  54. result.Industrys.First().DisplayOrder.ShouldBe(1, "排序异常");
  55. }
  56. /// <summary>
  57. /// 添加随手拍公告
  58. /// </summary>
  59. /// <returns></returns>
  60. [Fact]
  61. public async Task AddBulletin_Test()
  62. {
  63. var industry = await _industryRepository.Queryable()
  64. .OrderBy(m => m.DisplayOrder)
  65. .FirstAsync();
  66. if (industry == null)
  67. {
  68. return;
  69. }
  70. var inDto = new AddSnapshotBulletinInDto
  71. {
  72. Title = "单元测试" + DateTime.Now.ToLongDateTimeString(),
  73. Content = "测试内容" + DateTime.Now.ToLongDateTimeString(),
  74. SnapshotBulletinTypeId = industry.BulletinTypeGuideId!,
  75. SnapshotBulletinTypeName = industry.BulletinTypeGuideName!
  76. };
  77. var bulletinId = await _snapshotApplication.AddBulletinAsync(inDto);
  78. inDto = new AddSnapshotBulletinInDto
  79. {
  80. Title = "单元测试" + DateTime.Now.ToLongDateTimeString(),
  81. Content = "测试内容" + DateTime.Now.ToLongDateTimeString(),
  82. SnapshotBulletinTypeId = industry.BulletinTypePublicityId!,
  83. SnapshotBulletinTypeName = industry.BulletinTypePublicityName!
  84. };
  85. bulletinId = await _snapshotApplication.AddBulletinAsync(inDto);
  86. await _snapshotApplication.AuditBulletinAsync(new ExamineBulletinDto { Id = bulletinId, IsPass = true, Reason = "测试审核通过"});
  87. var items = await _snapshotApplication.GetBulletinsAsync(new BulletinInDto { IndustryId = industry.Id }, CancellationToken.None);
  88. items.Count.ShouldNotBe(0, "公告数量为0");
  89. }
  90. /// <summary>
  91. /// 获取公开工单集合
  92. /// </summary>
  93. /// <returns></returns>
  94. [Fact]
  95. public async Task GetPublishOrder_Test()
  96. {
  97. var industry = await _industryRepository.Queryable()
  98. .OrderBy(m => m.DisplayOrder)
  99. .FirstAsync();
  100. SetWeiXin();
  101. var order = _orderServiceMock.CreateSnapshotOrder()
  102. .办理到派单员(SetZuoXi)
  103. .办理到归档(SetPaiDanYuan)
  104. .GetCreateResult();
  105. SetWeiXin();
  106. var orderEntity = await _orderRepository.GetAsync(order.Id);
  107. var orderSnapshot = await _orderSnapshotRepository.GetAsync(order.Id);
  108. var inDto = new AddSnapshotOrderPublishInDto
  109. {
  110. ArrangeContent = orderEntity.Content,
  111. ArrangeOpinion = orderEntity.ActualOpinion,
  112. ArrangeTitle = orderEntity.Title,
  113. OrderId = orderEntity.Id,
  114. Address = orderEntity.FullAddress,
  115. HandleTime = DateTime.Now
  116. };
  117. await _snapshotApplication.AddOrderPublishAsync(inDto, CancellationToken.None);
  118. var items = await _snapshotApplication.GetOrderPublishAsync(new OrderPublishInDto { IndustryId = industry.Id }, CancellationToken.None);
  119. items.Count.ShouldNotBe(0);
  120. var orderPublishDetail = await _snapshotApplication.GetOrderPublishDetailAsync(items.OrderByDescending(m => m.HandleTime).First().Id, CancellationToken.None);
  121. orderPublishDetail.ShouldNotBeNull();
  122. orderPublishDetail.Workflow.Any(m => m.Name.IsNullOrEmpty()).ShouldBeFalse();
  123. }
  124. [Fact]
  125. public async Task GetOrderPublishDetail_Test()
  126. {
  127. }
  128. [Fact]
  129. public async Task GetBulletins_Test()
  130. {
  131. var homePage = await _snapshotApplication.GetHomePageAsync();
  132. var inDto = new BulletinInDto
  133. {
  134. IndustryId = homePage.Industrys.First(m => m.Name == "文化旅游").Id,
  135. };
  136. var items = await _snapshotApplication.GetBulletinsAsync(inDto, CancellationToken.None);
  137. items.ShouldNotBeNull();
  138. items.Any().ShouldBe(true, "公告数据为空");
  139. items.Any(m => m.Title.IsNullOrEmpty()).ShouldBe(false, "标题错误");
  140. items.Any(m => m.Content.IsNullOrEmpty()).ShouldBe(false, "内容错误");
  141. items.Any(m => m.Id.IsNullOrEmpty()).ShouldBe(false, "Id错误");
  142. }
  143. [Fact]
  144. public async Task GetSnapshotUserInfo_Test()
  145. {
  146. await _identityAppService.GetThredTokenAsync(new ThirdTokenInDto());
  147. var result = await _snapshotApplication.GetSnapshotUserInfoAsync();
  148. result.ShouldNotBeNull();
  149. result.PhoneNumber.ShouldNotBeNullOrEmpty();
  150. result.PhoneNumberMask.Contains("***").ShouldBeTrue();
  151. }
  152. [Fact]
  153. public async Task GetThirdToken_Test()
  154. {
  155. var result = await _identityAppService.GetThredTokenAsync(new ThirdTokenInDto { LoginCode = "0c3Adhll2zDMBe413rnl2KvEym2AdhlH" });
  156. }
  157. [Theory]
  158. [InlineData("")]
  159. [InlineData("测")]
  160. public async Task SnapshotOrder_Test(string key)
  161. {
  162. var dto = new OrderInDto();
  163. dto.KeyWords = key;
  164. var page = await _snapshotApplication.GetSnapshotOrdersAsync(dto, CancellationToken.None);
  165. page.Count.ShouldNotBe(0);
  166. page.FirstOrDefault()?.IndustryName.ShouldNotBeNullOrEmpty();
  167. page.FirstOrDefault()?.OrderNo.ShouldNotBeNullOrEmpty();
  168. page.FirstOrDefault()?.StatusText.ShouldNotBeNullOrEmpty();
  169. page.FirstOrDefault()?.Area.ShouldNotBeNullOrEmpty();
  170. }
  171. [Theory]
  172. [InlineData(EOrderQueryStatus.All, 3)]
  173. [InlineData(EOrderQueryStatus.Reply, 2)]
  174. [InlineData(EOrderQueryStatus.NoReply, 1)]
  175. [InlineData(EOrderQueryStatus.Appraise, 1)]
  176. public async Task SnapshotOrderStatus_Test(EOrderQueryStatus status, int count)
  177. {
  178. var dto = new OrderInDto { Status = status };
  179. var page = await _snapshotApplication.GetSnapshotOrdersAsync(dto, CancellationToken.None);
  180. page.Count.ShouldNotBe(0, $"状态:{status.GetDescription()} 数据为空");
  181. }
  182. [Fact]
  183. public async Task GetSnapshotOrderDetail_Test()
  184. {
  185. var page = await _snapshotApplication.GetSnapshotOrdersAsync(new OrderInDto(), CancellationToken.None);
  186. var id = page.First().Id;
  187. var detail = await _snapshotApplication.GetSnapshotOrderDetailAsync(id, CancellationToken.None);
  188. detail.Id.ShouldBe(id);
  189. detail.Title.ShouldNotBeNullOrEmpty();
  190. detail.Opinion.ShouldNotBeNullOrEmpty();
  191. detail.Content.ShouldNotBeNullOrEmpty();
  192. }
  193. [Theory]
  194. [InlineData(2, 2)]
  195. [InlineData(12, 12)]
  196. public async Task GetRedPackDateAsync(int count, int exp)
  197. {
  198. var items = await _snapshotApplication.GetRedPackDateAsync(new RedPackDateInDto { QueryCount = count }, CancellationToken.None);
  199. items.Count.ShouldNotBe(0, "0数据");
  200. items.Count.ShouldBe(exp, $"应该:{exp}, 实际 {items.Count}");
  201. }
  202. [Fact]
  203. public async Task GetRedPackReceivedTotal_Test()
  204. {
  205. var amount = await _snapshotApplication.GetRedPackReceivedTotalAsync(CancellationToken.None);
  206. amount.ShouldNotBe("0.00");
  207. amount.ShouldNotBe("0");
  208. }
  209. [Theory]
  210. [InlineData(ERedPackPickupStatus.Unreceived)]
  211. [InlineData(ERedPackPickupStatus.Received)]
  212. public async Task GetRedPacksAsync(ERedPackPickupStatus status)
  213. {
  214. for (int i = 0;i < 12;i++)
  215. {
  216. var now = DateTime.Now;
  217. var entity = new RedPackRecord
  218. {
  219. OrderId = "111111111",
  220. Amount = 10 * 10,
  221. CreationTime = new DateTime(2024, i + 1, 02, now.Hour, now.Minute, now.Second),
  222. WXOpenId = "测试生成的OpenId",
  223. PickupStatus = status,
  224. };
  225. await _redPackRecordRepository.AddAsync(entity);
  226. }
  227. var page = await _snapshotApplication.GetRedPacksAsync(new RedPacksInDto { Status = status }, CancellationToken.None);
  228. page.Count.ShouldNotBe(0, "数据不应该为空");
  229. }
  230. [Fact]
  231. public async Task GetBulletinsDetail_Test()
  232. {
  233. var detail = await _snapshotApplication.GetBulletinsDetailAsync("08dc788f-20f4-4bf1-83d3-b5a8a4f395b0");
  234. detail.Id.ShouldNotBeNullOrEmpty();
  235. detail.Title.ShouldNotBeNullOrEmpty();
  236. detail.Content.ShouldNotBeNullOrEmpty();
  237. }
  238. [Fact]
  239. public async Task InitRedPackDataAsync()
  240. {
  241. }
  242. /// <summary>
  243. /// 测试行业
  244. /// 测试添加数据是否和获取的数据一致
  245. /// </summary>
  246. /// <returns></returns>
  247. [Fact]
  248. public async Task Industry_Test()
  249. {
  250. var industry = new AddIndustryDto
  251. {
  252. Name = "测试行业",
  253. TitleSuffix = "测试标题",
  254. ApproveOrgId = "测试审批部门Id",
  255. ApproveOrgName = "测试审批部门名字",
  256. AcceptType = "测试受理类型",
  257. AcceptTypeCode = "测试受理类型代码",
  258. CitizenReadPackAmount = 100,
  259. GuiderReadPackAmount = 200,
  260. IsEnable = true,
  261. Files = new List<IndustryFileDto>
  262. {
  263. new IndustryFileDto
  264. {
  265. Name = "测试文件" + DateTime.Now.ToShortDateString(),
  266. Path = "测试文件地址" + DateTime.Now.ToShortTimeString(),
  267. FileName ="测试文件" + DateTime.Now.ToShortDateString() + ".doc",
  268. AdditionId = DateTime.Now.ToLongDateString()
  269. }
  270. }
  271. };
  272. var industryId = await _industryApplication.AddIndustryAsync(industry, CancellationToken.None);
  273. var pageDto = await _snapshotApplication.GetIndustryBaseAsync(industryId, CancellationToken.None);
  274. try
  275. {
  276. pageDto.ShouldNotBeNull();
  277. pageDto.Files.ShouldNotBeNull();
  278. foreach (var file in pageDto.Files)
  279. {
  280. file.Id.ShouldNotBeNullOrEmpty();
  281. file.Name.ShouldNotBeNullOrEmpty();
  282. file.Path.ShouldNotBeNullOrEmpty();
  283. file.FileName.ShouldNotBeNullOrEmpty();
  284. file.AdditionId.ShouldNotBeNullOrEmpty();
  285. file.Key.ShouldBe(industryId);
  286. }
  287. pageDto.Workplace.ShouldNotBeNull();
  288. pageDto.WorkplaceName.ShouldNotBeNull();
  289. }
  290. catch (Exception e)
  291. {
  292. // ignore
  293. }
  294. finally
  295. {
  296. await _industryRepository.Removeable().Where(m => m.Id == industryId).ExecuteCommandAsync();
  297. await _fileRepository.Removeable().Where(m => m.Id == pageDto.Files.First().Id).ExecuteCommandAsync();
  298. }
  299. }
  300. }