BiSnapshotApplicationTest.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using Hotline.Api.Controllers;
  2. using Hotline.Application.Snapshot;
  3. using Hotline.Identity.Accounts;
  4. using Hotline.Identity.Roles;
  5. using Hotline.Settings;
  6. using Hotline.Share.Dtos.Snapshot;
  7. using Hotline.Share.Tools;
  8. using Hotline.ThirdAccountDomainServices;
  9. using Hotline.ThirdAccountDomainServices.Interfaces;
  10. using Hotline.Users;
  11. using Mapster;
  12. using Microsoft.AspNetCore.Http;
  13. using Microsoft.Extensions.DependencyInjection;
  14. using Shouldly;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Linq;
  18. using System.Linq.Dynamic.Core;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. using XF.Domain.Cache;
  22. using XF.Domain.Repository;
  23. namespace Hotline.Tests.Application;
  24. public class BiSnapshotApplicationTest : TestBase
  25. {
  26. private readonly IBiSnapshotApplication _biSnapshotApplication;
  27. 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) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdIdentiyService, thirdAccountRepository, cacheSettingData, thirdAccountDomainFactory)
  28. {
  29. _biSnapshotApplication = biSnapshotApplication;
  30. }
  31. [Fact]
  32. public async Task GetCountyStatistics_Test()
  33. {
  34. var inDto = new CommunityStatisticsInDto
  35. {
  36. StartTime = DateTime.Now.AddDays(-30),
  37. EndTime = DateTime.Now
  38. };
  39. var items = await _biSnapshotApplication.GetCommunityStatistics(inDto).ToListAsync();
  40. var first = items.FirstOrDefault();
  41. first.ShouldNotBeNull();
  42. first.CommunityName.ShouldBe("自贡市");
  43. var end = true;
  44. while (end)
  45. {
  46. var hasChild = items.Where(m => m.SumCount != 0).FirstOrDefault();
  47. if (hasChild == null)
  48. {
  49. end = false;
  50. return;
  51. }
  52. inDto.CommunityCode = hasChild.CommunityCode;
  53. items = await _biSnapshotApplication.GetCommunityStatistics(inDto).ToListAsync();
  54. if (hasChild.SumCount != 0)
  55. {
  56. var inDto2 = inDto.Adapt<CommunityStatisticsDetailsInDto>();
  57. inDto2.CommunityCode = hasChild.CommunityCode;
  58. var details = await _biSnapshotApplication.GetCommunityStatisticsDetails(inDto2).ToListAsync();
  59. details.Count.ShouldBe(hasChild.SumCount);
  60. }
  61. }
  62. }
  63. [Fact]
  64. public async Task GetCountyRedPackStatistics_Test()
  65. {
  66. var inDto = new CountyRedPackStatisticsInDto
  67. {
  68. StartTime = DateTime.Now.AddDays(-30),
  69. EndTime = DateTime.Now,
  70. };
  71. var items = await _biSnapshotApplication.GetCountyRedPackStatistics(inDto).ToListAsync();
  72. var transposedItems = items.SelectMany(item => item.GetType().GetProperties()
  73. .Select(prop => new { Property = prop.Name, Value = prop.GetValue(item) }))
  74. .GroupBy(x => x.Property)
  75. .ToDictionary(g => g.Key, g => g.Select(x => x.Value).ToList());
  76. transposedItems.ShouldNotBeNull();
  77. transposedItems.Count.ShouldNotBe(0);
  78. }
  79. [Fact]
  80. public async Task GetSnapshotDepartmentStatistics_Test()
  81. {
  82. var inDto = new SnapshotDepartmentStatisticsInDto
  83. {
  84. StartTime = DateTime.Now.AddDays(-30),
  85. EndTime = DateTime.Now,
  86. };
  87. var items = await _biSnapshotApplication.GetSnapshotDepartmentStatistics(inDto).ToListAsync();
  88. items.ShouldNotBeNull();
  89. var a = await _biSnapshotApplication.GetSnapshotDepartmentAveTimeStatistics(inDto.Adapt<SnapshotDepartmentAveTimeStatisticsInDto>()).ToListAsync();
  90. a.ShouldNotBeNull();
  91. var b = _biSnapshotApplication.GetReTransactStatistics(inDto.Adapt<ReTransactStatisticsInDto>());
  92. b.ShouldNotBeNull();
  93. var c = b.ToJson();
  94. var bInDto = inDto.Adapt<ReTransactStatisticsDetailsInDto>();
  95. bInDto.OrgCode = "001";
  96. var d = await _biSnapshotApplication.GetReTransactStatisticsDetail(bInDto).ToListAsync();
  97. d.ShouldNotBeNull();
  98. var e = _biSnapshotApplication.GetIndustryStatistics(inDto.Adapt<IndustryStatisticsInDto>());
  99. e.ShouldNotBeNull();
  100. }
  101. }