раскомментированы все тесты
Some checks failed
Run Tests / run_tests (push) Failing after 1m32s

This commit is contained in:
Olga Nemt 2024-12-18 16:19:05 +05:00
parent e881fc81ad
commit dfd486219b
7 changed files with 1133 additions and 1133 deletions

View File

@ -1,343 +1,343 @@
//using Mapster; using Mapster;
//using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
//using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
//using DD.Persistence.Database.Model; using DD.Persistence.Database.Model;
//using DD.Persistence.Models; using DD.Persistence.Models;
//using DD.Persistence.Models.Requests; using DD.Persistence.Models.Requests;
//using Xunit; using Xunit;
//using DD.Persistence.Client.Clients.Interfaces; using DD.Persistence.Client.Clients.Interfaces;
//using DD.Persistence.Client; using DD.Persistence.Client;
//namespace DD.Persistence.IntegrationTests.Controllers; namespace DD.Persistence.IntegrationTests.Controllers;
//public class ChangeLogControllerTest : BaseIntegrationTest public class ChangeLogControllerTest : BaseIntegrationTest
//{ {
// private readonly IChangeLogClient client; private readonly IChangeLogClient client;
// private static readonly Random generatorRandomDigits = new(); private static readonly Random generatorRandomDigits = new();
// public ChangeLogControllerTest(WebAppFactoryFixture factory) : base(factory) public ChangeLogControllerTest(WebAppFactoryFixture factory) : base(factory)
// { {
// var persistenceClientFactory = scope.ServiceProvider var persistenceClientFactory = scope.ServiceProvider
// .GetRequiredService<PersistenceClientFactory>(); .GetRequiredService<PersistenceClientFactory>();
// client = persistenceClientFactory.GetChangeLogClient(); client = persistenceClientFactory.GetChangeLogClient();
// } }
// [Fact] [Fact]
// public async Task ClearAndInsertRange_InEmptyDb() public async Task ClearAndInsertRange_InEmptyDb()
// { {
// // arrange // arrange
// dbContext.CleanupDbSet<ChangeLog>(); dbContext.CleanupDbSet<ChangeLog>();
// var idDiscriminator = Guid.NewGuid(); var idDiscriminator = Guid.NewGuid();
// var dtos = Generate(2); var dtos = Generate(2);
// // act // act
// var result = await client.ClearAndAddRange(idDiscriminator, dtos, new CancellationToken()); var result = await client.ClearAndAddRange(idDiscriminator, dtos, new CancellationToken());
// // assert // assert
// Assert.Equal(2, result); Assert.Equal(2, result);
// } }
// [Fact] [Fact]
// public async Task ClearAndInsertRange_InNotEmptyDb() public async Task ClearAndInsertRange_InNotEmptyDb()
// { {
// // arrange // arrange
// var insertedCount = 10; var insertedCount = 10;
// var createdResult = CreateChangeLogItems(insertedCount, (-15, 15)); var createdResult = CreateChangeLogItems(insertedCount, (-15, 15));
// var idDiscriminator = createdResult.Item1; var idDiscriminator = createdResult.Item1;
// var dtos = createdResult.Item2.Select(e => e.Adapt<DataWithWellDepthAndSectionDto>()); var dtos = createdResult.Item2.Select(e => e.Adapt<DataWithWellDepthAndSectionDto>());
// // act // act
// var result = await client.ClearAndAddRange(idDiscriminator, dtos, new CancellationToken()); var result = await client.ClearAndAddRange(idDiscriminator, dtos, new CancellationToken());
// // assert // assert
// Assert.Equal(insertedCount*2, result); Assert.Equal(insertedCount * 2, result);
// } }
// [Fact] [Fact]
// public async Task Add_returns_success() public async Task Add_returns_success()
// { {
// // arrange // arrange
// var count = 1; var count = 1;
// var idDiscriminator = Guid.NewGuid(); var idDiscriminator = Guid.NewGuid();
// var dtos = Generate(count); var dtos = Generate(count);
// var dto = dtos.FirstOrDefault()!; var dto = dtos.FirstOrDefault()!;
// // act // act
// var result = await client.Add(idDiscriminator, dto, new CancellationToken()); var result = await client.Add(idDiscriminator, dto, new CancellationToken());
// // assert // assert
// Assert.Equal(count, result); Assert.Equal(count, result);
// } }
// [Fact] [Fact]
// public async Task AddRange_returns_success() public async Task AddRange_returns_success()
// { {
// // arrange // arrange
// var count = 3; var count = 3;
// var idDiscriminator = Guid.NewGuid(); var idDiscriminator = Guid.NewGuid();
// var dtos = Generate(count); var dtos = Generate(count);
// // act // act
// var result = await client.AddRange(idDiscriminator, dtos, new CancellationToken()); var result = await client.AddRange(idDiscriminator, dtos, new CancellationToken());
// // assert // assert
// Assert.Equal(count, result); Assert.Equal(count, result);
// } }
// [Fact] [Fact]
// public async Task Update_returns_success() public async Task Update_returns_success()
// { {
// // arrange // arrange
// dbContext.CleanupDbSet<ChangeLog>(); dbContext.CleanupDbSet<ChangeLog>();
// var idDiscriminator = Guid.NewGuid(); var idDiscriminator = Guid.NewGuid();
// var dtos = Generate(1); var dtos = Generate(1);
// var dto = dtos.FirstOrDefault()!; var dto = dtos.FirstOrDefault()!;
// var result = await client.Add(idDiscriminator, dto, new CancellationToken()); var result = await client.Add(idDiscriminator, dto, new CancellationToken());
// var entity = dbContext.ChangeLog var entity = dbContext.ChangeLog
// .Where(x => x.IdDiscriminator == idDiscriminator) .Where(x => x.IdDiscriminator == idDiscriminator)
// .FirstOrDefault(); .FirstOrDefault();
// dto = entity.Adapt<DataWithWellDepthAndSectionDto>(); dto = entity.Adapt<DataWithWellDepthAndSectionDto>();
// dto.DepthEnd += 10; dto.DepthEnd += 10;
// // act // act
// result = await client.Update(dto, new CancellationToken()); result = await client.Update(dto, new CancellationToken());
// // assert // assert
// Assert.Equal(2, result); Assert.Equal(2, result);
// var dateBegin = DateTimeOffset.UtcNow.AddDays(-1); var dateBegin = DateTimeOffset.UtcNow.AddDays(-1);
// var dateEnd = DateTimeOffset.UtcNow.AddDays(1); var dateEnd = DateTimeOffset.UtcNow.AddDays(1);
// var changeLogResult = await client.GetChangeLogForInterval(idDiscriminator, dateBegin, dateEnd, new CancellationToken()); var changeLogResult = await client.GetChangeLogForInterval(idDiscriminator, dateBegin, dateEnd, new CancellationToken());
// Assert.NotNull(changeLogResult); Assert.NotNull(changeLogResult);
// var obsoleteDto = changeLogResult var obsoleteDto = changeLogResult
// .Where(e => e.Obsolete.HasValue) .Where(e => e.Obsolete.HasValue)
// .FirstOrDefault(); .FirstOrDefault();
// var activeDto = changeLogResult var activeDto = changeLogResult
// .Where(e => !e.Obsolete.HasValue) .Where(e => !e.Obsolete.HasValue)
// .FirstOrDefault(); .FirstOrDefault();
// if (obsoleteDto == null || activeDto == null) if (obsoleteDto == null || activeDto == null)
// { {
// Assert.Fail(); Assert.Fail();
// return; return;
// } }
// Assert.Equal(activeDto.Id, obsoleteDto.IdNext); Assert.Equal(activeDto.Id, obsoleteDto.IdNext);
// } }
// [Fact] [Fact]
// public async Task UpdateRange_returns_success() public async Task UpdateRange_returns_success()
// { {
// // arrange // arrange
// var count = 2; var count = 2;
// var dtos = Generate(count); var dtos = Generate(count);
// var entities = dtos.Select(d => d.Adapt<ChangeLog>()).ToArray(); var entities = dtos.Select(d => d.Adapt<ChangeLog>()).ToArray();
// dbContext.ChangeLog.AddRange(entities); dbContext.ChangeLog.AddRange(entities);
// dbContext.SaveChanges(); dbContext.SaveChanges();
// dtos = entities.Select(c => new DataWithWellDepthAndSectionDto() dtos = entities.Select(c => new DataWithWellDepthAndSectionDto()
// { {
// DepthEnd = c.DepthEnd + 10, DepthEnd = c.DepthEnd + 10,
// DepthStart = c.DepthStart + 10, DepthStart = c.DepthStart + 10,
// Id = c.Id, Id = c.Id,
// IdSection = c.IdSection, IdSection = c.IdSection,
// Value = c.Value Value = c.Value
// }).ToArray(); }).ToArray();
// // act // act
// var result = await client.UpdateRange(dtos, new CancellationToken()); var result = await client.UpdateRange(dtos, new CancellationToken());
// // assert // assert
// Assert.Equal(count * 2, result); Assert.Equal(count * 2, result);
// } }
// [Fact] [Fact]
// public async Task Delete_returns_success() public async Task Delete_returns_success()
// { {
// // arrange // arrange
// var dtos = Generate(1); var dtos = Generate(1);
// var dto = dtos.FirstOrDefault()!; var dto = dtos.FirstOrDefault()!;
// var entity = dto.Adapt<ChangeLog>(); var entity = dto.Adapt<ChangeLog>();
// dbContext.ChangeLog.Add(entity); dbContext.ChangeLog.Add(entity);
// dbContext.SaveChanges(); dbContext.SaveChanges();
// // act // act
// var result = await client.Delete(entity.Id, new CancellationToken()); var result = await client.Delete(entity.Id, new CancellationToken());
// // assert // assert
// Assert.Equal(1, result); Assert.Equal(1, result);
// } }
// [Fact] [Fact]
// public async Task DeleteRange_returns_success() public async Task DeleteRange_returns_success()
// { {
// // arrange // arrange
// var count = 10; var count = 10;
// var dtos = Generate(count); var dtos = Generate(count);
// var entities = dtos.Select(d => d.Adapt<ChangeLog>()).ToArray(); var entities = dtos.Select(d => d.Adapt<ChangeLog>()).ToArray();
// dbContext.ChangeLog.AddRange(entities); dbContext.ChangeLog.AddRange(entities);
// dbContext.SaveChanges(); dbContext.SaveChanges();
// // act // act
// var ids = entities.Select(e => e.Id); var ids = entities.Select(e => e.Id);
// var result = await client.DeleteRange(ids, new CancellationToken()); var result = await client.DeleteRange(ids, new CancellationToken());
// // assert // assert
// Assert.Equal(count, result); Assert.Equal(count, result);
// } }
// [Fact] [Fact]
// public async Task GetDatesRange_returns_success() public async Task GetDatesRange_returns_success()
// { {
// // arrange // arrange
// var changeLogItems = CreateChangeLogItems(3, (-15, 15)); var changeLogItems = CreateChangeLogItems(3, (-15, 15));
// var idDiscriminator = changeLogItems.Item1; var idDiscriminator = changeLogItems.Item1;
// var entities = changeLogItems.Item2.OrderBy(e => e.Creation); var entities = changeLogItems.Item2.OrderBy(e => e.Creation);
// // act // act
// var result = await client.GetDatesRange(idDiscriminator, new CancellationToken()); var result = await client.GetDatesRange(idDiscriminator, new CancellationToken());
// // assert // assert
// Assert.NotNull(result); Assert.NotNull(result);
// var minDate = entities.First().Creation; var minDate = entities.First().Creation;
// var maxDate = entities.Last().Creation; var maxDate = entities.Last().Creation;
// var expectedMinDate = minDate.ToUniversalTime().ToString(); var expectedMinDate = minDate.ToUniversalTime().ToString();
// var actualMinDate = result.From.ToUniversalTime().ToString(); var actualMinDate = result.From.ToUniversalTime().ToString();
// Assert.Equal(expectedMinDate, actualMinDate); Assert.Equal(expectedMinDate, actualMinDate);
// var expectedMaxDate = maxDate.ToUniversalTime().ToString(); var expectedMaxDate = maxDate.ToUniversalTime().ToString();
// var actualMaxDate = result.To.ToUniversalTime().ToString(); var actualMaxDate = result.To.ToUniversalTime().ToString();
// Assert.Equal(expectedMaxDate, actualMaxDate); Assert.Equal(expectedMaxDate, actualMaxDate);
// } }
// [Fact] [Fact]
// public async Task GetByDate_returns_success() public async Task GetByDate_returns_success()
// { {
// // arrange // arrange
// dbContext.CleanupDbSet<ChangeLog>(); dbContext.CleanupDbSet<ChangeLog>();
// //создаем записи //создаем записи
// var count = 5; var count = 5;
// var changeLogItems = CreateChangeLogItems(count, (-15, 15)); var changeLogItems = CreateChangeLogItems(count, (-15, 15));
// var idDiscriminator = changeLogItems.Item1; var idDiscriminator = changeLogItems.Item1;
// var entities = changeLogItems.Item2; var entities = changeLogItems.Item2;
// //удаляем все созданные записи за исключением первой и второй //удаляем все созданные записи за исключением первой и второй
// //даты 2-х оставшихся записей должны вернуться в методе GetByDate //даты 2-х оставшихся записей должны вернуться в методе GetByDate
// var ids = entities.Select(e => e.Id); var ids = entities.Select(e => e.Id);
// var idsToDelete = ids.Skip(2); var idsToDelete = ids.Skip(2);
// var deletedCount = await client.DeleteRange(idsToDelete, new CancellationToken()); var deletedCount = await client.DeleteRange(idsToDelete, new CancellationToken());
// var filterRequest = new SectionPartRequest() var filterRequest = new SectionPartRequest()
// { {
// DepthStart = 0, DepthStart = 0,
// DepthEnd = 1000, DepthEnd = 1000,
// }; };
// var paginationRequest = new PaginationRequest() var paginationRequest = new PaginationRequest()
// { {
// Skip = 0, Skip = 0,
// Take = 10, Take = 10,
// SortSettings = String.Empty, SortSettings = String.Empty,
// }; };
// var moment = DateTimeOffset.UtcNow.AddDays(16); var moment = DateTimeOffset.UtcNow.AddDays(16);
// var result = await client.GetByDate(idDiscriminator, moment, filterRequest, paginationRequest, new CancellationToken()); var result = await client.GetByDate(idDiscriminator, moment, filterRequest, paginationRequest, new CancellationToken());
// Assert.NotNull(result); Assert.NotNull(result);
// var restEntities = entities.Where(e => !idsToDelete.Contains(e.Id)); var restEntities = entities.Where(e => !idsToDelete.Contains(e.Id));
// Assert.Equal(restEntities.Count(), result.Count); Assert.Equal(restEntities.Count(), result.Count);
// var actualIds = restEntities.Select(e => e.Id); var actualIds = restEntities.Select(e => e.Id);
// var expectedIds = result.Items.Select(e => e.Id); var expectedIds = result.Items.Select(e => e.Id);
// Assert.Equivalent(expectedIds, actualIds); Assert.Equivalent(expectedIds, actualIds);
// } }
// [Theory] [Theory]
// [InlineData(5, -15, 15, -20, 20, 10)] [InlineData(5, -15, 15, -20, 20, 10)]
// [InlineData(5, -15, -10, -16, -9, 5)] [InlineData(5, -15, -10, -16, -9, 5)]
// public async Task GetChangeLogForInterval_returns_success( public async Task GetChangeLogForInterval_returns_success(
// int insertedCount, int insertedCount,
// int daysBeforeNowChangeLog, int daysBeforeNowChangeLog,
// int daysAfterNowChangeLog, int daysAfterNowChangeLog,
// int daysBeforeNowFilter, int daysBeforeNowFilter,
// int daysAfterNowFilter, int daysAfterNowFilter,
// int changeLogCount) int changeLogCount)
// { {
// // arrange // arrange
// dbContext.CleanupDbSet<ChangeLog>(); dbContext.CleanupDbSet<ChangeLog>();
// //создаем записи //создаем записи
// var count = insertedCount; var count = insertedCount;
// var daysRange = (daysBeforeNowChangeLog, daysAfterNowChangeLog); var daysRange = (daysBeforeNowChangeLog, daysAfterNowChangeLog);
// var changeLogItems = CreateChangeLogItems(count, daysRange); var changeLogItems = CreateChangeLogItems(count, daysRange);
// var idDiscriminator = changeLogItems.Item1; var idDiscriminator = changeLogItems.Item1;
// var entities = changeLogItems.Item2; var entities = changeLogItems.Item2;
// foreach (var entity in entities) foreach (var entity in entities)
// { {
// entity.DepthEnd += 10; entity.DepthEnd += 10;
// } }
// var dtos = entities.Select(e => e.Adapt<DataWithWellDepthAndSectionDto>()).ToArray(); var dtos = entities.Select(e => e.Adapt<DataWithWellDepthAndSectionDto>()).ToArray();
// await client.UpdateRange(dtos, new CancellationToken()); await client.UpdateRange(dtos, new CancellationToken());
// //act //act
// var dateBegin = DateTimeOffset.UtcNow.AddDays(daysBeforeNowFilter); var dateBegin = DateTimeOffset.UtcNow.AddDays(daysBeforeNowFilter);
// var dateEnd = DateTimeOffset.UtcNow.AddDays(daysAfterNowFilter); var dateEnd = DateTimeOffset.UtcNow.AddDays(daysAfterNowFilter);
// var result = await client.GetChangeLogForInterval(idDiscriminator, dateBegin, dateEnd, new CancellationToken()); var result = await client.GetChangeLogForInterval(idDiscriminator, dateBegin, dateEnd, new CancellationToken());
// //assert //assert
// Assert.NotNull(result); Assert.NotNull(result);
// Assert.Equal(changeLogCount, result.Count()); Assert.Equal(changeLogCount, result.Count());
// } }
// private static IEnumerable<DataWithWellDepthAndSectionDto> Generate(int count) private static IEnumerable<DataWithWellDepthAndSectionDto> Generate(int count)
// { {
// for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
// yield return new DataWithWellDepthAndSectionDto() yield return new DataWithWellDepthAndSectionDto()
// { {
// Value = new Dictionary<string, object>() Value = new Dictionary<string, object>()
// { {
// { "Key", 1 } { "Key", 1 }
// }, },
// DepthStart = generatorRandomDigits.Next(1, 5), DepthStart = generatorRandomDigits.Next(1, 5),
// DepthEnd = generatorRandomDigits.Next(5, 15), DepthEnd = generatorRandomDigits.Next(5, 15),
// Id = Guid.NewGuid(), Id = Guid.NewGuid(),
// IdSection = Guid.NewGuid() IdSection = Guid.NewGuid()
// }; };
// } }
// private (Guid, ChangeLog[]) CreateChangeLogItems(int count, (int, int) daysRange) private (Guid, ChangeLog[]) CreateChangeLogItems(int count, (int, int) daysRange)
// { {
// var minDayCount = daysRange.Item1; var minDayCount = daysRange.Item1;
// var maxDayCount = daysRange.Item2; var maxDayCount = daysRange.Item2;
// Guid idDiscriminator = Guid.NewGuid(); Guid idDiscriminator = Guid.NewGuid();
// var dtos = Generate(count); var dtos = Generate(count);
// var entities = dtos.Select(d => var entities = dtos.Select(d =>
// { {
// var entity = d.Adapt<ChangeLog>(); var entity = d.Adapt<ChangeLog>();
// entity.IdDiscriminator = idDiscriminator; entity.IdDiscriminator = idDiscriminator;
// entity.Creation = DateTimeOffset.UtcNow.AddDays(generatorRandomDigits.Next(minDayCount, maxDayCount)); entity.Creation = DateTimeOffset.UtcNow.AddDays(generatorRandomDigits.Next(minDayCount, maxDayCount));
// return entity; return entity;
// }).ToArray(); }).ToArray();
// dbContext.ChangeLog.AddRange(entities); dbContext.ChangeLog.AddRange(entities);
// dbContext.SaveChanges(); dbContext.SaveChanges();
// return (idDiscriminator, entities); return (idDiscriminator, entities);
// } }
//} }

