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 MakeTrajectoryRepositoryMock(IEnumerable dateForGetMethod) where V : TrajectoryGeoDto where T : class, ITrajectoryRepository { var mock = new Mock(); mock.Setup(r => r.GetAsync(It.IsAny(), It.IsAny())) .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(plannedTrajectory); var mockFact = MakeTrajectoryRepositoryMock(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(plannedTrajectory); var mockFact = MakeTrajectoryRepositoryMock(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(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 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(plannedTrajectory); var mockFactual = MakeTrajectoryRepositoryMock(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, 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); } } }