forked from ddrilling/AsbCloudServer
Доработаны интеграционные тесты для DataSaubStat
This commit is contained in:
parent
163b9d55e1
commit
a7d7440a07
@ -1,10 +1,8 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Data.ProcessMapPlan;
|
|
||||||
using AsbCloudApp.Repositories;
|
using AsbCloudApp.Repositories;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using System.ComponentModel;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.IntegrationTests.Repository
|
namespace AsbCloudWebApi.IntegrationTests.Repository
|
||||||
@ -16,8 +14,8 @@ namespace AsbCloudWebApi.IntegrationTests.Repository
|
|||||||
new DataSaubStatDto()
|
new DataSaubStatDto()
|
||||||
{
|
{
|
||||||
IdTelemetry = 1,
|
IdTelemetry = 1,
|
||||||
DateEnd = DateTimeOffset.UtcNow.AddDays(-10),
|
DateEnd = new DateTimeOffset(2024, 1, 1, 20, 25, 0, TimeSpan.Zero),
|
||||||
DateStart = DateTimeOffset.UtcNow.AddDays(-11),
|
DateStart = new DateTimeOffset(2024, 1, 1, 20, 15, 0, TimeSpan.Zero),
|
||||||
AxialLoad = 10.0,
|
AxialLoad = 10.0,
|
||||||
AxialLoadLimitMax = 10.0,
|
AxialLoadLimitMax = 10.0,
|
||||||
AxialLoadSp = 10.0,
|
AxialLoadSp = 10.0,
|
||||||
@ -33,17 +31,17 @@ namespace AsbCloudWebApi.IntegrationTests.Repository
|
|||||||
Pressure = 10.0,
|
Pressure = 10.0,
|
||||||
PressureIdle = 10.0,
|
PressureIdle = 10.0,
|
||||||
PressureSp = 10.0,
|
PressureSp = 10.0,
|
||||||
RotorSpeed = 10.0,
|
RotorSpeed = 9.0,
|
||||||
RotorTorque = 10.0,
|
RotorTorque = 9.0,
|
||||||
RotorTorqueSp = 10.0,
|
RotorTorqueSp = 9.0,
|
||||||
RotorTorqueLimitMax = 10.0,
|
RotorTorqueLimitMax = 9.0,
|
||||||
Speed = 10.0
|
Speed = 10.0
|
||||||
},
|
},
|
||||||
new DataSaubStatDto()
|
new DataSaubStatDto()
|
||||||
{
|
{
|
||||||
IdTelemetry = 1,
|
IdTelemetry = 1,
|
||||||
DateEnd = DateTimeOffset.UtcNow.AddDays(-20),
|
DateEnd = new DateTimeOffset(2024, 2, 2, 20, 25, 0, TimeSpan.Zero),
|
||||||
DateStart = DateTimeOffset.UtcNow.AddDays(-21),
|
DateStart = new DateTimeOffset(2024, 2, 2, 20, 15, 0, TimeSpan.Zero),
|
||||||
AxialLoad = 10.0,
|
AxialLoad = 10.0,
|
||||||
AxialLoadLimitMax = 10.0,
|
AxialLoadLimitMax = 10.0,
|
||||||
AxialLoadSp = 10.0,
|
AxialLoadSp = 10.0,
|
||||||
@ -70,24 +68,24 @@ namespace AsbCloudWebApi.IntegrationTests.Repository
|
|||||||
{
|
{
|
||||||
Id = 2,
|
Id = 2,
|
||||||
IdParent = null,
|
IdParent = null,
|
||||||
Name = "Категория 2"
|
Name = "Категория 2"
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly IDataSaubStatRepository dataSaubStatRepository;
|
private readonly IDataSaubStatRepository dataSaubStatRepository;
|
||||||
|
|
||||||
public DataSaubStatRepositoryTest(WebAppFactoryFixture factory) : base(factory)
|
public DataSaubStatRepositoryTest(WebAppFactoryFixture factory) : base(factory)
|
||||||
{
|
{
|
||||||
var stats = dbContext.Set<DataSaubStat>();
|
var dbSet = dbContext.Set<DataSaubStat>();
|
||||||
var categories = dbContext.Set<WellOperationCategory>();
|
var categories = dbContext.Set<WellOperationCategory>();
|
||||||
|
|
||||||
categories.RemoveRange(categories);
|
categories.RemoveRange(categories);
|
||||||
stats.RemoveRange(stats);
|
dbSet.RemoveRange(dbSet);
|
||||||
dbContext.SaveChanges();
|
dbContext.SaveChanges();
|
||||||
|
|
||||||
categories.Add(category);
|
categories.Add(category);
|
||||||
|
|
||||||
var entities = statDtos.Select(stat => stat.Adapt<DataSaubStat>());
|
var entities = statDtos.Select(stat => stat.Adapt<DataSaubStat>());
|
||||||
stats.AddRange(entities);
|
dbSet.AddRange(entities);
|
||||||
dbContext.SaveChanges();
|
dbContext.SaveChanges();
|
||||||
|
|
||||||
dataSaubStatRepository = scope.ServiceProvider.GetRequiredService<IDataSaubStatRepository>();
|
dataSaubStatRepository = scope.ServiceProvider.GetRequiredService<IDataSaubStatRepository>();
|
||||||
@ -104,17 +102,39 @@ namespace AsbCloudWebApi.IntegrationTests.Repository
|
|||||||
var actual = result.Any() ? result.First().DateEnd : DateTimeOffset.UnixEpoch;
|
var actual = result.Any() ? result.First().DateEnd : DateTimeOffset.UnixEpoch;
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(expected.Ticks, actual.Ticks);
|
Assert.True((expected - actual).Ticks == 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task InsertRangeAsync_returns_success()
|
public async Task InsertRangeAsync_returns_success()
|
||||||
{
|
{
|
||||||
//act
|
//act
|
||||||
var result = await dataSaubStatRepository.InsertRangeAsync(statDtos, CancellationToken.None);
|
var dbSet = dbContext.Set<DataSaubStat>();
|
||||||
|
dbSet.RemoveRange(dbSet);
|
||||||
|
dbContext.SaveChanges();
|
||||||
|
|
||||||
|
var result = await dataSaubStatRepository.InsertRangeAsync(statDtos, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(statDtos.Length, result);
|
Assert.Equal(statDtos.Length, result);
|
||||||
|
|
||||||
|
var statDtosFromDb = dbSet.Select(stat => stat.Adapt<DataSaubStatDto>()).ToArray();
|
||||||
|
|
||||||
|
var excludedProps = new[] {
|
||||||
|
nameof(DataSaubStat.Telemetry),
|
||||||
|
nameof(DataSaubStat.Id),
|
||||||
|
nameof(DataSaubStat.OperationCategory)
|
||||||
|
};
|
||||||
|
foreach (var statDtoFromDb in statDtosFromDb)
|
||||||
|
{
|
||||||
|
var statDto = statDtos
|
||||||
|
.Where(stat => stat.DateStart == statDtoFromDb.DateStart)
|
||||||
|
.Where(stat => stat.DateEnd == statDtoFromDb.DateEnd)
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
MatchHelper.Match(statDtoFromDb, statDto, excludedProps);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user