View File

@ -1,85 +1,85 @@
//using DD.Persistence.Database.Model; using DD.Persistence.Database.Model;
//using DD.Persistence.Models; using DD.Persistence.Models;
//using Xunit; using Xunit;
//namespace DD.Persistence.IntegrationTests.Controllers; namespace DD.Persistence.IntegrationTests.Controllers;
//public class DataSaubControllerTest : TimeSeriesBaseControllerTest<DataSaub, DataSaubDto> public class DataSaubControllerTest : TimeSeriesBaseControllerTest<DataSaub, DataSaubDto>
//{ {
// private readonly DataSaubDto dto = new() private readonly DataSaubDto dto = new()
// { {
// AxialLoad = 1, AxialLoad = 1,
// BitDepth = 2, BitDepth = 2,
// BlockPosition = 3, BlockPosition = 3,
// BlockSpeed = 4, BlockSpeed = 4,
// Date = DateTimeOffset.UtcNow, Date = DateTimeOffset.UtcNow,
// Flow = 5, Flow = 5,
// HookWeight = 6, HookWeight = 6,
// IdFeedRegulator = 8, IdFeedRegulator = 8,
// Mode = 9, Mode = 9,
// Mse = 10, Mse = 10,
// MseState = 11, MseState = 11,
// Pressure = 12, Pressure = 12,
// Pump0Flow = 13, Pump0Flow = 13,
// Pump1Flow = 14, Pump1Flow = 14,
// Pump2Flow = 15, Pump2Flow = 15,
// RotorSpeed = 16, RotorSpeed = 16,
// RotorTorque = 17, RotorTorque = 17,
// User = string.Empty, User = string.Empty,
// WellDepth = 18, WellDepth = 18,
// }; };
// private readonly DataSaub entity = new() private readonly DataSaub entity = new()
// { {
// AxialLoad = 1, AxialLoad = 1,
// BitDepth = 2, BitDepth = 2,
// BlockPosition = 3, BlockPosition = 3,
// BlockSpeed = 4, BlockSpeed = 4,
// Date = DateTimeOffset.UtcNow, Date = DateTimeOffset.UtcNow,
// Flow = 5, Flow = 5,
// HookWeight = 6, HookWeight = 6,
// IdFeedRegulator = 8, IdFeedRegulator = 8,
// Mode = 9, Mode = 9,
// Mse = 10, Mse = 10,
// MseState = 11, MseState = 11,
// Pressure = 12, Pressure = 12,
// Pump0Flow = 13, Pump0Flow = 13,
// Pump1Flow = 14, Pump1Flow = 14,
// Pump2Flow = 15, Pump2Flow = 15,
// RotorSpeed = 16, RotorSpeed = 16,
// RotorTorque = 17, RotorTorque = 17,
// User = string.Empty, User = string.Empty,
// WellDepth = 18, WellDepth = 18,
// }; };
// public DataSaubControllerTest(WebAppFactoryFixture factory) : base(factory) public DataSaubControllerTest(WebAppFactoryFixture factory) : base(factory)
// { {
// } }
// [Fact] [Fact]
// public async Task InsertRange_returns_success() public async Task InsertRange_returns_success()
// { {
// await InsertRangeSuccess(dto); await InsertRangeSuccess(dto);
// } }
// [Fact] [Fact]
// public async Task Get_returns_success() public async Task Get_returns_success()
// { {
// var beginDate = DateTimeOffset.UtcNow.AddDays(-1); var beginDate = DateTimeOffset.UtcNow.AddDays(-1);
// var endDate = DateTimeOffset.UtcNow; var endDate = DateTimeOffset.UtcNow;
// await GetSuccess(beginDate, endDate, entity); await GetSuccess(beginDate, endDate, entity);
// } }
// [Fact] [Fact]
// public async Task GetDatesRange_returns_success() public async Task GetDatesRange_returns_success()
// { {
// await GetDatesRangeSuccess(entity); await GetDatesRangeSuccess(entity);
// } }
// [Fact] [Fact]
// public async Task GetResampledData_returns_success() public async Task GetResampledData_returns_success()
// { {
// await GetResampledDataSuccess(entity); await GetResampledDataSuccess(entity);
// } }
//} }

