1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using Hotline.Api.Controllers;
- using Hotline.Application.Snapshot;
- using Hotline.Identity.Accounts;
- using Hotline.Identity.Roles;
- using Hotline.Settings;
- using Hotline.Share.Dtos.Snapshot;
- using Hotline.Snapshot.Interfaces;
- using Hotline.Users;
- using Mapster;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.DependencyInjection;
- using Shouldly;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using XF.Domain.Cache;
- using XF.Domain.Repository;
- namespace Hotline.Tests.Application;
- public class BiSnapshotApplicationTest : TestBase
- {
- private readonly IBiSnapshotApplication _biSnapshotApplication;
- 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)
- {
- _biSnapshotApplication = biSnapshotApplication;
- }
- [Fact]
- public async Task GetCountyStatistics_Test()
- {
- var inDto = new CommunityStatisticsInDto
- {
- StartTime = DateTime.Now.AddDays(-30),
- EndTime = DateTime.Now
- };
- var items = await _biSnapshotApplication.GetCommunityStatistics(inDto).ToListAsync();
- var first = items.FirstOrDefault();
- first.ShouldNotBeNull();
- first.CommunityName.ShouldBe("自贡市");
- var end = true;
- while (end)
- {
- var hasChild = items.Where(m => m.SumCount != 0).FirstOrDefault();
- if (hasChild == null)
- {
- end = false;
- return;
- }
- inDto.CommunityCode = hasChild.CommunityCode;
- items = await _biSnapshotApplication.GetCommunityStatistics(inDto).ToListAsync();
- if (hasChild.SumCount != 0)
- {
- var inDto2 = inDto.Adapt<CommunityStatisticsDetailsInDto>();
- inDto2.CommunityCode = hasChild.CommunityCode;
- var details = await _biSnapshotApplication.GetCommunityStatisticsDetails(inDto2).ToListAsync();
- details.Count.ShouldBe(hasChild.SumCount);
- }
- }
- }
- [Fact]
- public async Task GetCountyRedPackStatistics_Test()
- {
- var inDto = new CountyRedPackStatisticsInDto
- {
- StartTime = DateTime.Now.AddDays(-30),
- EndTime = DateTime.Now,
- };
- var items = await _biSnapshotApplication.GetCountyRedPackStatistics(inDto).ToListAsync();
- var transposedItems = items.SelectMany(item => item.GetType().GetProperties()
- .Select(prop => new { Property = prop.Name, Value = prop.GetValue(item) }))
- .GroupBy(x => x.Property)
- .ToDictionary(g => g.Key, g => g.Select(x => x.Value).ToList());
- transposedItems.ShouldNotBeNull();
- transposedItems.Count.ShouldNotBe(0);
- }
- [Fact]
- public async Task GetSnapshotDepartmentStatistics_Test()
- {
- var inDto = new SnapshotDepartmentStatisticsInDto
- {
- StartTime = DateTime.Now.AddDays(-30),
- EndTime = DateTime.Now,
- };
- var items = await _biSnapshotApplication.GetSnapshotDepartmentStatistics(inDto).ToListAsync();
- items.ShouldNotBeNull();
- var a = await _biSnapshotApplication.GetSnapshotDepartmentAveTimeStatistics(inDto.Adapt<SnapshotDepartmentAveTimeStatisticsInDto>()).ToListAsync();
- a.ShouldNotBeNull();
- }
- }
|