DD.WellWorkover.Cloud/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs
Степанов Дмитрий Александрович 29c425d376 Исправил unit тесты
Исправил сравнения у тестов траекторий
2023-07-03 12:13:13 +05:00

130 lines
6.7 KiB
C#

using AsbCloudApp.Data;
using AsbCloudApp.Repositories;
using AsbCloudInfrastructure.Services.Trajectory;
using Moq;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
namespace AsbCloudWebApi.Tests.ServicesTests
{
public class TrajectoryVisualizationServiceTest
{
private Mock<T> MakeTrajectoryRepositoryMock<T, V>(IEnumerable<V> dateForGetMethod)
where V : TrajectoryGeoDto
where T : class, ITrajectoryRepository<V>
{
var mock = new Mock<T>();
mock.Setup(r => r.GetAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
.Returns(Task.FromResult(dateForGetMethod));
return mock;
}
[Fact]
public async Task GetTrajectoryAsync_SameCounts()
{
var plannedTrajectory = new TrajectoryGeoPlanDto[]
{
new TrajectoryGeoPlanDto() { WellboreDepth = 0d, ZenithAngle = 0d, AzimuthGeo = 0d },
new TrajectoryGeoPlanDto() { WellboreDepth = 0d, ZenithAngle = 0d, AzimuthGeo = 10d },
new TrajectoryGeoPlanDto() { WellboreDepth = 0d, ZenithAngle = 30d, AzimuthGeo = 20d },
new TrajectoryGeoPlanDto() { WellboreDepth = 30d, ZenithAngle = 0d, AzimuthGeo = 30d },
new TrajectoryGeoPlanDto() { WellboreDepth = 30d, ZenithAngle = 90d, AzimuthGeo = 40d },
new TrajectoryGeoPlanDto() { WellboreDepth = 0d, ZenithAngle = 0d, AzimuthGeo = 50d },
};
var actualTrajectory = new TrajectoryGeoFactDto[]
{
new TrajectoryGeoFactDto() { WellboreDepth = 0, ZenithAngle = 0, AzimuthGeo = 0 },
new TrajectoryGeoFactDto() { WellboreDepth = 30, ZenithAngle = 30, AzimuthGeo = 10 },
new TrajectoryGeoFactDto() { WellboreDepth = 0, ZenithAngle = 0, AzimuthGeo = 20 },
};
var mockPlan = MakeTrajectoryRepositoryMock<ITrajectoryPlanRepository, TrajectoryGeoPlanDto>(plannedTrajectory);
var mockFact = MakeTrajectoryRepositoryMock<ITrajectoryFactRepository, TrajectoryGeoFactDto>(actualTrajectory);
var service = new TrajectoryService(mockPlan.Object, mockFact.Object);
var result = await service.GetTrajectoryCartesianAsync(1, CancellationToken.None);
Assert.Equal(plannedTrajectory.Length, result.Plan?.Count());
Assert.Equal(actualTrajectory.Length, result.Fact?.Count());
}
[Fact]
public async Task GetTrajectoryAsync_StraightBore()
{
var plannedTrajectory = new TrajectoryGeoPlanDto[]
{
new TrajectoryGeoPlanDto() { WellboreDepth = 0, ZenithAngle = 0, AzimuthGeo = 0 },
new TrajectoryGeoPlanDto() { WellboreDepth = 0, ZenithAngle = 0, AzimuthGeo = 0 },
new TrajectoryGeoPlanDto() { WellboreDepth = 20, ZenithAngle = 0, AzimuthGeo = 0 },
new TrajectoryGeoPlanDto() { WellboreDepth = 20, ZenithAngle = 0, AzimuthGeo = 0 },
new TrajectoryGeoPlanDto() { WellboreDepth = 30, ZenithAngle = 0, AzimuthGeo = 0 },
new TrajectoryGeoPlanDto() { WellboreDepth = 50, ZenithAngle = 0, AzimuthGeo = 0 },
};
var actualTrajectory = new TrajectoryGeoFactDto[]
{
new TrajectoryGeoFactDto() { WellboreDepth = 0, ZenithAngle = 0, AzimuthGeo = 0 },
new TrajectoryGeoFactDto() { WellboreDepth = 0, ZenithAngle = 0, AzimuthGeo = 0 },
new TrajectoryGeoFactDto() { WellboreDepth = 20, ZenithAngle = 0, AzimuthGeo = 0 },
new TrajectoryGeoFactDto() { WellboreDepth = 20, ZenithAngle = 0, AzimuthGeo = 0 },
new TrajectoryGeoFactDto() { WellboreDepth = 30, ZenithAngle = 0, AzimuthGeo = 0 },
new TrajectoryGeoFactDto() { WellboreDepth = 50, ZenithAngle = 0, AzimuthGeo = 0 },
};
var mockPlan = MakeTrajectoryRepositoryMock<ITrajectoryPlanRepository, TrajectoryGeoPlanDto>(plannedTrajectory);
var mockFact = MakeTrajectoryRepositoryMock<ITrajectoryFactRepository, TrajectoryGeoFactDto>(actualTrajectory);
var service = new TrajectoryService(mockPlan.Object, mockFact.Object);
var result = await service.GetTrajectoryCartesianAsync(1, CancellationToken.None);
var lastPointPlan = result.Plan!.Last();
var lastPointFact = result.Fact!.Last();
Assert.Equal(0d, lastPointPlan.X, 0.1d);
Assert.Equal(-50d, lastPointPlan.Y, 0.1d);
Assert.Equal(0d, lastPointPlan.Z, 0.1d);
Assert.Equal(0d, lastPointFact.X, 0.1d);
Assert.Equal(-50d, lastPointFact.Y, 0.1d);
Assert.Equal(0d, lastPointFact.Z, 0.1d);
}
[Fact]
public async Task GetTrajectoryAsync_Match()
{
var plannedTrajectory = new TrajectoryGeoPlanDto[]
{
new TrajectoryGeoPlanDto() { WellboreDepth = 0, ZenithAngle = 0, AzimuthGeo = 0 },
new TrajectoryGeoPlanDto() { WellboreDepth = 10, ZenithAngle = 30, AzimuthGeo = 30 },
new TrajectoryGeoPlanDto() { WellboreDepth = 20, ZenithAngle = 0, AzimuthGeo = 0 },
};
var actualTrajectory = new TrajectoryGeoFactDto[]
{
new TrajectoryGeoFactDto() { WellboreDepth = 0, ZenithAngle = 0, AzimuthGeo = 0 },
new TrajectoryGeoFactDto() { WellboreDepth = 10, ZenithAngle = 30, AzimuthGeo = 30 },
new TrajectoryGeoFactDto() { WellboreDepth = 20, ZenithAngle = 0, AzimuthGeo = 0 },
};
var mockPlanned = MakeTrajectoryRepositoryMock<ITrajectoryPlanRepository, TrajectoryGeoPlanDto>(plannedTrajectory);
var mockFactual = MakeTrajectoryRepositoryMock<ITrajectoryFactRepository, TrajectoryGeoFactDto>(actualTrajectory);
var service = new TrajectoryService(mockPlanned.Object, mockFactual.Object);
var result = await service.GetTrajectoryCartesianAsync(1, CancellationToken.None);
var lastPointPlan = result.Plan!.Last();
var lastPointFact = result.Fact!.Last();
var tolerancePlan = 0.001d;
var toleranceFact = 0.001d;
Assert.InRange(lastPointPlan.Z, -10 - tolerancePlan, 0 - tolerancePlan);
Assert.InRange(lastPointPlan.Y, -20 - tolerancePlan, -10 + tolerancePlan);
Assert.InRange(lastPointPlan.X, 0 + tolerancePlan, 10 - tolerancePlan);
Assert.InRange(lastPointFact.Z, -10 - toleranceFact, 0 - toleranceFact);
Assert.InRange(lastPointFact.Y, -20 - toleranceFact, -10 + toleranceFact);
Assert.InRange(lastPointFact.X, 0 + toleranceFact, 10 - toleranceFact);
}
}
}