View File

@ -1,82 +1,82 @@
//using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Caching.Memory;
//using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
//using DD.Persistence.Client; using DD.Persistence.Client;
//using DD.Persistence.Client.Clients; using DD.Persistence.Client.Clients;
//using DD.Persistence.Client.Clients.Interfaces; using DD.Persistence.Client.Clients.Interfaces;
//using DD.Persistence.Database.Entity; using DD.Persistence.Database.Entity;
//using DD.Persistence.Models; using DD.Persistence.Models;
//using Xunit; using Xunit;
//namespace DD.Persistence.IntegrationTests.Controllers namespace DD.Persistence.IntegrationTests.Controllers
//{ {
// public class DataSourceSystemControllerTest : BaseIntegrationTest public class DataSourceSystemControllerTest : BaseIntegrationTest
// { {
// private static readonly string SystemCacheKey = $"{typeof(Database.Entity.DataSourceSystem).FullName}CacheKey"; private static readonly string SystemCacheKey = $"{typeof(Database.Entity.DataSourceSystem).FullName}CacheKey";
// private readonly IDataSourceSystemClient dataSourceSystemClient; private readonly IDataSourceSystemClient dataSourceSystemClient;
// private readonly IMemoryCache memoryCache; private readonly IMemoryCache memoryCache;
// public DataSourceSystemControllerTest(WebAppFactoryFixture factory) : base(factory) public DataSourceSystemControllerTest(WebAppFactoryFixture factory) : base(factory)
// { {
// var scope = factory.Services.CreateScope(); var scope = factory.Services.CreateScope();
// var persistenceClientFactory = scope.ServiceProvider var persistenceClientFactory = scope.ServiceProvider
// .GetRequiredService<PersistenceClientFactory>(); .GetRequiredService<PersistenceClientFactory>();
// dataSourceSystemClient = persistenceClientFactory.GetDataSourceSystemClient(); dataSourceSystemClient = persistenceClientFactory.GetDataSourceSystemClient();
// memoryCache = scope.ServiceProvider.GetRequiredService<IMemoryCache>(); memoryCache = scope.ServiceProvider.GetRequiredService<IMemoryCache>();
// } }
// [Fact] [Fact]
// public async Task Get_returns_success() public async Task Get_returns_success()
// { {
// //arrange //arrange
// memoryCache.Remove(SystemCacheKey); memoryCache.Remove(SystemCacheKey);
// dbContext.CleanupDbSet<DataSourceSystem>(); dbContext.CleanupDbSet<DataSourceSystem>();
// //act //act
// var response = await dataSourceSystemClient.Get(CancellationToken.None); var response = await dataSourceSystemClient.Get(CancellationToken.None);
// //assert //assert
// Assert.NotNull(response); Assert.NotNull(response);
// Assert.Empty(response); Assert.Empty(response);
// } }
// [Fact] [Fact]
// public async Task Get_AfterSave_returns_success() public async Task Get_AfterSave_returns_success()
// { {
// //arrange //arrange
// await Add(); await Add();
// //act //act
// var response = await dataSourceSystemClient.Get(CancellationToken.None); var response = await dataSourceSystemClient.Get(CancellationToken.None);
// //assert //assert
// Assert.NotNull(response); Assert.NotNull(response);
// var expectedSystemCount = 1; var expectedSystemCount = 1;
// var actualSystemCount = response!.Count(); var actualSystemCount = response!.Count();
// Assert.Equal(expectedSystemCount, actualSystemCount); Assert.Equal(expectedSystemCount, actualSystemCount);
// } }
// [Fact] [Fact]
// public async Task Add_returns_success() public async Task Add_returns_success()
// { {
// await Add(); await Add();
// } }
// private async Task Add() private async Task Add()
// { {
// //arrange //arrange
// memoryCache.Remove(SystemCacheKey); memoryCache.Remove(SystemCacheKey);
// dbContext.CleanupDbSet<DataSourceSystem>(); dbContext.CleanupDbSet<DataSourceSystem>();
// var dto = new DataSourceSystemDto() var dto = new DataSourceSystemDto()
// { {
// SystemId = Guid.NewGuid(), SystemId = Guid.NewGuid(),
// Name = "Test", Name = "Test",
// Description = "Test" Description = "Test"
// }; };
// //act //act
// await dataSourceSystemClient.Add(dto, CancellationToken.None); await dataSourceSystemClient.Add(dto, CancellationToken.None);
// } }
// } }
//} }

