BiSnapshotApplicationTest.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 System;
  17. using System.Collections.Generic;
  18. using System.Linq;
  19. using System.Linq.Dynamic.Core;
  20. using System.Text;
  21. using System.Threading.Tasks;
  22. using XF.Domain.Cache;
  23. using XF.Domain.Repository;
  24. namespace Hotline.Tests.Application;
  25. public class BiSnapshotApplicationTest : TestBase
  26. {
  27. private readonly IBiSnapshotApplication _biSnapshotApplication;
  28. 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)
  29. {
  30. _biSnapshotApplication = biSnapshotApplication;
  31. }
  32. [Fact]
  33. public async Task GetCountyStatistics_Test()
  34. {
  35. var inDto = new CommunityStatisticsInDto
  36. {
  37. StartTime = DateTime.Now.AddDays(-30),
  38. EndTime = DateTime.Now
  39. };
  40. var items = await _biSnapshotApplication.GetCommunityStatistics(inDto).ToListAsync();
  41. var first = items.FirstOrDefault();
  42. first.ShouldNotBeNull();
  43. first.CommunityName.ShouldBe("自贡市");
  44. var end = true;
  45. while (end)
  46. {
  47. var hasChild = items.Where(m => m.SumCount != 0).FirstOrDefault();
  48. if (hasChild == null)
  49. {
  50. end = false;
  51. return;
  52. }
  53. inDto.CommunityCode = hasChild.CommunityCode;
  54. items = await _biSnapshotApplication.GetCommunityStatistics(inDto).ToListAsync();
  55. if (hasChild.SumCount != 0)
  56. {
  57. var inDto2 = inDto.Adapt<CommunityStatisticsDetailsInDto>();
  58. inDto2.CommunityCode = hasChild.CommunityCode;
  59. var details = await _biSnapshotApplication.GetCommunityStatisticsDetails(inDto2).ToListAsync();
  60. details.Count.ShouldBe(hasChild.SumCount);
  61. }
  62. }
  63. }
  64. [Fact]
  65. public async Task GetCountyRedPackStatistics_Test()
  66. {
  67. var inDto = new CountyRedPackStatisticsInDto
  68. {
  69. StartTime = DateTime.Now.AddDays(-30),
  70. EndTime = DateTime.Now,
  71. };
  72. var items = await _biSnapshotApplication.GetCountyRedPackStatistics(inDto).ToListAsync();
  73. var transposedItems = items.SelectMany(item => item.GetType().GetProperties()
  74. .Select(prop => new { Property = prop.Name, Value = prop.GetValue(item) }))
  75. .GroupBy(x => x.Property)
  76. .ToDictionary(g => g.Key, g => g.Select(x => x.Value).ToList());
  77. transposedItems.ShouldNotBeNull();
  78. transposedItems.Count.ShouldNotBe(0);
  79. }
  80. [Fact]
  81. public async Task GetSnapshotDepartmentStatistics_Test()
  82. {
  83. var inDto = new SnapshotDepartmentStatisticsInDto
  84. {
  85. StartTime = DateTime.Now.AddDays(-30),
  86. EndTime = DateTime.Now,
  87. };
  88. var items = await _biSnapshotApplication.GetSnapshotDepartmentStatistics(inDto).ToListAsync();
  89. items.ShouldNotBeNull();
  90. var a = await _biSnapshotApplication.GetSnapshotDepartmentAveTimeStatistics(inDto.Adapt<SnapshotDepartmentAveTimeStatisticsInDto>()).ToListAsync();
  91. a.ShouldNotBeNull();
  92. var b = _biSnapshotApplication.GetReTransactStatistics(inDto.Adapt<ReTransactStatisticsInDto>());
  93. b.ShouldNotBeNull();
  94. var c = b.ToJson();
  95. var bInDto = inDto.Adapt<ReTransactStatisticsDetailsInDto>();
  96. bInDto.OrgCode = "001";
  97. var d = await _biSnapshotApplication.GetReTransactStatisticsDetail(bInDto).ToListAsync();
  98. d.ShouldNotBeNull();
  99. var e = _biSnapshotApplication.GetIndustryStatistics(inDto.Adapt<IndustryStatisticsInDto>());
  100. e.ShouldNotBeNull();
  101. }
  102. [Fact]
  103. public async Task GetCompliantStatisticsDetails_Test()
  104. {
  105. var inDto = new CompliantStatisticsDetailsInDto()
  106. {
  107. PageIndex = 1,
  108. PageSize = 20,
  109. StartTime = DateTime.Now.AddDays(-30),
  110. EndTime = DateTime.Now,
  111. FieldName = "orderCountNum",
  112. };
  113. var items = await _biSnapshotApplication.GetCompliantStatisticsDetails(inDto).ToPagedListAsync(inDto);
  114. items.Total.ShouldNotBe(0);
  115. }
  116. /// <summary>
  117. /// 检查合规统计
  118. /// </summary>
  119. /// <returns></returns>
  120. [Fact]
  121. public async Task GetCompliantStatistics_Test()
  122. {
  123. var inDto = new CompliantStatisticsInDto
  124. {
  125. StartTime = DateTime.Now.AddDays(-7),
  126. EndTime = DateTime.Now
  127. };
  128. var items = await _biSnapshotApplication.GetCompliantStatistics(inDto).ToListAsync();
  129. items.AddSumLine("OrgName");
  130. items.ShouldNotBeNull();
  131. }
  132. /// <summary>
  133. /// 市民红包审批统计
  134. /// </summary>
  135. /// <returns></returns>
  136. [Fact]
  137. public async Task GetRedPackAuditStatistics_Test()
  138. {
  139. var items = _biSnapshotApplication.GetRedPackAuditStatistics(new RedPackStatisticsInDto()
  140. {
  141. StartTime = DateTime.Now.AddDays(-7),
  142. EndTime = DateTime.Now
  143. });
  144. items.ShouldNotBeNull();
  145. }
  146. }