Поправлены юнит-тесты для плановой траектории

This commit is contained in:
Olga Nemt 2023-05-10 11:31:40 +05:00
parent 83fcf738b9
commit e1228ef6bf

View File

@ -1,4 +1,5 @@
using AsbCloudApp.Data; using AsbCloudApp.Data;
using AsbCloudApp.Data.WITS;
using AsbCloudApp.Repositories; using AsbCloudApp.Repositories;
using AsbCloudInfrastructure.Services; using AsbCloudInfrastructure.Services;
using AsbCloudInfrastructure.Services.Trajectory; using AsbCloudInfrastructure.Services.Trajectory;
@ -24,6 +25,16 @@ namespace AsbCloudWebApi.Tests.ServicesTests
return mock; return mock;
} }
private Mock<IFactualTrajectoryRepository> MakeFactualTrajectoryRepositoryMock(IEnumerable<Record7Dto> dateForGetMethod)
{
var mock = new Mock<IFactualTrajectoryRepository>();
mock.Setup(r => r.GetAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
.Returns(Task.FromResult(dateForGetMethod));
return mock;
}
[Fact] [Fact]
public async Task GetTrajectoryAsync_SameCounts() public async Task GetTrajectoryAsync_SameCounts()
{ {
@ -37,11 +48,19 @@ namespace AsbCloudWebApi.Tests.ServicesTests
new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 50d}, new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 50d},
}; };
var mock = MakePlannedTrajectoryRepositoryMock(plannedTrajectory); var actualTrajectory = new Record7Dto[]
//var service = new TrajectoryVisualizationService(mock.Object); {
//ar result = await service.GetTrajectoryAsync(1, CancellationToken.None); new() { Svyazc = 0, Svyinc = 0, Deptsvym = 0},
new() { Svyazc = 30, Svyinc = 30, Deptsvym = 10},
new() { Svyazc = 0, Svyinc = 0, Deptsvym = 20},
};
//Assert.Equal(plannedTrajectory.Length, result.Count()); var mockPlan = MakePlannedTrajectoryRepositoryMock(plannedTrajectory);
var mockFact = MakeFactualTrajectoryRepositoryMock(actualTrajectory);
var service = new TrajectoryVisualizationService(mockPlan.Object, mockFact.Object);
var result = await service.GetTrajectoryAsync(1, CancellationToken.None);
Assert.Equal(plannedTrajectory.Length, result.Plan?.Count());
Assert.Equal(actualTrajectory.Length, result.Fact?.Count());
} }
[Fact] [Fact]
@ -57,14 +76,23 @@ namespace AsbCloudWebApi.Tests.ServicesTests
new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 50d}, new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 50d},
}; };
var mock = MakePlannedTrajectoryRepositoryMock(plannedTrajectory); var factualTrajectory = new Record7Dto[]
//var service = new TrajectoryVisualizationService(mock.Object); {
//var result = await service.GetTrajectoryAsync(1, CancellationToken.None); new() { Svyazc = 0, Svyinc = 0, Deptsvym = 0},
//var lastPoint = result.Last(); new() { Svyazc = 30, Svyinc = 30, Deptsvym = 10},
new() { Svyazc = 0, Svyinc = 0, Deptsvym = 20},
};
//Assert.Equal(0d, lastPoint.X, 0.1d); var mockPlan = MakePlannedTrajectoryRepositoryMock(plannedTrajectory);
//Assert.Equal(0d, lastPoint.Y, 0.1d); var mockFact = MakeFactualTrajectoryRepositoryMock(factualTrajectory);
//Assert.Equal(50d, lastPoint.Z, 0.1d); var service = new TrajectoryVisualizationService(mockPlan.Object, mockFact.Object);
var result = await service.GetTrajectoryAsync(1, CancellationToken.None);
var lastPointPlan = result.Plan!.Last();
var lastPointFact = result.Fact!.Last();
Assert.Equal(0d, lastPointPlan.X, 0.1d);
Assert.Equal(0d, lastPointPlan.Y, 0.1d);
Assert.Equal(50d, lastPointPlan.Z, 0.1d);
} }
[Fact] [Fact]
@ -77,15 +105,23 @@ namespace AsbCloudWebApi.Tests.ServicesTests
new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 20d}, new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 20d},
}; };
var mock = MakePlannedTrajectoryRepositoryMock(plannedTrajectory); var factualTrajectory = new Record7Dto[]
//var service = new TrajectoryVisualizationService(mock.Object); {
//var result = await service.GetTrajectoryAsync(1, CancellationToken.None); new() { Svyazc = 0, Svyinc = 0, Deptsvym = 0},
//var lastPoint = result.Last(); new() { Svyazc = 30, Svyinc = 30, Deptsvym = 10},
//var tolerance = 0.001d; new() { Svyazc = 0, Svyinc = 0, Deptsvym = 20},
};
//Assert.InRange(lastPoint.Z, 10 + tolerance, 20 - tolerance); var mockPlanned = MakePlannedTrajectoryRepositoryMock(plannedTrajectory);
//Assert.InRange(lastPoint.Y, 0 + tolerance, 10 - tolerance); var mockFactual = MakeFactualTrajectoryRepositoryMock(factualTrajectory);
//Assert.InRange(lastPoint.X, 0 + tolerance, 10 - tolerance); var service = new TrajectoryVisualizationService(mockPlanned.Object, mockFactual.Object);
var result = await service.GetTrajectoryAsync(1, CancellationToken.None);
var lastPointPlan = result.Plan!.Last();
var tolerancePlan = 0.001d;
Assert.InRange(lastPointPlan.Z, 10 + tolerancePlan, 20 - tolerancePlan);
Assert.InRange(lastPointPlan.Y, 0 + tolerancePlan, 10 - tolerancePlan);
Assert.InRange(lastPointPlan.X, 0 + tolerancePlan, 10 - tolerancePlan);
} }
} }
} }