View File

@ -1,227 +1,227 @@
//using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
//using DD.Persistence.Client; using DD.Persistence.Client;
//using DD.Persistence.Client.Clients.Interfaces; using DD.Persistence.Client.Clients.Interfaces;
//using DD.Persistence.Database.Model; using DD.Persistence.Database.Model;
//using System.Net; using System.Net;
//using Xunit; using Xunit;
//namespace DD.Persistence.IntegrationTests.Controllers namespace DD.Persistence.IntegrationTests.Controllers
//{ {
// public class SetpointControllerTest : BaseIntegrationTest public class SetpointControllerTest : BaseIntegrationTest
// { {
// private readonly ISetpointClient setpointClient; private readonly ISetpointClient setpointClient;
// private class TestObject private class TestObject
// { {
// public string? Value1 { get; set; } public string? Value1 { get; set; }
// public int? Value2 { get; set; } public int? Value2 { get; set; }
// } }
// public SetpointControllerTest(WebAppFactoryFixture factory) : base(factory) public SetpointControllerTest(WebAppFactoryFixture factory) : base(factory)
// { {
// var scope = factory.Services.CreateScope(); var scope = factory.Services.CreateScope();
// var persistenceClientFactory = scope.ServiceProvider var persistenceClientFactory = scope.ServiceProvider
// .GetRequiredService<PersistenceClientFactory>(); .GetRequiredService<PersistenceClientFactory>();
// setpointClient = persistenceClientFactory.GetSetpointClient(); setpointClient = persistenceClientFactory.GetSetpointClient();
// } }
// [Fact] [Fact]
// public async Task GetCurrent_returns_success() public async Task GetCurrent_returns_success()
// { {
// //arrange //arrange
// var setpointKeys = new List<Guid>() var setpointKeys = new List<Guid>()
// { {
// Guid.NewGuid(), Guid.NewGuid(),
// Guid.NewGuid() Guid.NewGuid()
// }; };
// //act //act
// var response = await setpointClient.GetCurrent(setpointKeys, new CancellationToken()); var response = await setpointClient.GetCurrent(setpointKeys, new CancellationToken());
// //assert //assert
// Assert.NotNull(response); Assert.NotNull(response);
// Assert.Empty(response); Assert.Empty(response);
// } }
// [Fact] [Fact]
// public async Task GetCurrent_AfterSave_returns_success() public async Task GetCurrent_AfterSave_returns_success()
// { {
// //arrange //arrange
// var setpointKey = await Add(); var setpointKey = await Add();
// //act //act
// var response = await setpointClient.GetCurrent([setpointKey], new CancellationToken()); var response = await setpointClient.GetCurrent([setpointKey], new CancellationToken());
// //assert //assert
// Assert.NotNull(response); Assert.NotNull(response);
// Assert.NotEmpty(response); Assert.NotEmpty(response);
// Assert.Equal(setpointKey, response.FirstOrDefault()?.Key); Assert.Equal(setpointKey, response.FirstOrDefault()?.Key);
// } }
// [Fact] [Fact]
// public async Task GetHistory_returns_success() public async Task GetHistory_returns_success()
// { {
// //arrange //arrange
// var setpointKeys = new List<Guid>() var setpointKeys = new List<Guid>()
// { {
// Guid.NewGuid(), Guid.NewGuid(),
// Guid.NewGuid() Guid.NewGuid()
// }; };
// var historyMoment = DateTimeOffset.UtcNow; var historyMoment = DateTimeOffset.UtcNow;
// //act //act
// var response = await setpointClient.GetHistory(setpointKeys, historyMoment, new CancellationToken()); var response = await setpointClient.GetHistory(setpointKeys, historyMoment, new CancellationToken());
// //assert //assert
// Assert.NotNull(response); Assert.NotNull(response);
// Assert.Empty(response); Assert.Empty(response);
// } }
// [Fact] [Fact]
// public async Task GetHistory_AfterSave_returns_success() public async Task GetHistory_AfterSave_returns_success()
// { {
// //arrange //arrange
// var setpointKey = await Add(); var setpointKey = await Add();
// var historyMoment = DateTimeOffset.UtcNow; var historyMoment = DateTimeOffset.UtcNow;
// historyMoment = historyMoment.AddDays(1); historyMoment = historyMoment.AddDays(1);
// //act //act
// var response = await setpointClient.GetHistory([setpointKey], historyMoment, new CancellationToken()); var response = await setpointClient.GetHistory([setpointKey], historyMoment, new CancellationToken());
// //assert //assert
// Assert.NotNull(response); Assert.NotNull(response);
// Assert.NotEmpty(response); Assert.NotEmpty(response);
// Assert.Equal(setpointKey, response.FirstOrDefault()?.Key); Assert.Equal(setpointKey, response.FirstOrDefault()?.Key);
// } }
// [Fact] [Fact]
// public async Task GetLog_returns_success() public async Task GetLog_returns_success()
// { {
// //arrange //arrange
// var setpointKeys = new List<Guid>() var setpointKeys = new List<Guid>()
// { {
// Guid.NewGuid(), Guid.NewGuid(),
// Guid.NewGuid() Guid.NewGuid()
// }; };
// //act //act
// var response = await setpointClient.GetLog(setpointKeys, new CancellationToken()); var response = await setpointClient.GetLog(setpointKeys, new CancellationToken());
// //assert //assert
// Assert.NotNull(response); Assert.NotNull(response);
// Assert.Empty(response); Assert.Empty(response);
// } }
// [Fact] [Fact]
// public async Task GetLog_AfterSave_returns_success() public async Task GetLog_AfterSave_returns_success()
// { {
// //arrange //arrange
// var setpointKey = await Add(); var setpointKey = await Add();
// //act //act
// var response = await setpointClient.GetLog([setpointKey], new CancellationToken()); var response = await setpointClient.GetLog([setpointKey], new CancellationToken());
// //assert //assert
// Assert.NotNull(response); Assert.NotNull(response);
// Assert.NotEmpty(response); Assert.NotEmpty(response);
// Assert.Equal(setpointKey, response.FirstOrDefault().Key); Assert.Equal(setpointKey, response.FirstOrDefault().Key);
// } }
// [Fact] [Fact]
// public async Task GetDatesRange_returns_success() public async Task GetDatesRange_returns_success()
// { {
// //arrange //arrange
// dbContext.CleanupDbSet<Setpoint>(); dbContext.CleanupDbSet<Setpoint>();
// //act //act
// var response = await setpointClient.GetDatesRangeAsync(CancellationToken.None); var response = await setpointClient.GetDatesRangeAsync(CancellationToken.None);
// //assert //assert
// Assert.NotNull(response); Assert.NotNull(response);
// Assert.Equal(DateTimeOffset.MinValue, response!.From); Assert.Equal(DateTimeOffset.MinValue, response!.From);
// Assert.Equal(DateTimeOffset.MaxValue, response!.To); Assert.Equal(DateTimeOffset.MaxValue, response!.To);
// } }
// [Fact] [Fact]
// public async Task GetDatesRange_AfterSave_returns_success() public async Task GetDatesRange_AfterSave_returns_success()
// { {
// //arrange //arrange
// dbContext.CleanupDbSet<Setpoint>(); dbContext.CleanupDbSet<Setpoint>();
// await Add(); await Add();
// var dateBegin = DateTimeOffset.MinValue; var dateBegin = DateTimeOffset.MinValue;
// var take = 1; var take = 1;
// var part = await setpointClient.GetPart(dateBegin, take, CancellationToken.None); var part = await setpointClient.GetPart(dateBegin, take, CancellationToken.None);
// //act //act
// var response = await setpointClient.GetDatesRangeAsync(CancellationToken.None); var response = await setpointClient.GetDatesRangeAsync(CancellationToken.None);
// //assert //assert
// Assert.NotNull(response); Assert.NotNull(response);
// var expectedValue = part! var expectedValue = part!
// .FirstOrDefault()!.Created .FirstOrDefault()!.Created
// .ToString("dd.MM.yyyy-HH:mm:ss"); .ToString("dd.MM.yyyy-HH:mm:ss");
// var actualValueFrom = response.From var actualValueFrom = response.From
// .ToString("dd.MM.yyyy-HH:mm:ss"); .ToString("dd.MM.yyyy-HH:mm:ss");
// Assert.Equal(expectedValue, actualValueFrom); Assert.Equal(expectedValue, actualValueFrom);
// var actualValueTo = response.To var actualValueTo = response.To
// .ToString("dd.MM.yyyy-HH:mm:ss"); .ToString("dd.MM.yyyy-HH:mm:ss");
// Assert.Equal(expectedValue, actualValueTo); Assert.Equal(expectedValue, actualValueTo);
// } }
// [Fact] [Fact]
// public async Task GetPart_returns_success() public async Task GetPart_returns_success()
// { {
// //arrange //arrange
// var dateBegin = DateTimeOffset.UtcNow; var dateBegin = DateTimeOffset.UtcNow;
// var take = 2; var take = 2;
// //act //act
// var response = await setpointClient.GetPart(dateBegin, take, CancellationToken.None); var response = await setpointClient.GetPart(dateBegin, take, CancellationToken.None);
// //assert //assert
// Assert.NotNull(response); Assert.NotNull(response);
// Assert.Empty(response); Assert.Empty(response);
// } }
// [Fact] [Fact]
// public async Task GetPart_AfterSave_returns_success() public async Task GetPart_AfterSave_returns_success()
// { {
// //arrange //arrange
// var dateBegin = DateTimeOffset.UtcNow; var dateBegin = DateTimeOffset.UtcNow;
// var take = 1; var take = 1;
// await Add(); await Add();
// //act //act
// var response = await setpointClient.GetPart(dateBegin, take, CancellationToken.None); var response = await setpointClient.GetPart(dateBegin, take, CancellationToken.None);
// //assert //assert
// Assert.NotNull(response); Assert.NotNull(response);
// Assert.NotEmpty(response); Assert.NotEmpty(response);
// } }
// [Fact] [Fact]
// public async Task Save_returns_success() public async Task Save_returns_success()
// { {
// await Add(); await Add();
// } }
// private async Task<Guid> Add() private async Task<Guid> Add()
// { {
// //arrange //arrange
// var setpointKey = Guid.NewGuid(); var setpointKey = Guid.NewGuid();
// var setpointValue = new TestObject() var setpointValue = new TestObject()
// { {
// Value1 = "1", Value1 = "1",
// Value2 = 2 Value2 = 2
// }; };
// //act //act
// await setpointClient.Add(setpointKey, setpointValue, new CancellationToken()); await setpointClient.Add(setpointKey, setpointValue, new CancellationToken());
// return setpointKey; return setpointKey;
// } }
// } }
//} }

