forked from ddrilling/AsbCloudServer
Добавлены функциональные тесты, удалены интеграционные (DataSaubStat)
This commit is contained in:
parent
1f80d37da9
commit
163b9d55e1
@ -0,0 +1,120 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.ProcessMapPlan;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudDb.Model;
|
||||
using Mapster;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.ComponentModel;
|
||||
using Xunit;
|
||||
|
||||
namespace AsbCloudWebApi.IntegrationTests.Repository
|
||||
{
|
||||
public class DataSaubStatRepositoryTest : BaseIntegrationTest
|
||||
{
|
||||
private static readonly DataSaubStatDto[] statDtos = new DataSaubStatDto[2]
|
||||
{
|
||||
new DataSaubStatDto()
|
||||
{
|
||||
IdTelemetry = 1,
|
||||
DateEnd = DateTimeOffset.UtcNow.AddDays(-10),
|
||||
DateStart = DateTimeOffset.UtcNow.AddDays(-11),
|
||||
AxialLoad = 10.0,
|
||||
AxialLoadLimitMax = 10.0,
|
||||
AxialLoadSp = 10.0,
|
||||
BlockSpeedSp = 1000,
|
||||
DepthEnd = 10.0,
|
||||
DepthStart = 5.0,
|
||||
EnabledSubsystems = 1,
|
||||
Flow = 10.0,
|
||||
HasOscillation = true,
|
||||
Id = default,
|
||||
IdCategory = 2,
|
||||
IdFeedRegulator = 1,
|
||||
Pressure = 10.0,
|
||||
PressureIdle = 10.0,
|
||||
PressureSp = 10.0,
|
||||
RotorSpeed = 10.0,
|
||||
RotorTorque = 10.0,
|
||||
RotorTorqueSp = 10.0,
|
||||
RotorTorqueLimitMax = 10.0,
|
||||
Speed = 10.0
|
||||
},
|
||||
new DataSaubStatDto()
|
||||
{
|
||||
IdTelemetry = 1,
|
||||
DateEnd = DateTimeOffset.UtcNow.AddDays(-20),
|
||||
DateStart = DateTimeOffset.UtcNow.AddDays(-21),
|
||||
AxialLoad = 10.0,
|
||||
AxialLoadLimitMax = 10.0,
|
||||
AxialLoadSp = 10.0,
|
||||
BlockSpeedSp = 1000,
|
||||
DepthEnd = 10.0,
|
||||
DepthStart = 5.0,
|
||||
EnabledSubsystems = 1,
|
||||
Flow = 10.0,
|
||||
HasOscillation = true,
|
||||
Id = default,
|
||||
IdCategory = 2,
|
||||
IdFeedRegulator = 1,
|
||||
Pressure = 10.0,
|
||||
PressureIdle = 10.0,
|
||||
PressureSp = 10.0,
|
||||
RotorSpeed = 10.0,
|
||||
RotorTorque = 10.0,
|
||||
RotorTorqueSp = 10.0,
|
||||
RotorTorqueLimitMax = 10.0,
|
||||
Speed = 10.0
|
||||
}
|
||||
};
|
||||
private static readonly WellOperationCategory category = new()
|
||||
{
|
||||
Id = 2,
|
||||
IdParent = null,
|
||||
Name = "Категория 2"
|
||||
};
|
||||
|
||||
private readonly IDataSaubStatRepository dataSaubStatRepository;
|
||||
|
||||
public DataSaubStatRepositoryTest(WebAppFactoryFixture factory) : base(factory)
|
||||
{
|
||||
var stats = dbContext.Set<DataSaubStat>();
|
||||
var categories = dbContext.Set<WellOperationCategory>();
|
||||
|
||||
categories.RemoveRange(categories);
|
||||
stats.RemoveRange(stats);
|
||||
dbContext.SaveChanges();
|
||||
|
||||
categories.Add(category);
|
||||
|
||||
var entities = statDtos.Select(stat => stat.Adapt<DataSaubStat>());
|
||||
stats.AddRange(entities);
|
||||
dbContext.SaveChanges();
|
||||
|
||||
dataSaubStatRepository = scope.ServiceProvider.GetRequiredService<IDataSaubStatRepository>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetLastDatesAsync_returns_success()
|
||||
{
|
||||
//act
|
||||
var telemetryIds = statDtos.Select(stat => stat.IdTelemetry).ToArray();
|
||||
var result = await dataSaubStatRepository.GetLastDatesAsync(telemetryIds, CancellationToken.None);
|
||||
|
||||
var expected = statDtos.Max(stat => stat.DateEnd);
|
||||
var actual = result.Any() ? result.First().DateEnd : DateTimeOffset.UnixEpoch;
|
||||
|
||||
//assert
|
||||
Assert.Equal(expected.Ticks, actual.Ticks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InsertRangeAsync_returns_success()
|
||||
{
|
||||
//act
|
||||
var result = await dataSaubStatRepository.InsertRangeAsync(statDtos, CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.Equal(statDtos.Length, result);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.ProcessMaps;
|
||||
using AsbCloudApp.Repositories;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace AsbCloudWebApi.Tests.Services.ProcessMaps;
|
||||
|
||||
public class DataSaubStatServiceTests
|
||||
{
|
||||
private readonly IEnumerable<DataSaubStatDto> stats = new DataSaubStatDto[]
|
||||
{
|
||||
new()
|
||||
{
|
||||
IdTelemetry = 1,
|
||||
DateEnd = DateTimeOffset.UtcNow.AddDays(-10),
|
||||
DateStart = DateTimeOffset.UtcNow.AddDays(-11),
|
||||
AxialLoad = 10.0,
|
||||
AxialLoadLimitMax = 10.0,
|
||||
AxialLoadSp = 10.0,
|
||||
BlockSpeedSp = 1000,
|
||||
DepthEnd = 10.0,
|
||||
DepthStart = 5.0,
|
||||
EnabledSubsystems = 1,
|
||||
Flow = 10.0,
|
||||
HasOscillation = true,
|
||||
Id = 1,
|
||||
IdCategory = 2,
|
||||
IdFeedRegulator = 1,
|
||||
Pressure = 10.0,
|
||||
PressureIdle = 10.0,
|
||||
PressureSp = 10.0,
|
||||
RotorSpeed = 10.0,
|
||||
RotorTorque = 10.0,
|
||||
RotorTorqueSp = 10.0,
|
||||
RotorTorqueLimitMax = 10.0,
|
||||
Speed = 10.0,
|
||||
Telemetry = new TelemetryDto(){
|
||||
Id = 1,
|
||||
},
|
||||
OperationCategory = new WellOperationCategoryDto(){
|
||||
Id = 2,
|
||||
}
|
||||
}
|
||||
};
|
||||
private readonly IDataSaubStatRepository dataSaubStatRepository;
|
||||
|
||||
public DataSaubStatServiceTests()
|
||||
{
|
||||
dataSaubStatRepository = Substitute.For<IDataSaubStatRepository>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAsync_ReturnsDataSaubStat()
|
||||
{
|
||||
dataSaubStatRepository.GetLastDatesAsync(Arg.Any<int[]>(), Arg.Any<CancellationToken>()).Returns(stats);
|
||||
Assert.Equal(2, stats.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InsertRangeAsync_Returns_statusOk()
|
||||
{
|
||||
var result = await dataSaubStatRepository.InsertRangeAsync(stats, Arg.Any<CancellationToken>());
|
||||
Assert.Equal(1, result);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user