2023-02-15 13:35:18 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
2023-05-10 11:31:40 +05:00
|
|
|
|
using AsbCloudApp.Data.WITS;
|
2023-02-15 13:35:18 +05:00
|
|
|
|
using AsbCloudApp.Repositories;
|
2023-02-21 10:19:07 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services.Trajectory;
|
2023-02-15 13:35:18 +05:00
|
|
|
|
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
|
|
|
|
|
{
|
2023-05-11 15:36:49 +05:00
|
|
|
|
private Mock<T> MakeTrajectoryRepositoryMock<T>(TrajectoryDto[] dateForGetMethod)
|
|
|
|
|
where T : class, ITrajectoryRepository
|
2023-02-15 13:35:18 +05:00
|
|
|
|
{
|
2023-05-11 15:36:49 +05:00
|
|
|
|
var mock = new Mock<T>();
|
2023-02-15 13:35:18 +05:00
|
|
|
|
|
2023-05-11 15:36:49 +05:00
|
|
|
|
mock.Setup(r => r.GetTrajectoryAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
2023-05-10 11:31:40 +05:00
|
|
|
|
.Returns(Task.FromResult(dateForGetMethod));
|
|
|
|
|
|
|
|
|
|
return mock;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-15 13:35:18 +05:00
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetTrajectoryAsync_SameCounts()
|
|
|
|
|
{
|
2023-05-11 15:36:49 +05:00
|
|
|
|
var plannedTrajectory = new TrajectoryDto[]
|
2023-02-15 13:35:18 +05:00
|
|
|
|
{
|
2023-05-11 15:36:49 +05:00
|
|
|
|
new(0d, 0d, 0d),
|
|
|
|
|
new(0d, 0d, 10d),
|
|
|
|
|
new(0d, 30d, 20d),
|
|
|
|
|
new(30d, 0d, 30d),
|
|
|
|
|
new(30d, 90d, 40d),
|
|
|
|
|
new(0d, 0d, 50d),
|
2023-02-15 13:35:18 +05:00
|
|
|
|
};
|
|
|
|
|
|
2023-05-11 15:36:49 +05:00
|
|
|
|
var actualTrajectory = new TrajectoryDto[]
|
2023-05-10 11:31:40 +05:00
|
|
|
|
{
|
2023-05-11 15:36:49 +05:00
|
|
|
|
new(0, 0, 0),
|
|
|
|
|
new(30,30,10),
|
|
|
|
|
new(0, 0, 20),
|
2023-05-10 11:31:40 +05:00
|
|
|
|
};
|
2023-02-15 13:35:18 +05:00
|
|
|
|
|
2023-05-11 15:36:49 +05:00
|
|
|
|
var mockPlan = MakeTrajectoryRepositoryMock<IPlannedTrajectoryRepository>(plannedTrajectory);
|
|
|
|
|
var mockFact = MakeTrajectoryRepositoryMock<IActualTrajectoryRepository>(actualTrajectory);
|
2023-05-10 11:31:40 +05:00
|
|
|
|
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());
|
2023-02-15 13:35:18 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetTrajectoryAsync_StraigthBore()
|
|
|
|
|
{
|
2023-05-11 15:36:49 +05:00
|
|
|
|
var plannedTrajectory = new TrajectoryDto[]
|
2023-02-15 13:35:18 +05:00
|
|
|
|
{
|
2023-05-11 15:36:49 +05:00
|
|
|
|
new(0, 0, 0),
|
|
|
|
|
new(0, 0, 0),
|
|
|
|
|
new(0, 0, 20),
|
|
|
|
|
new(0, 0, 20),
|
|
|
|
|
new(0, 0, 30),
|
|
|
|
|
new(0, 0, 50),
|
2023-02-15 13:35:18 +05:00
|
|
|
|
};
|
|
|
|
|
|
2023-05-11 15:36:49 +05:00
|
|
|
|
var factualTrajectory = new TrajectoryDto[]
|
2023-05-10 11:31:40 +05:00
|
|
|
|
{
|
2023-05-11 15:36:49 +05:00
|
|
|
|
new(0, 0, 0),
|
|
|
|
|
new(0, 0, 0),
|
|
|
|
|
new(0, 0, 20),
|
|
|
|
|
new(0, 0, 20),
|
|
|
|
|
new(0, 0, 30),
|
|
|
|
|
new(0, 0, 50),
|
2023-05-10 11:31:40 +05:00
|
|
|
|
};
|
|
|
|
|
|
2023-05-11 15:36:49 +05:00
|
|
|
|
var mockPlan = MakeTrajectoryRepositoryMock<IPlannedTrajectoryRepository>(plannedTrajectory);
|
|
|
|
|
var mockFact = MakeTrajectoryRepositoryMock<IActualTrajectoryRepository>(factualTrajectory);
|
2023-05-10 11:31:40 +05:00
|
|
|
|
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();
|
2023-02-15 13:35:18 +05:00
|
|
|
|
|
2023-05-10 11:31:40 +05:00
|
|
|
|
Assert.Equal(0d, lastPointPlan.X, 0.1d);
|
|
|
|
|
Assert.Equal(0d, lastPointPlan.Y, 0.1d);
|
|
|
|
|
Assert.Equal(50d, lastPointPlan.Z, 0.1d);
|
2023-05-10 15:05:05 +05:00
|
|
|
|
|
|
|
|
|
Assert.Equal(0d, lastPointFact.X, 0.1d);
|
|
|
|
|
Assert.Equal(0d, lastPointFact.Y, 0.1d);
|
|
|
|
|
Assert.Equal(50d, lastPointFact.Z, 0.1d);
|
2023-02-15 13:35:18 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetTrajectoryAsync_Match()
|
|
|
|
|
{
|
2023-05-11 15:36:49 +05:00
|
|
|
|
var plannedTrajectory = new TrajectoryDto[]
|
2023-02-15 13:35:18 +05:00
|
|
|
|
{
|
2023-05-11 15:36:49 +05:00
|
|
|
|
new(0, 0, 0),
|
|
|
|
|
new(30, 30, 10),
|
|
|
|
|
new(0, 0, 20),
|
2023-02-15 13:35:18 +05:00
|
|
|
|
};
|
|
|
|
|
|
2023-05-11 15:36:49 +05:00
|
|
|
|
var factualTrajectory = new TrajectoryDto[]
|
2023-05-10 11:31:40 +05:00
|
|
|
|
{
|
2023-05-11 15:36:49 +05:00
|
|
|
|
new(0, 0, 0),
|
|
|
|
|
new(30, 30, 10),
|
|
|
|
|
new(0, 0, 20),
|
2023-05-10 11:31:40 +05:00
|
|
|
|
};
|
|
|
|
|
|
2023-05-11 15:36:49 +05:00
|
|
|
|
var mockPlanned = MakeTrajectoryRepositoryMock<IPlannedTrajectoryRepository>(plannedTrajectory);
|
|
|
|
|
var mockFactual = MakeTrajectoryRepositoryMock<IActualTrajectoryRepository>(factualTrajectory);
|
2023-05-10 11:31:40 +05:00
|
|
|
|
var service = new TrajectoryVisualizationService(mockPlanned.Object, mockFactual.Object);
|
|
|
|
|
var result = await service.GetTrajectoryAsync(1, CancellationToken.None);
|
|
|
|
|
var lastPointPlan = result.Plan!.Last();
|
2023-05-10 15:05:05 +05:00
|
|
|
|
var lastPointFact = result.Fact!.Last();
|
2023-05-10 11:31:40 +05:00
|
|
|
|
var tolerancePlan = 0.001d;
|
2023-05-10 15:05:05 +05:00
|
|
|
|
var toleranceFact = 0.001d;
|
2023-02-15 13:35:18 +05:00
|
|
|
|
|
2023-05-10 11:31:40 +05:00
|
|
|
|
Assert.InRange(lastPointPlan.Z, 10 + tolerancePlan, 20 - tolerancePlan);
|
|
|
|
|
Assert.InRange(lastPointPlan.Y, 0 + tolerancePlan, 10 - tolerancePlan);
|
|
|
|
|
Assert.InRange(lastPointPlan.X, 0 + tolerancePlan, 10 - tolerancePlan);
|
2023-05-10 15:05:05 +05:00
|
|
|
|
|
|
|
|
|
Assert.InRange(lastPointFact.Z, 10 + toleranceFact, 20 - toleranceFact);
|
|
|
|
|
Assert.InRange(lastPointFact.Y, 0 + toleranceFact, 10 - toleranceFact);
|
|
|
|
|
Assert.InRange(lastPointFact.X, 0 + toleranceFact, 10 - toleranceFact);
|
2023-02-15 13:35:18 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|