View File

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

View File

@ -1,206 +1,206 @@
//using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
//using DD.Persistence.Client; using DD.Persistence.Client;
//using DD.Persistence.Client.Clients.Interfaces; using DD.Persistence.Client.Clients.Interfaces;
//using DD.Persistence.Models; using DD.Persistence.Models;
//using Xunit; using Xunit;
//namespace DD.Persistence.IntegrationTests.Controllers; namespace DD.Persistence.IntegrationTests.Controllers;
//public class TimestampedSetControllerTest : BaseIntegrationTest public class TimestampedSetControllerTest : BaseIntegrationTest
//{ {
// private readonly ITimestampedSetClient client; private readonly ITimestampedSetClient client;
// public TimestampedSetControllerTest(WebAppFactoryFixture factory) : base(factory) public TimestampedSetControllerTest(WebAppFactoryFixture factory) : base(factory)
// { {
// var persistenceClientFactory = scope.ServiceProvider var persistenceClientFactory = scope.ServiceProvider
// .GetRequiredService<PersistenceClientFactory>(); .GetRequiredService<PersistenceClientFactory>();
// client = persistenceClientFactory.GetTimestampedSetClient(); client = persistenceClientFactory.GetTimestampedSetClient();
// } }
// [Fact] [Fact]
// public async Task InsertRange() public async Task InsertRange()
// { {
// // arrange // arrange
// Guid idDiscriminator = Guid.NewGuid(); Guid idDiscriminator = Guid.NewGuid();
// IEnumerable<TimestampedSetDto> testSets = Generate(10, DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(7))); IEnumerable<TimestampedSetDto> testSets = Generate(10, DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(7)));
// // act // act
// var response = await client.AddRange(idDiscriminator, testSets, CancellationToken.None); var response = await client.AddRange(idDiscriminator, testSets, CancellationToken.None);
// // assert // assert
// Assert.Equal(testSets.Count(), response); Assert.Equal(testSets.Count(), response);
// } }
// [Fact] [Fact]
// public async Task Get_without_filter() public async Task Get_without_filter()
// { {
// // arrange // arrange
// Guid idDiscriminator = Guid.NewGuid(); Guid idDiscriminator = Guid.NewGuid();
// int count = 10; int count = 10;
// IEnumerable<TimestampedSetDto> testSets = Generate(count, DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(7))); IEnumerable<TimestampedSetDto> testSets = Generate(count, DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(7)));
// await client.AddRange(idDiscriminator, testSets, CancellationToken.None); await client.AddRange(idDiscriminator, testSets, CancellationToken.None);
// // act // act
// var response = await client.Get(idDiscriminator, null, null, 0, int.MaxValue, CancellationToken.None); var response = await client.Get(idDiscriminator, null, null, 0, int.MaxValue, CancellationToken.None);
// // assert // assert
// Assert.NotNull(response); Assert.NotNull(response);
// Assert.Equal(count, response.Count()); Assert.Equal(count, response.Count());
// } }
// [Fact] [Fact]
// public async Task Get_with_filter_props() public async Task Get_with_filter_props()
// { {
// // arrange // arrange
// Guid idDiscriminator = Guid.NewGuid(); Guid idDiscriminator = Guid.NewGuid();
// int count = 10; int count = 10;
// IEnumerable<TimestampedSetDto> testSets = Generate(count, DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(7))); IEnumerable<TimestampedSetDto> testSets = Generate(count, DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(7)));
// await client.AddRange(idDiscriminator, testSets, CancellationToken.None); await client.AddRange(idDiscriminator, testSets, CancellationToken.None);
// string[] props = ["A"]; string[] props = ["A"];
// // act // act
// var response = await client.Get(idDiscriminator, null, props, 0, int.MaxValue, new CancellationToken()); var response = await client.Get(idDiscriminator, null, props, 0, int.MaxValue, new CancellationToken());
// // assert // assert
// Assert.NotNull(response); Assert.NotNull(response);
// Assert.Equal(count, response.Count()); Assert.Equal(count, response.Count());
// foreach (var item in response) foreach (var item in response)
// { {
// Assert.Single(item.Set); Assert.Single(item.Set);
// var kv = item.Set.First(); var kv = item.Set.First();
// Assert.Equal("A", kv.Key); Assert.Equal("A", kv.Key);
// } }
// } }
// [Fact] [Fact]
// public async Task Get_geDate() public async Task Get_geDate()
// { {
// // arrange // arrange
// Guid idDiscriminator = Guid.NewGuid(); Guid idDiscriminator = Guid.NewGuid();
// int count = 10; int count = 10;
// var dateMin = DateTimeOffset.Now; var dateMin = DateTimeOffset.Now;
// var dateMax = DateTimeOffset.Now.AddSeconds(count); var dateMax = DateTimeOffset.Now.AddSeconds(count);
// IEnumerable<TimestampedSetDto> testSets = Generate(count, dateMin.ToOffset(TimeSpan.FromHours(7))); IEnumerable<TimestampedSetDto> testSets = Generate(count, dateMin.ToOffset(TimeSpan.FromHours(7)));
// var insertResponse = await client.AddRange(idDiscriminator, testSets, CancellationToken.None); var insertResponse = await client.AddRange(idDiscriminator, testSets, CancellationToken.None);
// var tail = testSets.OrderBy(t => t.Timestamp).Skip(count / 2).Take(int.MaxValue); var tail = testSets.OrderBy(t => t.Timestamp).Skip(count / 2).Take(int.MaxValue);
// var geDate = tail.First().Timestamp; var geDate = tail.First().Timestamp;
// var tolerance = TimeSpan.FromSeconds(1); var tolerance = TimeSpan.FromSeconds(1);
// var expectedCount = tail.Count(); var expectedCount = tail.Count();
// // act // act
// var response = await client.Get(idDiscriminator, geDate, null, 0, int.MaxValue, CancellationToken.None); var response = await client.Get(idDiscriminator, geDate, null, 0, int.MaxValue, CancellationToken.None);
// // assert // assert
// Assert.NotNull(response); Assert.NotNull(response);
// Assert.Equal(expectedCount, response.Count()); Assert.Equal(expectedCount, response.Count());
// var minDate = response.Min(t => t.Timestamp); var minDate = response.Min(t => t.Timestamp);
// Assert.Equal(geDate, geDate, tolerance); Assert.Equal(geDate, geDate, tolerance);
// } }
// [Fact] [Fact]
// public async Task Get_with_skip_take() public async Task Get_with_skip_take()
// { {
// // arrange // arrange
// Guid idDiscriminator = Guid.NewGuid(); Guid idDiscriminator = Guid.NewGuid();
// int count = 10; int count = 10;
// IEnumerable<TimestampedSetDto> testSets = Generate(count, DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(7))); IEnumerable<TimestampedSetDto> testSets = Generate(count, DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(7)));
// await client.AddRange(idDiscriminator, testSets, CancellationToken.None); await client.AddRange(idDiscriminator, testSets, CancellationToken.None);
// var expectedCount = count / 2; var expectedCount = count / 2;
// // act // act
// var response = await client.Get(idDiscriminator, null, null, 2, expectedCount, new CancellationToken()); var response = await client.Get(idDiscriminator, null, null, 2, expectedCount, new CancellationToken());
// // assert // assert
// Assert.NotNull(response); Assert.NotNull(response);
// Assert.Equal(expectedCount, response.Count()); Assert.Equal(expectedCount, response.Count());
// } }
// [Fact] [Fact]
// public async Task Get_with_big_skip_take() public async Task Get_with_big_skip_take()
// { {
// // arrange // arrange
// Guid idDiscriminator = Guid.NewGuid(); Guid idDiscriminator = Guid.NewGuid();
// var expectedCount = 1; var expectedCount = 1;
// int count = 10 + expectedCount; int count = 10 + expectedCount;
// IEnumerable<TimestampedSetDto> testSets = Generate(count, DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(7))); IEnumerable<TimestampedSetDto> testSets = Generate(count, DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(7)));
// await client.AddRange(idDiscriminator, testSets, CancellationToken.None); await client.AddRange(idDiscriminator, testSets, CancellationToken.None);
// // act // act
// var response = await client.Get(idDiscriminator, null, null, count - expectedCount, count, new CancellationToken()); var response = await client.Get(idDiscriminator, null, null, count - expectedCount, count, new CancellationToken());
// // assert // assert
// Assert.NotNull(response); Assert.NotNull(response);
// Assert.Equal(expectedCount, response.Count()); Assert.Equal(expectedCount, response.Count());
// } }
// [Fact] [Fact]
// public async Task GetLast() public async Task GetLast()
// { {
// // arrange // arrange
// Guid idDiscriminator = Guid.NewGuid(); Guid idDiscriminator = Guid.NewGuid();
// int count = 10; int count = 10;
// IEnumerable<TimestampedSetDto> testSets = Generate(count, DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(7))); IEnumerable<TimestampedSetDto> testSets = Generate(count, DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(7)));
// await client.AddRange(idDiscriminator, testSets, CancellationToken.None); await client.AddRange(idDiscriminator, testSets, CancellationToken.None);
// var expectedCount = 8; var expectedCount = 8;
// // act // act
// var response = await client.GetLast(idDiscriminator, null, expectedCount, new CancellationToken()); var response = await client.GetLast(idDiscriminator, null, expectedCount, new CancellationToken());
// // assert // assert
// Assert.NotNull(response); Assert.NotNull(response);
// Assert.Equal(expectedCount, response.Count()); Assert.Equal(expectedCount, response.Count());
// } }
// [Fact] [Fact]
// public async Task GetDatesRange() public async Task GetDatesRange()
// { {
// // arrange // arrange
// Guid idDiscriminator = Guid.NewGuid(); Guid idDiscriminator = Guid.NewGuid();
// int count = 10; int count = 10;
// var dateMin = DateTimeOffset.Now; var dateMin = DateTimeOffset.Now;
// var dateMax = DateTimeOffset.Now.AddSeconds(count - 1); var dateMax = DateTimeOffset.Now.AddSeconds(count - 1);
// IEnumerable<TimestampedSetDto> testSets = Generate(count, dateMin.ToOffset(TimeSpan.FromHours(7))); IEnumerable<TimestampedSetDto> testSets = Generate(count, dateMin.ToOffset(TimeSpan.FromHours(7)));
// await client.AddRange(idDiscriminator, testSets, CancellationToken.None); await client.AddRange(idDiscriminator, testSets, CancellationToken.None);
// var tolerance = TimeSpan.FromSeconds(1); var tolerance = TimeSpan.FromSeconds(1);
// // act // act
// var response = await client.GetDatesRange(idDiscriminator, new CancellationToken()); var response = await client.GetDatesRange(idDiscriminator, new CancellationToken());
// // assert // assert
// Assert.NotNull(response); Assert.NotNull(response);
// Assert.Equal(dateMin, response.From, tolerance); Assert.Equal(dateMin, response.From, tolerance);
// Assert.Equal(dateMax, response.To, tolerance); Assert.Equal(dateMax, response.To, tolerance);
// } }
// [Fact] [Fact]
// public async Task Count() public async Task Count()
// { {
// // arrange // arrange
// Guid idDiscriminator = Guid.NewGuid(); Guid idDiscriminator = Guid.NewGuid();
// int count = 144; int count = 144;
// IEnumerable<TimestampedSetDto> testSets = Generate(count, DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(7))); IEnumerable<TimestampedSetDto> testSets = Generate(count, DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(7)));
// await client.AddRange(idDiscriminator, testSets, CancellationToken.None); await client.AddRange(idDiscriminator, testSets, CancellationToken.None);
// // act // act
// var response = await client.Count(idDiscriminator, new CancellationToken()); var response = await client.Count(idDiscriminator, new CancellationToken());
// // assert // assert
// Assert.Equal(count, response); Assert.Equal(count, response);
// } }
// private static IEnumerable<TimestampedSetDto> Generate(int n, DateTimeOffset from) private static IEnumerable<TimestampedSetDto> Generate(int n, DateTimeOffset from)
// { {
// for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
// yield return new TimestampedSetDto yield return new TimestampedSetDto
// ( (
// from.AddSeconds(i), from.AddSeconds(i),
// new Dictionary<string, object>{ new Dictionary<string, object>{
// {"A", i }, {"A", i },
// {"B", i * 1.1 }, {"B", i * 1.1 },
// {"C", $"Any{i}" }, {"C", $"Any{i}" },
// {"D", DateTimeOffset.Now}, {"D", DateTimeOffset.Now},
// } }
// ); );
// } }
//} }

