Правки, IFactualRepository переименован на IActualRepository, правки в юнит-тестах

This commit is contained in:
Olga Nemt 2023-05-11 15:36:49 +05:00
parent 37399f74a7
commit a1b4b1b9bb
5 changed files with 75 additions and 99 deletions

View File

@ -0,0 +1,17 @@
using AsbCloudApp.Data;
using AsbCloudApp.Data.WITS;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudApp.Repositories
{
/// <summary>
/// CRUD для работы с фактической траекторией из клиента
/// </summary>
/// <returns></returns>
public interface IActualTrajectoryRepository : ITrajectoryRepository
{
}
}

View File

@ -1,23 +0,0 @@
using AsbCloudApp.Data;
using AsbCloudApp.Data.WITS;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudApp.Repositories
{
/// <summary>
/// CRUD для работы с фактической траекторией из клиента
/// </summary>
/// <returns></returns>
public interface IFactualTrajectoryRepository : ITrajectoryRepository
{
/// <summary>
/// Получить все добавленные по скважине координаты фактической траектории
/// </summary>
/// <param name="idWell"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<Record7Dto>> GetAsync(int idWell, CancellationToken token);
}
}

View File

@ -1,51 +1,45 @@
using AsbCloudApp.Data;
using AsbCloudApp.Data.WITS;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using Mapster;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Repository
{
internal class FactualTrajectoryRepository : IFactualTrajectoryRepository
internal class ActualTrajectoryRepository : IActualTrajectoryRepository
{
private readonly IAsbCloudDbContext db;
private readonly IWellService wellService;
public FactualTrajectoryRepository(IAsbCloudDbContext db, IWellService wellService)
public ActualTrajectoryRepository(IAsbCloudDbContext db, IWellService wellService)
{
this.db = db;
this.wellService = wellService;
}
public async Task<IEnumerable<Record7Dto>> GetAsync(int idWell, CancellationToken token)
public async Task<TrajectoryDto[]> GetTrajectoryAsync(int idWell, CancellationToken token)
{
var well = wellService.GetOrDefault(idWell);
if (well is null || well.Timezone is null)
throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell));
var query = db.Record7
var entities = await db.Record7
.AsNoTracking()
.Where(x => x.IdTelemetry == well.IdTelemetry);
var entities = await query
.OrderBy(e => e.Deptsvym)
.ToListAsync(token);
var result = entities
.Select(r => r.Adapt<Record7Dto>());
return result;
}
public async Task<TrajectoryDto[]> GetTrajectoryAsync(int idWell, CancellationToken token)
{
return (await GetAsync(idWell, token))
.Where(x => x.IdTelemetry == well.IdTelemetry)
.Where(coord => coord.Deptsvym != null && coord.Svyinc != null && coord.Svyazc != null)
.OrderBy(e => e.Deptsvym)
.Select(x => new { x.Deptsvym, x.Svyinc, x.Svyazc })
.ToArrayAsync(token);
var result = entities
.Select(coord => new TrajectoryDto(coord.Deptsvym!.Value, coord.Svyinc!.Value, coord.Svyazc!.Value))
.ToArray();
return result;
}
}
}

View File

