Правки по результатам ревью

This commit is contained in:
Olga Nemt 2024-02-06 11:44:29 +05:00
parent a7d7440a07
commit deca1bf35b
4 changed files with 24 additions and 26 deletions

View File

@ -11,12 +11,12 @@ namespace AsbCloudApp.Repositories
public interface IDataSaubStatRepository
{
/// <summary>
/// Получение последних дат по телеметриям
/// Получение последних по дате окончания бурения записей в разрезе телеметрий
/// </summary>
/// <param name="idTelemetries">ключи телеметрий</param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<DataSaubStatDto>> GetLastDatesAsync(int[] idTelemetries, CancellationToken token);
Task<IEnumerable<DataSaubStatDto>> GetLastsAsync(int[] idTelemetries, CancellationToken token);
/// <summary>
/// Вставка записей статистики

View File

@ -43,7 +43,7 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
return;
var dataSaubStatRepo = services.GetRequiredService<IDataSaubStatRepository>();
var stats = await dataSaubStatRepo.GetLastDatesAsync(idTelemetries, token);
var stats = await dataSaubStatRepo.GetLastsAsync(idTelemetries, token);
for( var i =0; i < idTelemetries.Length; i++)
{

View File

@ -20,15 +20,11 @@ namespace AsbCloudInfrastructure.Repository
db = dbContext;
}
public async Task<IEnumerable<DataSaubStatDto>> GetLastDatesAsync(int[] idTelemetries, CancellationToken token)
public async Task<IEnumerable<DataSaubStatDto>> GetLastsAsync(int[] idTelemetries, CancellationToken token)
{
var stats = await db.Set<DataSaubStat>()
.Where(s => idTelemetries.Contains(s.IdTelemetry))
.GroupBy(s => s.IdTelemetry, (key, group) => new DataSaubStatDto()
{
IdTelemetry = key,
DateEnd = group.Max(s => s.DateEnd)
})
.GroupBy(s => s.IdTelemetry, (key, group) => group.OrderByDescending(el => el.DateEnd).First().Adapt<DataSaubStatDto>())
.ToArrayAsync(token);
return stats;

View File

@ -75,31 +75,30 @@ namespace AsbCloudWebApi.IntegrationTests.Repository
public DataSaubStatRepositoryTest(WebAppFactoryFixture factory) : base(factory)
{
var dbSet = dbContext.Set<DataSaubStat>();
var categories = dbContext.Set<WellOperationCategory>();
categories.RemoveRange(categories);
dbSet.RemoveRange(dbSet);
dbContext.SaveChanges();
categories.Add(category);
var entities = statDtos.Select(stat => stat.Adapt<DataSaubStat>());
dbSet.AddRange(entities);
dbContext.SaveChanges();
dataSaubStatRepository = scope.ServiceProvider.GetRequiredService<IDataSaubStatRepository>();
}
[Fact]
public async Task GetLastDatesAsync_returns_success()
{
//prepare
dbContext.CleanupDbSet<DataSaubStat>();
var dbSetSaubStat = dbContext.Set<DataSaubStat>();
var dbSetCategories = dbContext.Set<WellOperationCategory>();
var entities = statDtos.Select(stat => stat.Adapt<DataSaubStat>());
dbSetCategories.Add(category);
dbSetSaubStat.AddRange(entities);
dbContext.SaveChanges();
//act
var telemetryIds = statDtos.Select(stat => stat.IdTelemetry).ToArray();
var result = await dataSaubStatRepository.GetLastDatesAsync(telemetryIds, CancellationToken.None);
var result = await dataSaubStatRepository.GetLastsAsync(telemetryIds, CancellationToken.None);
var expected = statDtos.Max(stat => stat.DateEnd);
var actual = result.Any() ? result.First().DateEnd : DateTimeOffset.UnixEpoch;
var actual = result.First().DateEnd;
//assert
Assert.True((expected - actual).Ticks == 0.0);
@ -108,6 +107,9 @@ namespace AsbCloudWebApi.IntegrationTests.Repository
[Fact]
public async Task InsertRangeAsync_returns_success()
{
//prepare
dbContext.CleanupDbSet<DataSaubStat>();
//act
var dbSet = dbContext.Set<DataSaubStat>();
dbSet.RemoveRange(dbSet);