BiSnapshotApplicationTest.cs 4.4 KB

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