BiSnapshotApplicationTest.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.Text;
  18. using System.Threading.Tasks;
  19. using XF.Domain.Cache;
  20. using XF.Domain.Repository;
  21. namespace Hotline.Tests.Application;
  22. public class BiSnapshotApplicationTest : TestBase
  23. {
  24. private readonly IBiSnapshotApplication _biSnapshotApplication;
  25. 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)
  26. {
  27. _biSnapshotApplication = biSnapshotApplication;
  28. }
  29. [Fact]
  30. public async Task GetCountyStatistics_Test()
  31. {
  32. var inDto = new CommunityStatisticsInDto
  33. {
  34. StartTime = DateTime.Now.AddDays(-30),
  35. EndTime = DateTime.Now
  36. };
  37. var items = await _biSnapshotApplication.GetCommunityStatistics(inDto).ToListAsync();
  38. var first = items.FirstOrDefault();
  39. first.ShouldNotBeNull();
  40. first.CommunityName.ShouldBe("自贡市");
  41. var end = true;
  42. while (end)
  43. {
  44. var hasChild = items.Where(m => m.SumCount != 0).FirstOrDefault();
  45. if (hasChild == null)
  46. {
  47. end = false;
  48. return;
  49. }
  50. inDto.CommunityCode = hasChild.CommunityCode;
  51. items = await _biSnapshotApplication.GetCommunityStatistics(inDto).ToListAsync();
  52. if (hasChild.SumCount != 0)
  53. {
  54. var inDto2 = inDto.Adapt<CommunityStatisticsDetailsInDto>();
  55. inDto2.CommunityCode = hasChild.CommunityCode;
  56. var details = await _biSnapshotApplication.GetCommunityStatisticsDetails(inDto2).ToListAsync();
  57. details.Count.ShouldBe(hasChild.SumCount);
  58. }
  59. }
  60. }
  61. [Fact]
  62. public async Task GetCountyRedPackStatistics_Test()
  63. {
  64. var inDto = new CountyRedPackStatisticsInDto
  65. {
  66. StartTime = DateTime.Now.AddDays(-30),
  67. EndTime = DateTime.Now,
  68. };
  69. var items = await _biSnapshotApplication.GetCountyRedPackStatistics(inDto).ToListAsync();
  70. var transposedItems = items.SelectMany(item => item.GetType().GetProperties()
  71. .Select(prop => new { Property = prop.Name, Value = prop.GetValue(item) }))
  72. .GroupBy(x => x.Property)
  73. .ToDictionary(g => g.Key, g => g.Select(x => x.Value).ToList());
  74. transposedItems.ShouldNotBeNull();
  75. transposedItems.Count.ShouldNotBe(0);
  76. }
  77. [Fact]
  78. public async Task GetSnapshotDepartmentStatistics_Test()
  79. {
  80. var inDto = new SnapshotDepartmentStatisticsInDto
  81. {
  82. StartTime = DateTime.Now.AddDays(-30),
  83. EndTime = DateTime.Now,
  84. };
  85. var items = await _biSnapshotApplication.GetSnapshotDepartmentStatistics(inDto).ToListAsync();
  86. items.ShouldNotBeNull();
  87. var a = await _biSnapshotApplication.GetSnapshotDepartmentAveTimeStatistics(inDto.Adapt<SnapshotDepartmentAveTimeStatisticsInDto>()).ToListAsync();
  88. a.ShouldNotBeNull();
  89. var b = _biSnapshotApplication.GetReTransactStatistics(inDto.Adapt<ReTransactStatisticsInDto>());
  90. b.ShouldNotBeNull();
  91. var c = b.ToJson();
  92. }
  93. }