DD.WellWorkover.Cloud/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs

130 lines
4.8 KiB
C#

using AsbCloudApp.Data;
using AsbCloudApp.Data.WITS;
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>(TrajectoryDto[] dateForGetMethod)
where T : class, ITrajectoryRepository
{
var mock = new Mock<T>();
mock.Setup(r => r.GetTrajectoryAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
.Returns(Task.FromResult(dateForGetMethod));
return mock;
}
[Fact]
public async Task GetTrajectoryAsync_SameCounts()
{
var plannedTrajectory = new TrajectoryDto[]
{
new(0d, 0d, 0d),
new(0d, 0d, 10d),
new(0d, 30d, 20d),
new(30d, 0d, 30d),
new(30d, 90d, 40d),
new(0d, 0d, 50d),
};
var actualTrajectory = new TrajectoryDto[]
{
new(0, 0, 0),
new(30,30,10),
new(0, 0, 20),
};
var mockPlan = MakeTrajectoryRepositoryMock<IPlannedTrajectoryRepository>(plannedTrajectory);
var mockFact = MakeTrajectoryRepositoryMock<IActualTrajectoryRepository>(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]
public async Task GetTrajectoryAsync_StraigthBore()
{
var plannedTrajectory = new TrajectoryDto[]
{
new(0, 0, 0),
new(0, 0, 0),
new(0, 0, 20),
new(0, 0, 20),
new(0, 0, 30),
new(0, 0, 50),
};
var factualTrajectory = new TrajectoryDto[]
{
new(0, 0, 0),
new(0, 0, 0),
new(0, 0, 20),
new(0, 0, 20),
new(0, 0, 30),
new(0, 0, 50),
};
var mockPlan = MakeTrajectoryRepositoryMock<IPlannedTrajectoryRepository>(plannedTrajectory);
var mockFact = MakeTrajectoryRepositoryMock<IActualTrajectoryRepository>(factualTrajectory);
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);
Assert.Equal(0d, lastPointFact.X, 0.1d);
Assert.Equal(0d, lastPointFact.Y, 0.1d);
Assert.Equal(50d, lastPointFact.Z, 0.1d);
}
[Fact]
public async Task GetTrajectoryAsync_Match()
{
var plannedTrajectory = new TrajectoryDto[]
{
new(0, 0, 0),
new(30, 30, 10),
new(0, 0, 20),
};
var factualTrajectory = new TrajectoryDto[]
{
new(0, 0, 0),
new(30, 30, 10),
new(0, 0, 20),
};
var mockPlanned = MakeTrajectoryRepositoryMock<IPlannedTrajectoryRepository>(plannedTrajectory);
var mockFactual = MakeTrajectoryRepositoryMock<IActualTrajectoryRepository>(factualTrajectory);
var service = new TrajectoryVisualizationService(mockPlanned.Object, mockFactual.Object);
var result = await service.GetTrajectoryAsync(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, 20 - tolerancePlan);
Assert.InRange(lastPointPlan.Y, 0 + tolerancePlan, 10 - tolerancePlan);
Assert.InRange(lastPointPlan.X, 0 + tolerancePlan, 10 - tolerancePlan);
Assert.InRange(lastPointFact.Z, 10 + toleranceFact, 20 - toleranceFact);
Assert.InRange(lastPointFact.Y, 0 + toleranceFact, 10 - toleranceFact);
Assert.InRange(lastPointFact.X, 0 + toleranceFact, 10 - toleranceFact);
}
}
}