BiSnapshotApplicationTest.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 GetDuplicateItems_Test()
  35. {
  36. var inDto = new DuplicateItemsInDto();
  37. var items = await _biSnapshotApplication.GetDuplicateItems(inDto).ToListAsync();
  38. var count = items.Count;
  39. }
  40. [Fact]
  41. public async Task GetCountyStatistics_Test()
  42. {
  43. var inDto = new CommunityStatisticsInDto
  44. {
  45. StartTime = DateTime.Now.AddDays(-30),
  46. EndTime = DateTime.Now
  47. };
  48. var items = await _biSnapshotApplication.GetCommunityStatistics(inDto).ToListAsync();
  49. var first = items.FirstOrDefault();
  50. first.ShouldNotBeNull();
  51. first.CommunityName.ShouldBe("自贡市");
  52. var end = true;
  53. while (end)
  54. {
  55. var hasChild = items.Where(m => m.SumCount != 0).FirstOrDefault();
  56. if (hasChild == null)
  57. {
  58. end = false;
  59. return;
  60. }
  61. inDto.CommunityCode = hasChild.CommunityCode;
  62. items = await _biSnapshotApplication.GetCommunityStatistics(inDto).ToListAsync();
  63. if (hasChild.SumCount != 0)
  64. {
  65. var inDto2 = inDto.Adapt<CommunityStatisticsDetailsInDto>();
  66. inDto2.CommunityFullName = hasChild.CommunityFullName;
  67. var details = await _biSnapshotApplication.GetCommunityStatisticsDetails(inDto2).ToListAsync();
  68. details.Count.ShouldBe(hasChild.SumCount);
  69. }
  70. }
  71. }
  72. [Fact]
  73. public async Task GetCountyRedPackStatistics_Test()
  74. {
  75. var inDto = new CountyRedPackStatisticsInDto
  76. {
  77. StartTime = DateTime.Now.AddDays(-30),
  78. EndTime = DateTime.Now,
  79. };
  80. var items = await _biSnapshotApplication.GetCountyRedPackStatistics(inDto).ToListAsync();
  81. var transposedItems = items.SelectMany(item => item.GetType().GetProperties()
  82. .Select(prop => new { Property = prop.Name, Value = prop.GetValue(item) }))
  83. .GroupBy(x => x.Property)
  84. .ToDictionary(g => g.Key, g => g.Select(x => x.Value).ToList());
  85. transposedItems.ShouldNotBeNull();
  86. transposedItems.Count.ShouldNotBe(0);
  87. }
  88. [Fact]
  89. public async Task GetSnapshotDepartmentStatistics_Test()
  90. {
  91. var inDto = new SnapshotDepartmentStatisticsInDto
  92. {
  93. StartTime = DateTime.Now.AddDays(-30),
  94. EndTime = DateTime.Now,
  95. };
  96. var items = await _biSnapshotApplication.GetSnapshotDepartmentStatistics(inDto).ToListAsync();
  97. items.ShouldNotBeNull();
  98. var a = await _biSnapshotApplication.GetSnapshotDepartmentAveTimeStatistics(inDto.Adapt<SnapshotDepartmentAveTimeStatisticsInDto>()).ToListAsync();
  99. a.ShouldNotBeNull();
  100. var b = _biSnapshotApplication.GetReTransactStatistics(inDto.Adapt<ReTransactStatisticsInDto>());
  101. b.ShouldNotBeNull();
  102. var c = b.ToJson();
  103. var bInDto = inDto.Adapt<ReTransactStatisticsDetailsInDto>();
  104. bInDto.OrgCode = "001";
  105. var d = await _biSnapshotApplication.GetReTransactStatisticsDetail(bInDto).ToListAsync();
  106. d.ShouldNotBeNull();
  107. var e = _biSnapshotApplication.GetIndustryStatistics(inDto.Adapt<IndustryStatisticsInDto>());
  108. e.ShouldNotBeNull();
  109. var areaPointsInDto = new SnapshotCountyPointsStatisticsInDto
  110. {
  111. StartTime = DateTime.Now.AddDays(-30),
  112. EndTime = DateTime.Now,
  113. };
  114. var areaPointsOutDto = _biSnapshotApplication.GetAreaPointsStatistics(areaPointsInDto).ToList();
  115. areaPointsOutDto.ShouldNotBeNull();
  116. }
  117. [Fact]
  118. public async Task GetCompliantStatisticsDetails_Test()
  119. {
  120. var inDto = new CompliantStatisticsDetailsInDto()
  121. {
  122. PageIndex = 1,
  123. PageSize = 20,
  124. StartTime = DateTime.Now.AddDays(-30),
  125. EndTime = DateTime.Now,
  126. FieldName = "orderCountNum",
  127. };
  128. var items = await _biSnapshotApplication.GetCompliantStatisticsDetails(inDto).ToPagedListAsync(inDto);
  129. items.Total.ShouldNotBe(0);
  130. }
  131. /// <summary>
  132. /// 检查合规统计
  133. /// </summary>
  134. /// <returns></returns>
  135. [Fact]
  136. public async Task GetCompliantStatistics_Test()
  137. {
  138. var inDto = new CompliantStatisticsInDto
  139. {
  140. StartTime = DateTime.Now.AddDays(-7),
  141. EndTime = DateTime.Now
  142. };
  143. var items = await _biSnapshotApplication.GetCompliantStatistics(inDto).ToListAsync();
  144. items.AddSumLine("OrgName");
  145. items.ShouldNotBeNull();
  146. }
  147. /// <summary>
  148. /// 市民红包审批统计
  149. /// </summary>
  150. /// <returns></returns>
  151. [Fact]
  152. public async Task GetRedPackAuditStatistics_Test()
  153. {
  154. var items = _biSnapshotApplication.GetRedPackAuditStatistics(new RedPackStatisticsInDto()
  155. {
  156. StartTime = DateTime.Now.AddDays(-7),
  157. EndTime = DateTime.Now
  158. });
  159. items.ShouldNotBeNull();
  160. }
  161. }