@ -1,11 +1,8 @@
using AsbCloudApp.Data;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudDb.Model.WITS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@ -15,9 +12,9 @@ namespace AsbCloudInfrastructure.Services.Trajectory
public class TrajectoryVisualizationService : ITrajectoryVisualizationService
{
private readonly IPlannedTrajectoryRepository plannedRepository;
private readonly IFactualTrajectoryRepository factualRepository;
private readonly IActualTrajectoryRepository factualRepository;
public TrajectoryVisualizationService(IPlannedTrajectoryRepository plannedRepository, IFactualTrajectoryRepository factualRepository)
public TrajectoryVisualizationService(IPlannedTrajectoryRepository plannedRepository, IActualTrajectoryRepository factualRepository)
{
this.plannedRepository = plannedRepository;
this.factualRepository = factualRepository;

View File

@ -13,21 +13,12 @@ namespace AsbCloudWebApi.Tests.ServicesTests
{
public class TrajectoryVisualizationServiceTest
{
private Mock<IPlannedTrajectoryRepository> MakePlannedTrajectoryRepositoryMock(IEnumerable<PlannedTrajectoryDto> dateForGetMethod)
private Mock<T> MakeTrajectoryRepositoryMock<T>(TrajectoryDto[] dateForGetMethod)
where T : class, ITrajectoryRepository
{
var mock = new Mock<IPlannedTrajectoryRepository>();
var mock = new Mock<T>();
mock.Setup(r => r.GetAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
.Returns(Task.FromResult(dateForGetMethod));
return mock;
}
private Mock<IFactualTrajectoryRepository> MakeFactualTrajectoryRepositoryMock(IEnumerable<Record7Dto> dateForGetMethod)
{
var mock = new Mock<IFactualTrajectoryRepository>();
mock.Setup(r => r.GetAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
mock.Setup(r => r.GetTrajectoryAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
.Returns(Task.FromResult(dateForGetMethod));
return mock;
@ -36,25 +27,25 @@ namespace AsbCloudWebApi.Tests.ServicesTests
[Fact]
public async Task GetTrajectoryAsync_SameCounts()
{
var plannedTrajectory = new PlannedTrajectoryDto[]
var plannedTrajectory = new TrajectoryDto[]
{
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},
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 Record7Dto[]
var actualTrajectory = new TrajectoryDto[]
{
new() { Svyazc = 0, Svyinc = 0, Deptsvym = 0},
new() { Svyazc = 30, Svyinc = 30, Deptsvym = 10},
new() { Svyazc = 0, Svyinc = 0, Deptsvym = 20},
new(0, 0, 0),
new(30,30,10),
new(0, 0, 20),
};
var mockPlan = MakePlannedTrajectoryRepositoryMock(plannedTrajectory);
var mockFact = MakeFactualTrajectoryRepositoryMock(actualTrajectory);
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());
@ -64,28 +55,28 @@ namespace AsbCloudWebApi.Tests.ServicesTests
[Fact]
public async Task GetTrajectoryAsync_StraigthBore()
{
var plannedTrajectory = new PlannedTrajectoryDto[]
var plannedTrajectory = new TrajectoryDto[]
{
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},
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 Record7Dto[]
var factualTrajectory = new TrajectoryDto[]
{
new() { Svyazc = 0, Svyinc = 0, Deptsvym = 0},
new() { Svyazc = 0, Svyinc = 0, Deptsvym = 0},
new() { Svyazc = 0, Svyinc = 0, Deptsvym = 20},
new() { Svyazc = 0, Svyinc = 0, Deptsvym = 20},
new() { Svyazc = 0, Svyinc = 0, Deptsvym = 30},
new() { Svyazc = 0, Svyinc = 0, Deptsvym = 50},
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 = MakePlannedTrajectoryRepositoryMock(plannedTrajectory);
var mockFact = MakeFactualTrajectoryRepositoryMock(factualTrajectory);
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();
@ -103,22 +94,22 @@ namespace AsbCloudWebApi.Tests.ServicesTests
[Fact]
public async Task GetTrajectoryAsync_Match()
{
var plannedTrajectory = new PlannedTrajectoryDto[]
var plannedTrajectory = new TrajectoryDto[]
{
new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 0d},
new() { AzimuthGeo = 30d, ZenithAngle = 30d, WellboreDepth = 10d},
new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 20d},
new(0, 0, 0),
new(30, 30, 10),
new(0, 0, 20),
};
var factualTrajectory = new Record7Dto[]
var factualTrajectory = new TrajectoryDto[]
{
new() { Svyazc = 0, Svyinc = 0, Deptsvym = 0},
new() { Svyazc = 30, Svyinc = 30, Deptsvym = 10},
new() { Svyazc = 0, Svyinc = 0, Deptsvym = 20},
new(0, 0, 0),
new(30, 30, 10),
new(0, 0, 20),
};
var mockPlanned = MakePlannedTrajectoryRepositoryMock(plannedTrajectory);
var mockFactual = MakeFactualTrajectoryRepositoryMock(factualTrajectory);
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();