Тесты для проверки

This commit is contained in:
Lyudmila Romanova 2022-06-16 11:03:49 +05:00 committed by ngfrolov
parent ae34d17ae1
commit 24026f8de8

View File

@ -17,9 +17,16 @@ namespace AsbCloudWebApi.Tests.ServicesTests
private readonly AsbCloudDbContext context; private readonly AsbCloudDbContext context;
private readonly CacheDb cacheDb; private readonly CacheDb cacheDb;
private readonly DetectedOperationService service; private readonly DetectedOperationService service;
#region Задача данных
private Deposit deposit = new Deposit { Id = 1, Caption = "Депозит 1" }; private Deposit deposit = new Deposit { Id = 1, Caption = "Депозит 1" };
private Cluster cluster = new Cluster { Id = 1, Caption = "Кластер 1", IdDeposit = 1, Timezone = new SimpleTimezone() }; private Cluster cluster = new Cluster { Id = 1, Caption = "Кластер 1", IdDeposit = 1, Timezone = new SimpleTimezone() };
private WellDto wellDto = new WellDto
{
Id = 1,
Caption = "Test well 1",
IdTelemetry = 1,
IdCluster = 1,
Timezone = new SimpleTimezoneDto { Hours = 5 }
};
private Well well = new Well private Well well = new Well
{ {
Id = 1, Id = 1,
@ -35,7 +42,8 @@ namespace AsbCloudWebApi.Tests.ServicesTests
Patronymic = "Тест", Patronymic = "Тест",
Surname = "Тестович" Surname = "Тестович"
}; };
private DetectedOperation do1 = new DetectedOperation private List<DetectedOperation> do1 = new List<DetectedOperation> {
new DetectedOperation
{ {
Id = 1, Id = 1,
IdCategory = 1, IdCategory = 1,
@ -43,14 +51,54 @@ namespace AsbCloudWebApi.Tests.ServicesTests
DateStart = DateTimeOffset.Parse("2022-05-16T10:00:00.286Z"), DateStart = DateTimeOffset.Parse("2022-05-16T10:00:00.286Z"),
DateEnd = DateTimeOffset.Parse("2022-05-16T18:00:00.286Z"), DateEnd = DateTimeOffset.Parse("2022-05-16T18:00:00.286Z"),
DepthStart = 100, DepthStart = 100,
Value = 50,
DepthEnd = 1000 DepthEnd = 1000
}; },
new DetectedOperation
{
Id = 2,
IdCategory = 1,
IdTelemetry = 1,
DateStart = DateTimeOffset.Parse("2022-05-16T10:00:00.286Z"),
DateEnd = DateTimeOffset.Parse("2022-05-16T18:00:00.286Z"),
DepthStart = 100,
Value = 10,
DepthEnd = 1000
}};
private Telemetry telemetry = new Telemetry private Telemetry telemetry = new Telemetry
{ {
Id = 1, Id = 1,
RemoteUid = Guid.NewGuid().ToString() RemoteUid = Guid.NewGuid().ToString()
}; };
#endregion private OperationValue ovd = new OperationValue
{
Id = 1,
StandardValue = 200,
TargetValue = 100,
DepthEnd = 300,
DepthStart = 100,
IdOperationCategory=1,
IdWell = 1
};
private List<Schedule> sch = new List<Schedule> { new Schedule
{
Id = 1,
IdDriller = 1,
IdWell = 1,
DrillStart = DateTimeOffset.Parse("2022-05-16T10:00:00.286Z"),
DrillEnd = DateTimeOffset.Parse("2022-05-16T18:00:00.286Z"),
ShiftStart = new TimeOnly(10, 00),
ShiftEnd = new TimeOnly(18, 00)
}, new Schedule
{
Id = 2,
IdDriller = 1,
IdWell = 1,
DrillStart = DateTimeOffset.Parse("2022-05-17T10:00:00.286Z"),
DrillEnd = DateTimeOffset.Parse("2022-05-17T18:00:00.286Z"),
ShiftStart = new TimeOnly(10, 00),
ShiftEnd = new TimeOnly(18, 00)
} };
public DetectedOperationServiceTest() public DetectedOperationServiceTest()
{ {
@ -62,13 +110,16 @@ namespace AsbCloudWebApi.Tests.ServicesTests
context.Clusters.Add(cluster); context.Clusters.Add(cluster);
context.Wells.Add(well); context.Wells.Add(well);
context.Drillers.Add(driller); context.Drillers.Add(driller);
context.DetectedOperations.Add(do1); context.DetectedOperations.AddRange(do1);
context.OperationValues.Add(ovd);
context.Schedule.AddRange(sch);
context.SaveChanges(); context.SaveChanges();
var timezone = new SimpleTimezoneDto { Hours = 5 }; var timezone = new SimpleTimezoneDto { Hours = 5 };
var wellServiceMock = new Mock<IWellService>(); var wellServiceMock = new Mock<IWellService>();
wellServiceMock.Setup(s => s.GetTimezone(It.IsAny<int>())).Returns(timezone); wellServiceMock.Setup(s => s.GetTimezone(It.IsAny<int>())).Returns(timezone);
wellServiceMock.Setup(s => s.GetAsync(It.IsAny<int>(),CancellationToken.None)).Returns(Task.Run(() => wellDto));
var operationValueService = new OperationValueService(context); var operationValueService = new OperationValueService(context);
var scheduleService = new ScheduleService(context, wellServiceMock.Object); var scheduleService = new ScheduleService(context, wellServiceMock.Object);
@ -84,9 +135,40 @@ namespace AsbCloudWebApi.Tests.ServicesTests
[Fact] [Fact]
public async Task Count_grouping_by_driller() public async Task Count_grouping_by_driller()
{ {
var count = 10;
var list = await service.GetAsync(1, null, CancellationToken.None); var list = await service.GetAsync(1, null, CancellationToken.None);
Assert.Equal(3, count); Assert.Equal(2, list.Stats.First().Count);
}
[Fact]
public async Task AvgVal_grouping_by_driller()
{
var list = await service.GetAsync(1, null, CancellationToken.None);
Assert.Equal(30, list.Stats.First().AverageValue);
}
[Fact]
public async Task AvgTargetVal_grouping_by_driller()
{
var list = await service.GetAsync(1, null, CancellationToken.None);
Assert.Equal(100, list.Stats.First().AverageTargetValue);
}
[Fact]
public async Task Loss_grouping_by_driller()
{
var list = await service.GetAsync(1, null, CancellationToken.None);
Assert.Equal(0, list.Stats.First().Loss);
}
[Fact]
public async Task Efficiency_grouping_by_driller()
{
var list = await service.GetAsync(1, null, CancellationToken.None);
Assert.Equal(100, list.Stats.First().Efficiency);
}
[Fact]
public async Task GroupCount_grouping_by_driller()
{
var list = await service.GetAsync(1, null, CancellationToken.None);
Assert.Equal(1, list.Stats.Count());
} }
} }