BiSnapshotApplicationTest.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.Snapshot.Interfaces;
  8. using Hotline.Users;
  9. using Mapster;
  10. using Microsoft.AspNetCore.Http;
  11. using Microsoft.Extensions.DependencyInjection;
  12. using Shouldly;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using XF.Domain.Cache;
  19. using XF.Domain.Repository;
  20. namespace Hotline.Tests.Application;
  21. public class BiSnapshotApplicationTest : TestBase
  22. {
  23. private readonly IBiSnapshotApplication _biSnapshotApplication;
  24. 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)
  25. {
  26. _biSnapshotApplication = biSnapshotApplication;
  27. }
  28. [Fact]
  29. public async Task GetCountyStatistics_Test()
  30. {
  31. var inDto = new CommunityStatisticsInDto
  32. {
  33. StartTime = DateTime.Now.AddDays(-30),
  34. EndTime = DateTime.Now
  35. };
  36. var items = await _biSnapshotApplication.GetCommunityStatistics(inDto).ToListAsync();
  37. var first = items.FirstOrDefault();
  38. first.ShouldNotBeNull();
  39. first.CommunityName.ShouldBe("自贡市");
  40. var end = true;
  41. while (end)
  42. {
  43. var hasChild = items.Where(m => m.SumCount != 0).FirstOrDefault();
  44. if (hasChild == null)
  45. {
  46. end = false;
  47. return;
  48. }
  49. inDto.CommunityCode = hasChild.CommunityCode;
  50. items = await _biSnapshotApplication.GetCommunityStatistics(inDto).ToListAsync();
  51. if (hasChild.SumCount != 0)
  52. {
  53. var inDto2 = inDto.Adapt<CommunityStatisticsDetailsInDto>();
  54. inDto2.CommunityCode = hasChild.CommunityCode;
  55. var details = await _biSnapshotApplication.GetCommunityStatisticsDetails(inDto2).ToListAsync();
  56. details.Count.ShouldBe(hasChild.SumCount);
  57. }
  58. }
  59. }
  60. [Fact]
  61. public async Task GetCountyRedPackStatistics_Test()
  62. {
  63. var inDto = new CountyRedPackStatisticsInDto
  64. {
  65. StartTime = DateTime.Now.AddDays(-30),
  66. EndTime = DateTime.Now,
  67. };
  68. var items = await _biSnapshotApplication.GetCountyRedPackStatistics(inDto).ToListAsync();
  69. var transposedItems = items.SelectMany(item => item.GetType().GetProperties()
  70. .Select(prop => new { Property = prop.Name, Value = prop.GetValue(item) }))
  71. .GroupBy(x => x.Property)
  72. .ToDictionary(g => g.Key, g => g.Select(x => x.Value).ToList());
  73. transposedItems.ShouldNotBeNull();
  74. transposedItems.Count.ShouldNotBe(0);
  75. }
  76. }