forked from ddrilling/AsbCloudServer
105 lines
4.3 KiB
C#
105 lines
4.3 KiB
C#
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<IPlannedTrajectoryRepository> MakePlannedTrajectoryRepositoryMock(IEnumerable<PlannedTrajectoryDto> dateForGetMethod)
|
|
{
|
|
var mock = new Mock<IPlannedTrajectoryRepository>();
|
|
|
|
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 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);
|
|
}
|
|
|
|
}
|
|
}
|