View File

@ -1,234 +1,234 @@
//using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
//using DD.Persistence.Database.Entity; using DD.Persistence.Database.Entity;
//using DD.Persistence.Models; using DD.Persistence.Models;
//using System.Net; using System.Net;
//using Xunit; using Xunit;
//using DD.Persistence.Client.Clients.Interfaces; using DD.Persistence.Client.Clients.Interfaces;
//using DD.Persistence.Client; using DD.Persistence.Client;
//namespace DD.Persistence.IntegrationTests.Controllers; namespace DD.Persistence.IntegrationTests.Controllers;
//public class WitsDataControllerTest : BaseIntegrationTest public class WitsDataControllerTest : BaseIntegrationTest
//{ {
// private IWitsDataClient witsDataClient; private IWitsDataClient witsDataClient;
// public WitsDataControllerTest(WebAppFactoryFixture factory) : base(factory) public WitsDataControllerTest(WebAppFactoryFixture factory) : base(factory)
// { {
// var scope = factory.Services.CreateScope(); var scope = factory.Services.CreateScope();
// var persistenceClientFactory = scope.ServiceProvider var persistenceClientFactory = scope.ServiceProvider
// .GetRequiredService<PersistenceClientFactory>(); .GetRequiredService<PersistenceClientFactory>();
// witsDataClient = persistenceClientFactory.GetWitsDataClient(); witsDataClient = persistenceClientFactory.GetWitsDataClient();
// } }
// [Fact] [Fact]
// public async Task GetDatesRangeAsync_returns_success() public async Task GetDatesRangeAsync_returns_success()
// { {
// //arrange //arrange
// dbContext.CleanupDbSet<ParameterData>(); dbContext.CleanupDbSet<ParameterData>();
// var discriminatorId = Guid.NewGuid(); var discriminatorId = Guid.NewGuid();
// //act //act
// var response = await witsDataClient.GetDatesRangeAsync(discriminatorId, CancellationToken.None); var response = await witsDataClient.GetDatesRangeAsync(discriminatorId, CancellationToken.None);
// //assert //assert
// Assert.NotNull(response); Assert.NotNull(response);
// } }
// [Fact] [Fact]
// public async Task GetPart_returns_success() public async Task GetPart_returns_success()
// { {
// //arrange //arrange
// dbContext.CleanupDbSet<ParameterData>(); dbContext.CleanupDbSet<ParameterData>();
// var discriminatorId = Guid.NewGuid(); var discriminatorId = Guid.NewGuid();
// var dateBegin = DateTimeOffset.UtcNow; var dateBegin = DateTimeOffset.UtcNow;
// var take = 1; var take = 1;
// //act //act
// var response = await witsDataClient.GetPart(discriminatorId, dateBegin, take, CancellationToken.None); var response = await witsDataClient.GetPart(discriminatorId, dateBegin, take, CancellationToken.None);
// //assert //assert
// Assert.NotNull(response); Assert.NotNull(response);
// Assert.Empty(response); Assert.Empty(response);
// } }
// [Fact] [Fact]
// public async Task InsertRange_returns_success() public async Task InsertRange_returns_success()
// { {
// //arrange //arrange
// dbContext.CleanupDbSet<ParameterData>(); dbContext.CleanupDbSet<ParameterData>();
// //act //act
// await AddRange(); await AddRange();
// } }
// [Fact] [Fact]
// public async Task GetValuesForGraph_returns_success() public async Task GetValuesForGraph_returns_success()
// { {
// //arrange //arrange
// dbContext.CleanupDbSet<ParameterData>(); dbContext.CleanupDbSet<ParameterData>();
// var discriminatorId = Guid.NewGuid(); var discriminatorId = Guid.NewGuid();
// var dateFrom = DateTimeOffset.UtcNow; var dateFrom = DateTimeOffset.UtcNow;
// var dateTo = DateTimeOffset.UtcNow; var dateTo = DateTimeOffset.UtcNow;
// var approxPointCount = 12; var approxPointCount = 12;
// //act //act
// var response = await witsDataClient.GetValuesForGraph(discriminatorId, dateFrom, dateTo, approxPointCount, CancellationToken.None); var response = await witsDataClient.GetValuesForGraph(discriminatorId, dateFrom, dateTo, approxPointCount, CancellationToken.None);
// //assert //assert
// Assert.NotNull(response); Assert.NotNull(response);
// Assert.Empty(response); Assert.Empty(response);
// } }
// [Fact] [Fact]
// public async Task GetDatesRangeAsync_AfterSave_returns_success() public async Task GetDatesRangeAsync_AfterSave_returns_success()
// { {
// //arrange //arrange
// dbContext.CleanupDbSet<ParameterData>(); dbContext.CleanupDbSet<ParameterData>();
// var dtos = await AddRange(); var dtos = await AddRange();
// var discriminatorId = dtos.FirstOrDefault()!.DiscriminatorId; var discriminatorId = dtos.FirstOrDefault()!.DiscriminatorId;
// //act //act
// var response = await witsDataClient.GetDatesRangeAsync(discriminatorId, CancellationToken.None); var response = await witsDataClient.GetDatesRangeAsync(discriminatorId, CancellationToken.None);
// //assert //assert
// Assert.NotNull(response); Assert.NotNull(response);
// var expectedDateFrom = dtos var expectedDateFrom = dtos
// .Select(e => e.Timestamped) .Select(e => e.Timestamped)
// .Min() .Min()
// .ToString("dd.MM.yyyy-HH:mm:ss"); .ToString("dd.MM.yyyy-HH:mm:ss");
// var actualDateFrom = response.From.DateTime var actualDateFrom = response.From.DateTime
// .ToString("dd.MM.yyyy-HH:mm:ss"); .ToString("dd.MM.yyyy-HH:mm:ss");
// Assert.Equal(expectedDateFrom, actualDateFrom); Assert.Equal(expectedDateFrom, actualDateFrom);
// var expectedDateTo = dtos var expectedDateTo = dtos
// .Select(e => e.Timestamped) .Select(e => e.Timestamped)
// .Max() .Max()
// .ToString("dd.MM.yyyy-HH:mm:ss"); .ToString("dd.MM.yyyy-HH:mm:ss");
// var actualDateTo = response.To.DateTime var actualDateTo = response.To.DateTime
// .ToString("dd.MM.yyyy-HH:mm:ss"); .ToString("dd.MM.yyyy-HH:mm:ss");
// Assert.Equal(expectedDateTo, actualDateTo); Assert.Equal(expectedDateTo, actualDateTo);
// } }
// [Fact] [Fact]
// public async Task GetPart_AfterSave_returns_success() public async Task GetPart_AfterSave_returns_success()
// { {
// //arrange //arrange
// dbContext.CleanupDbSet<ParameterData>(); dbContext.CleanupDbSet<ParameterData>();
// var dtos = await AddRange(); var dtos = await AddRange();
// var discriminatorId = dtos.FirstOrDefault()!.DiscriminatorId; var discriminatorId = dtos.FirstOrDefault()!.DiscriminatorId;
// var dateBegin = dtos.FirstOrDefault()!.Timestamped; var dateBegin = dtos.FirstOrDefault()!.Timestamped;
// var take = 1; var take = 1;
// //act //act
// var response = await witsDataClient.GetPart(discriminatorId, dateBegin, take, CancellationToken.None); var response = await witsDataClient.GetPart(discriminatorId, dateBegin, take, CancellationToken.None);
// //assert //assert
// Assert.NotNull(response); Assert.NotNull(response);
// Assert.NotEmpty(response); Assert.NotEmpty(response);
// Assert.Equal(take, response.Count()); Assert.Equal(take, response.Count());
// var expectedDto = dtos.FirstOrDefault(); var expectedDto = dtos.FirstOrDefault();
// var actualDto = response.FirstOrDefault(); var actualDto = response.FirstOrDefault();
// Assert.Equal(expectedDto?.DiscriminatorId, actualDto?.DiscriminatorId); Assert.Equal(expectedDto?.DiscriminatorId, actualDto?.DiscriminatorId);
// var expectedValueDto = expectedDto?.Values.FirstOrDefault(); var expectedValueDto = expectedDto?.Values.FirstOrDefault();
// var actualValueDto = actualDto?.Values.FirstOrDefault(); var actualValueDto = actualDto?.Values.FirstOrDefault();
// Assert.Equal(expectedValueDto?.ItemId, actualValueDto?.ItemId); Assert.Equal(expectedValueDto?.ItemId, actualValueDto?.ItemId);
// Assert.Equal(expectedValueDto?.RecordId, actualValueDto?.RecordId); Assert.Equal(expectedValueDto?.RecordId, actualValueDto?.RecordId);
// } }
// [Fact] [Fact]
// public async Task GetValuesForGraph_AfterSave_returns_success() public async Task GetValuesForGraph_AfterSave_returns_success()
// { {
// //arrange //arrange
// dbContext.CleanupDbSet<ParameterData>(); dbContext.CleanupDbSet<ParameterData>();
// var dtos = await AddRange(37); var dtos = await AddRange(37);
// var discriminatorId = dtos.FirstOrDefault()!.DiscriminatorId; var discriminatorId = dtos.FirstOrDefault()!.DiscriminatorId;
// var dateFrom = dtos.Select(e => e.Timestamped).Min(); var dateFrom = dtos.Select(e => e.Timestamped).Min();
// var dateTo = dtos.Select(e => e.Timestamped).Max(); var dateTo = dtos.Select(e => e.Timestamped).Max();
// var approxPointCount = 12; var approxPointCount = 12;
// //act //act
// var response = await witsDataClient.GetValuesForGraph(discriminatorId, dateFrom, dateTo, approxPointCount, CancellationToken.None); var response = await witsDataClient.GetValuesForGraph(discriminatorId, dateFrom, dateTo, approxPointCount, CancellationToken.None);
// //assert //assert
// Assert.NotNull(response); Assert.NotNull(response);
// Assert.Equal(approxPointCount, response.Count()); Assert.Equal(approxPointCount, response.Count());
// } }
// [Fact] [Fact]
// public async Task AddRange_returns_BadRequest() public async Task AddRange_returns_BadRequest()
// { {
// //arrange //arrange
// const string exceptionMessage = "Ошибка валидации, формата или маршрутизации запроса"; const string exceptionMessage = "Ошибка валидации, формата или маршрутизации запроса";
// var dtos = new List<WitsDataDto>() var dtos = new List<WitsDataDto>()
// { {
// new WitsDataDto() new WitsDataDto()
// { {
// DiscriminatorId = Guid.NewGuid(), DiscriminatorId = Guid.NewGuid(),
// Timestamped = DateTimeOffset.UtcNow, Timestamped = DateTimeOffset.UtcNow,
// Values = new List<WitsValueDto>() Values = new List<WitsValueDto>()
// { {
// new WitsValueDto() new WitsValueDto()
// { {
// RecordId = -1, // < 0 RecordId = -1, // < 0
// ItemId = 101, // > 100 ItemId = 101, // > 100
// Value = string.Empty Value = string.Empty
// } }
// } }
// } }
// }; };
// try try
// { {
// //act //act
// var response = await witsDataClient.AddRange(dtos, CancellationToken.None); var response = await witsDataClient.AddRange(dtos, CancellationToken.None);
// } }
// catch (Exception ex) catch (Exception ex)
// { {
// //assert //assert
// Assert.Equal(exceptionMessage, ex.Message); Assert.Equal(exceptionMessage, ex.Message);
// } }
// } }
// private async Task<IEnumerable<WitsDataDto>> AddRange(int countToCreate = 10) private async Task<IEnumerable<WitsDataDto>> AddRange(int countToCreate = 10)
// { {
// var dtos = new List<WitsDataDto>(); var dtos = new List<WitsDataDto>();
// var discriminatorId = Guid.NewGuid(); var discriminatorId = Guid.NewGuid();
// var timestamped = DateTimeOffset.UtcNow; var timestamped = DateTimeOffset.UtcNow;
// for (var i = 0; i < countToCreate; i++) for (var i = 0; i < countToCreate; i++)
// { {
// var random = new Random(); var random = new Random();
// dtos.Add(new WitsDataDto() dtos.Add(new WitsDataDto()
// { {
// DiscriminatorId = discriminatorId, DiscriminatorId = discriminatorId,
// Timestamped = timestamped.AddSeconds(i), Timestamped = timestamped.AddSeconds(i),
// Values = new List<WitsValueDto>() Values = new List<WitsValueDto>()
// { {
// new WitsValueDto() new WitsValueDto()
// { {
// RecordId = i + 1, RecordId = i + 1,
// ItemId = i + 1, ItemId = i + 1,
// Value = random.Next(1, 100) Value = random.Next(1, 100)
// } }
// } }
// }); });
// } }
// //act //act
// var response = await witsDataClient.AddRange(dtos, CancellationToken.None); var response = await witsDataClient.AddRange(dtos, CancellationToken.None);
// //assert //assert
// var count = dtos.SelectMany(e => e.Values).Count(); var count = dtos.SelectMany(e => e.Values).Count();
// Assert.Equal(count, response); Assert.Equal(count, response);
// return dtos; return dtos;
// } }
//} }