BiSnapshotApplicationTest.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using Hotline.Api.Controllers;
  2. using Hotline.Application.Snapshot.Contracts;
  3. using Hotline.Identity.Accounts;
  4. using Hotline.Identity.Roles;
  5. using Hotline.Repository.SqlSugar.Extensions;
  6. using Hotline.Settings;
  7. using Hotline.Share.Dtos.Snapshot;
  8. using Hotline.Share.Tools;
  9. using Hotline.ThirdAccountDomainServices;
  10. using Hotline.ThirdAccountDomainServices.Interfaces;
  11. using Hotline.Users;
  12. using Mapster;
  13. using Microsoft.AspNetCore.Http;
  14. using Microsoft.Extensions.DependencyInjection;
  15. using Shouldly;
  16. using SqlSugar;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Linq;
  20. using System.Linq.Dynamic.Core;
  21. using System.Text;
  22. using System.Threading.Tasks;
  23. using XF.Domain.Cache;
  24. using XF.Domain.Repository;
  25. namespace Hotline.Tests.Application;
  26. public class BiSnapshotApplicationTest : TestBase
  27. {
  28. private readonly IBiSnapshotApplication _biSnapshotApplication;
  29. public BiSnapshotApplicationTest(IAccountRepository accountRepository, IRepository<Role> roleRepository, UserController userController, IServiceScopeFactory scopeFactory, IRepository<User> userRepository, IHttpContextAccessor httpContextAccessor, IThirdIdentiyService thirdIdentiyService, IThirdAccountRepository thirdAccountRepository, ITypedCache<SystemSetting> cacheSettingData, IBiSnapshotApplication biSnapshotApplication, ThirdAccounSupplierFactory thirdAccountDomainFactory, IServiceProvider serviceProvider) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdIdentiyService, thirdAccountRepository, cacheSettingData, thirdAccountDomainFactory, serviceProvider)
  30. {
  31. _biSnapshotApplication = biSnapshotApplication;
  32. }
  33. [Fact]
  34. public async Task GetCountyStatistics_Test()
  35. {
  36. var inDto = new CommunityStatisticsInDto
  37. {
  38. StartTime = DateTime.Now.AddDays(-30),
  39. EndTime = DateTime.Now
  40. };
  41. var items = await _biSnapshotApplication.GetCommunityStatistics(inDto).ToListAsync();
  42. var first = items.FirstOrDefault();
  43. first.ShouldNotBeNull();
  44. first.CommunityName.ShouldBe("自贡市");
  45. var end = true;
  46. while (end)
  47. {
  48. var hasChild = items.Where(m => m.SumCount != 0).FirstOrDefault();
  49. if (hasChild == null)
  50. {
  51. end = false;
  52. return;
  53. }
  54. inDto.CommunityCode = hasChild.CommunityCode;
  55. items = await _biSnapshotApplication.GetCommunityStatistics(inDto).ToListAsync();
  56. if (hasChild.SumCount != 0)
  57. {
  58. var inDto2 = inDto.Adapt<CommunityStatisticsDetailsInDto>();
  59. inDto2.CommunityCode = hasChild.CommunityCode;
  60. var details = await _biSnapshotApplication.GetCommunityStatisticsDetails(inDto2).ToListAsync();
  61. details.Count.ShouldBe(hasChild.SumCount);
  62. }
  63. }
  64. }
  65. [Fact]
  66. public async Task GetCountyRedPackStatistics_Test()
  67. {
  68. var inDto = new CountyRedPackStatisticsInDto
  69. {
  70. StartTime = DateTime.Now.AddDays(-30),
  71. EndTime = DateTime.Now,
  72. };
  73. var items = await _biSnapshotApplication.GetCountyRedPackStatistics(inDto).ToListAsync();
  74. var transposedItems = items.SelectMany(item => item.GetType().GetProperties()
  75. .Select(prop => new { Property = prop.Name, Value = prop.GetValue(item) }))
  76. .GroupBy(x => x.Property)
  77. .ToDictionary(g => g.Key, g => g.Select(x => x.Value).ToList());
  78. transposedItems.ShouldNotBeNull();
  79. transposedItems.Count.ShouldNotBe(0);
  80. }
  81. [Fact]
  82. public async Task GetSnapshotDepartmentStatistics_Test()
  83. {
  84. var inDto = new SnapshotDepartmentStatisticsInDto
  85. {
  86. StartTime = DateTime.Now.AddDays(-30),
  87. EndTime = DateTime.Now,
  88. };
  89. var items = await _biSnapshotApplication.GetSnapshotDepartmentStatistics(inDto).ToListAsync();
  90. items.ShouldNotBeNull();
  91. var a = await _biSnapshotApplication.GetSnapshotDepartmentAveTimeStatistics(inDto.Adapt<SnapshotDepartmentAveTimeStatisticsInDto>()).ToListAsync();
  92. a.ShouldNotBeNull();
  93. var b = _biSnapshotApplication.GetReTransactStatistics(inDto.Adapt<ReTransactStatisticsInDto>());
  94. b.ShouldNotBeNull();
  95. var c = b.ToJson();
  96. var bInDto = inDto.Adapt<ReTransactStatisticsDetailsInDto>();
  97. bInDto.OrgCode = "001";
  98. var d = await _biSnapshotApplication.GetReTransactStatisticsDetail(bInDto).ToListAsync();
  99. d.ShouldNotBeNull();
  100. var e = _biSnapshotApplication.GetIndustryStatistics(inDto.Adapt<IndustryStatisticsInDto>());
  101. e.ShouldNotBeNull();
  102. var areaPointsInDto = new SnapshotCountyPointsStatisticsInDto
  103. {
  104. StartTime = DateTime.Now.AddDays(-30),
  105. EndTime = DateTime.Now,
  106. };
  107. var areaPointsOutDto = _biSnapshotApplication.GetAreaPointsStatistics(areaPointsInDto).ToList();
  108. areaPointsOutDto.ShouldNotBeNull();
  109. }
  110. [Fact]
  111. public async Task GetCompliantStatisticsDetails_Test()
  112. {
  113. var inDto = new CompliantStatisticsDetailsInDto()
  114. {
  115. PageIndex = 1,
  116. PageSize = 20,
  117. StartTime = DateTime.Now.AddDays(-30),
  118. EndTime = DateTime.Now,
  119. FieldName = "orderCountNum",
  120. };
  121. var items = await _biSnapshotApplication.GetCompliantStatisticsDetails(inDto).ToPagedListAsync(inDto);
  122. items.Total.ShouldNotBe(0);
  123. }
  124. /// <summary>
  125. /// 检查合规统计
  126. /// </summary>
  127. /// <returns></returns>
  128. [Fact]
  129. public async Task GetCompliantStatistics_Test()
  130. {
  131. var inDto = new CompliantStatisticsInDto
  132. {
  133. StartTime = DateTime.Now.AddDays(-7),
  134. EndTime = DateTime.Now
  135. };
  136. var items = await _biSnapshotApplication.GetCompliantStatistics(inDto).ToListAsync();
  137. items.AddSumLine("OrgName");
  138. items.ShouldNotBeNull();
  139. }
  140. /// <summary>
  141. /// 市民红包审批统计
  142. /// </summary>
  143. /// <returns></returns>
  144. [Fact]
  145. public async Task GetRedPackAuditStatistics_Test()
  146. {
  147. var items = _biSnapshotApplication.GetRedPackAuditStatistics(new RedPackStatisticsInDto()
  148. {
  149. StartTime = DateTime.Now.AddDays(-7),
  150. EndTime = DateTime.Now
  151. });
  152. items.ShouldNotBeNull();
  153. }
  154. }