persistence/DD.Persistence.IntegrationTests/Controllers/TimeSeriesBaseControllerTest.cs
2024-12-18 14:20:05 +05:00

119 lines
3.6 KiB
C#

//using Mapster;
//using Microsoft.Extensions.DependencyInjection;
//using DD.Persistence.Client;
//using DD.Persistence.Client.Clients.Interfaces;
//using DD.Persistence.Database.Model;
//using System.Net;
//using Xunit;
//namespace DD.Persistence.IntegrationTests.Controllers;
//public abstract class TimeSeriesBaseControllerTest<TEntity, TDto> : BaseIntegrationTest
// where TEntity : class, ITimestampedData, new()
// where TDto : class, new()
//{
// private readonly ITimeSeriesClient<TDto> timeSeriesClient;
// public TimeSeriesBaseControllerTest(WebAppFactoryFixture factory) : base(factory)
// {
// dbContext.CleanupDbSet<TEntity>();
// var scope = factory.Services.CreateScope();
// var persistenceClientFactory = scope.ServiceProvider
// .GetRequiredService<PersistenceClientFactory>();
// timeSeriesClient = persistenceClientFactory.GetTimeSeriesClient<TDto>();
// }
// public async Task InsertRangeSuccess(TDto dto)
// {
// //arrange
// var expected = dto.Adapt<TDto>();
// //act
// var response = await timeSeriesClient.AddRange(new TDto[] { expected }, new CancellationToken());
// //assert
// Assert.Equal(1, response);
// }
// public async Task GetSuccess(DateTimeOffset beginDate, DateTimeOffset endDate, TEntity entity)
// {
// //arrange
// var dbset = dbContext.Set<TEntity>();
// dbset.Add(entity);
// dbContext.SaveChanges();
// var response = await timeSeriesClient.Get(beginDate, endDate, new CancellationToken());
// //assert
// Assert.NotNull(response);
// Assert.Single(response);
// }
// public async Task GetDatesRangeSuccess(TEntity entity)
// {
// //arrange
// var datesRangeExpected = 30;
// var entity2 = entity.Adapt<TEntity>();
// entity2.Date = entity.Date.AddDays(datesRangeExpected);
// var dbset = dbContext.Set<TEntity>();
// dbset.Add(entity);
// dbset.Add(entity2);
// dbContext.SaveChanges();
// var response = await timeSeriesClient.GetDatesRange(new CancellationToken());
// //assert
// Assert.NotNull(response);
// var datesRangeActual = (response.To - response.From).Days;
// Assert.Equal(datesRangeExpected, datesRangeActual);
// }
// public async Task GetResampledDataSuccess(TEntity entity)
// {
// //arrange
// var approxPointsCount = 10;
// var differenceBetweenStartAndEndDays = 50;
// var entities = new List<TEntity>();
// for (var i = 1; i <= differenceBetweenStartAndEndDays; i++)
// {
// var entity2 = entity.Adapt<TEntity>();
// entity2.Date = entity.Date.AddDays(i - 1);
// entities.Add(entity2);
// }
// var dbset = dbContext.Set<TEntity>();
// dbset.AddRange(entities);
// dbContext.SaveChanges();
// var response = await timeSeriesClient.GetResampledData(entity.Date.AddMinutes(-1), differenceBetweenStartAndEndDays * 24 * 60 * 60 + 60, approxPointsCount, new CancellationToken());
// //assert
// Assert.NotNull(response);
// var ratio = entities.Count / approxPointsCount;
// if (ratio > 1)
// {
// var expectedResampledCount = entities
// .Where((_, index) => index % ratio == 0)
// .Count();
// Assert.Equal(expectedResampledCount, response.Count());
// }
// else
// {
// Assert.Equal(entities.Count(), response.Count());
// }
// }
//}