From 2e59d97dcd7069e30eb29c3e5b8bc3c37b7f28c3 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Wed, 15 Feb 2023 13:35:18 +0500 Subject: [PATCH] Add test --- .../TrajectoryVisualizationServiceTest.cs | 104 ++++++++++++++++++ .../PlannedTrajectoryController.cs | 1 - 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs diff --git a/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs b/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs new file mode 100644 index 00000000..ab57843e --- /dev/null +++ b/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs @@ -0,0 +1,104 @@ +using AsbCloudApp.Data; +using AsbCloudApp.Repositories; +using AsbCloudInfrastructure.Services; +using Moq; +using System; +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 MakePlannedTrajectoryRepositoryMock(IEnumerable dateForGetMethod) + { + 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 PlannedTrajectoryDto[] + { + new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 0d}, + new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 10d}, + new() { AzimuthGeo = 0d, ZenithAngle = 30d, WellboreDepth = 20d}, + new() { AzimuthGeo = 30d, ZenithAngle = 0d, WellboreDepth = 30d}, + new() { AzimuthGeo = 30d, ZenithAngle = 90d, WellboreDepth = 40d}, + new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 50d}, + }; + + var mock = MakePlannedTrajectoryRepositoryMock(plannedTrajectory); + var service = new TrajectoryVisualizationService(mock.Object); + var result = await service.GetTrajectoryAsync(1, CancellationToken.None); + + Assert.Equal(plannedTrajectory.Length, result.Count()); + } + + [Fact] + public async Task GetTrajectoryAsync_StraigthBore() + { + var plannedTrajectory = new PlannedTrajectoryDto[] + { + new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 0d}, + new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 0d}, + new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 20d}, + new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 20d}, + new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 30d}, + new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 50d}, + }; + + var mock = MakePlannedTrajectoryRepositoryMock(plannedTrajectory); + var service = new TrajectoryVisualizationService(mock.Object); + var result = await service.GetTrajectoryAsync(1, CancellationToken.None); + var lastPoint = result.Last(); + + Assert.Equal(0d, lastPoint.X, 0.1d); + Assert.Equal(0d, lastPoint.Y, 0.1d); + Assert.Equal(50d, lastPoint.Z, 0.1d); + } + + + [Fact] + public async Task GetTrajectoryAsync_Match() + { + var plannedTrajectory = new PlannedTrajectoryDto[] + { + new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 0d}, + new() { AzimuthGeo = 30d, ZenithAngle = 30d, WellboreDepth = 10d}, + new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 20d}, + }; + + var mock = MakePlannedTrajectoryRepositoryMock(plannedTrajectory); + var service = new TrajectoryVisualizationService(mock.Object); + var result = await service.GetTrajectoryAsync(1, CancellationToken.None); + var lastPoint = result.Last(); + + var deltaLength = plannedTrajectory[2].WellboreDepth - plannedTrajectory[1].WellboreDepth; + var zenith = plannedTrajectory[1].ZenithAngle * Math.PI / 1800; + var azimuth = plannedTrajectory[1].AzimuthGeo * Math.PI / 1800; + + var dz = deltaLength * Math.Cos(zenith); + var xySurfaceSegmentProjectionLength = deltaLength * Math.Sin(zenith); + var dx = xySurfaceSegmentProjectionLength * Math.Cos(azimuth); + var dy = xySurfaceSegmentProjectionLength * Math.Sin(azimuth); + + var Z = plannedTrajectory[1].WellboreDepth + dz; + var X = dx; + var Y = dy; + + Assert.Equal(0d, lastPoint.X, 1d); + Assert.Equal(0d, lastPoint.Y, 1d); + Assert.Equal(50d, lastPoint.Z, 1d); + } + + } +} diff --git a/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs b/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs index ef50518c..f44f1600 100644 --- a/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs +++ b/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs @@ -4,7 +4,6 @@ using AsbCloudApp.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using ProtoBuf.Meta; using System.Collections.Generic; using System.IO; using System.Threading;