2024-04-17 11:10:56 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Data.WellOperation;
|
|
|
|
|
using AsbCloudApp.Repositories;
|
|
|
|
|
using AsbCloudApp.Requests;
|
|
|
|
|
using AsbCloudApp.Services;
|
2024-03-12 15:00:14 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services;
|
|
|
|
|
using NSubstitute;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
|
|
|
|
|
{
|
|
|
|
|
public class WellCompositeOperationServiceTest
|
|
|
|
|
{
|
|
|
|
|
private WellCompositeOperationService service;
|
|
|
|
|
|
|
|
|
|
private ICrudRepository<WellSectionTypeDto> wellSectionTypeRepository
|
|
|
|
|
= Substitute.For<ICrudRepository<WellSectionTypeDto>>();
|
|
|
|
|
private IWellOperationCategoryRepository wellOperationCategoryRepository
|
|
|
|
|
= Substitute.For<IWellOperationCategoryRepository>();
|
|
|
|
|
private IWellOperationRepository wellOperationRepository
|
|
|
|
|
= Substitute.For<IWellOperationRepository>();
|
2024-04-17 11:10:56 +05:00
|
|
|
|
private IWellService wellService
|
|
|
|
|
= Substitute.For<IWellService>();
|
|
|
|
|
|
2024-03-12 15:00:14 +05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private readonly static IEnumerable<WellOperationCategoryDto> operationCategories = new List<WellOperationCategoryDto>()
|
|
|
|
|
{
|
|
|
|
|
new(){Id = 5096, Name = "Шаблонирование перед спуском"},
|
|
|
|
|
new(){Id = 5008, Name = "Шаблонировка во время бурения"},
|
|
|
|
|
new(){Id = 5013, Name = "Подъем КНБК"},
|
|
|
|
|
new(){Id = 5003, Name = "Бурение ротором"},
|
|
|
|
|
new(){Id = 5036, Name = "Промывка"},
|
|
|
|
|
new(){Id = 5012, Name = "Подъем инструмента"},
|
|
|
|
|
new(){Id = 5083, Name = "Проработка принудительная"},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private readonly static IEnumerable<WellSectionTypeDto> sectionTypes = new List<WellSectionTypeDto>()
|
|
|
|
|
{
|
|
|
|
|
new() {Id = 2, Caption = "Направление", Order = 0},
|
|
|
|
|
new() {Id = 3, Caption = "Кондуктор", Order = 1},
|
|
|
|
|
new() {Id = 31, Caption = "Техническая колонна", Order = 2}
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-22 09:29:01 +05:00
|
|
|
|
private readonly static IEnumerable<WellOperationDto> wellOperations1 = new List<WellOperationDto>()
|
2024-03-12 15:00:14 +05:00
|
|
|
|
{
|
2024-03-22 09:29:01 +05:00
|
|
|
|
new()
|
2024-03-12 15:00:14 +05:00
|
|
|
|
{
|
|
|
|
|
DepthStart = 50,
|
|
|
|
|
DurationHours = 1,
|
|
|
|
|
IdCategory = 5096,
|
|
|
|
|
IdWell = 55,
|
|
|
|
|
IdWellSectionType = 2,
|
|
|
|
|
OperationCategoryName = "Шаблонирование перед спуском",
|
2024-04-17 11:10:56 +05:00
|
|
|
|
WellSectionTypeCaption = "Направление"
|
2024-03-12 15:00:14 +05:00
|
|
|
|
},
|
2024-03-22 09:29:01 +05:00
|
|
|
|
new()
|
2024-03-12 15:00:14 +05:00
|
|
|
|
{
|
|
|
|
|
DepthStart = 84,
|
|
|
|
|
DurationHours = 1,
|
|
|
|
|
IdCategory = 5008,
|
|
|
|
|
IdWell = 64,
|
|
|
|
|
IdWellSectionType = 2,
|
|
|
|
|
OperationCategoryName = "Шаблонировка во время бурения",
|
|
|
|
|
WellSectionTypeCaption = "Направление"
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-22 09:29:01 +05:00
|
|
|
|
private readonly static IEnumerable<WellOperationDto> wellOperations2 = new List<WellOperationDto>()
|
2024-03-12 15:00:14 +05:00
|
|
|
|
{
|
2024-03-22 09:29:01 +05:00
|
|
|
|
new()
|
2024-03-12 15:00:14 +05:00
|
|
|
|
{
|
|
|
|
|
DepthStart = 10,
|
|
|
|
|
DurationHours = 1.5,
|
|
|
|
|
IdCategory = 5003,
|
|
|
|
|
IdWell = 55,
|
|
|
|
|
IdWellSectionType = 2,
|
|
|
|
|
OperationCategoryName = "Бурение ротором",
|
|
|
|
|
WellSectionTypeCaption = "Направление"
|
|
|
|
|
},
|
2024-03-22 09:29:01 +05:00
|
|
|
|
new()
|
2024-03-12 15:00:14 +05:00
|
|
|
|
{
|
|
|
|
|
DepthStart = 20,
|
|
|
|
|
DurationHours = 3.5,
|
|
|
|
|
IdCategory = 5003,
|
|
|
|
|
IdWell = 64,
|
|
|
|
|
IdWellSectionType = 2,
|
|
|
|
|
OperationCategoryName = "Бурение ротором",
|
|
|
|
|
WellSectionTypeCaption = "Направление"
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-22 09:29:01 +05:00
|
|
|
|
private readonly static IEnumerable<WellOperationDto> wellOperations3 = new List<WellOperationDto>()
|
2024-03-12 15:00:14 +05:00
|
|
|
|
{
|
2024-03-22 09:29:01 +05:00
|
|
|
|
new()
|
2024-03-12 15:00:14 +05:00
|
|
|
|
{
|
|
|
|
|
DepthStart = 1372,
|
|
|
|
|
DurationHours = 3,
|
|
|
|
|
IdCategory = 5036,
|
|
|
|
|
IdWell = 55,
|
|
|
|
|
IdWellSectionType = 3,
|
|
|
|
|
OperationCategoryName = "Промывка",
|
|
|
|
|
WellSectionTypeCaption = "Кондуктор"
|
|
|
|
|
},
|
2024-03-22 09:29:01 +05:00
|
|
|
|
new()
|
2024-03-12 15:00:14 +05:00
|
|
|
|
{
|
|
|
|
|
DepthStart = 1435,
|
|
|
|
|
DurationHours = 4,
|
|
|
|
|
IdCategory = 5036,
|
|
|
|
|
IdWell = 64,
|
|
|
|
|
IdWellSectionType = 3,
|
|
|
|
|
OperationCategoryName = "Промывка",
|
|
|
|
|
WellSectionTypeCaption = "Кондуктор"
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-22 09:29:01 +05:00
|
|
|
|
private readonly static IEnumerable<WellOperationDto> wellOperations4 = new List<WellOperationDto>()
|
2024-03-12 15:00:14 +05:00
|
|
|
|
{
|
2024-03-22 09:29:01 +05:00
|
|
|
|
new()
|
2024-03-12 15:00:14 +05:00
|
|
|
|
{
|
|
|
|
|
DepthStart = 1000,
|
|
|
|
|
DurationHours = 10,
|
|
|
|
|
IdCategory = 5012,
|
|
|
|
|
IdWell = 55,
|
|
|
|
|
IdWellSectionType = 31,
|
|
|
|
|
OperationCategoryName = "Подъем инструмента",
|
|
|
|
|
WellSectionTypeCaption = "Техническая колонна"
|
|
|
|
|
},
|
2024-03-22 09:29:01 +05:00
|
|
|
|
new()
|
2024-03-12 15:00:14 +05:00
|
|
|
|
{
|
|
|
|
|
DepthStart = 500,
|
|
|
|
|
DurationHours = 5,
|
|
|
|
|
IdCategory = 5083,
|
|
|
|
|
IdWell = 55,
|
|
|
|
|
IdWellSectionType = 31,
|
|
|
|
|
OperationCategoryName = "Проработка принудительная",
|
|
|
|
|
WellSectionTypeCaption = "Техническая колонна"
|
|
|
|
|
},
|
2024-03-22 09:29:01 +05:00
|
|
|
|
new()
|
2024-03-12 15:00:14 +05:00
|
|
|
|
{
|
|
|
|
|
DepthStart = 600,
|
|
|
|
|
DurationHours = 5,
|
|
|
|
|
IdCategory = 5083,
|
|
|
|
|
IdWell = 64,
|
|
|
|
|
IdWellSectionType = 31,
|
|
|
|
|
OperationCategoryName = "Проработка принудительная",
|
|
|
|
|
WellSectionTypeCaption = "Техническая колонна"
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public WellCompositeOperationServiceTest()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
wellSectionTypeRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
|
|
|
|
.Returns(sectionTypes);
|
|
|
|
|
|
|
|
|
|
wellOperationCategoryRepository.Get(Arg.Any<bool>())
|
|
|
|
|
.Returns(operationCategories);
|
|
|
|
|
|
|
|
|
|
service = new WellCompositeOperationService(
|
2024-04-17 11:10:56 +05:00
|
|
|
|
wellSectionTypeRepository,
|
2024-03-12 15:00:14 +05:00
|
|
|
|
wellOperationCategoryRepository,
|
2024-04-17 11:10:56 +05:00
|
|
|
|
wellOperationRepository,
|
|
|
|
|
wellService);
|
2024-03-12 15:00:14 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-13 14:30:54 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// На вход подаются 2 операции с одинаковыми секциями (id = 2), но разными категориями (ids = 5096, 5008) и ключами скважин (ids = 55, 64)
|
2024-04-17 09:44:30 +05:00
|
|
|
|
/// Метод возвращает объект с одной композитной операцией и списком операций в разрезе 2-х скважин
|
|
|
|
|
/// Композитная операция должна иметь категорию 5013
|
2024-03-13 14:30:54 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2024-03-12 15:00:14 +05:00
|
|
|
|
[Fact]
|
2024-03-13 14:30:54 +05:00
|
|
|
|
public async Task GetAsync_return_composite_and_others_with_category_5013()
|
2024-03-12 15:00:14 +05:00
|
|
|
|
{
|
|
|
|
|
// arrange
|
2024-03-22 09:29:01 +05:00
|
|
|
|
wellOperationRepository.GetAsync(Arg.Any<WellOperationRequest>(), Arg.Any<CancellationToken>())
|
2024-03-12 15:00:14 +05:00
|
|
|
|
.Returns(wellOperations1);
|
|
|
|
|
|
2024-04-17 11:10:56 +05:00
|
|
|
|
var idsWell = new List<int>() { 55, 64 };
|
2024-03-12 15:00:14 +05:00
|
|
|
|
|
|
|
|
|
// act
|
|
|
|
|
var result = await service.GetAsync(idsWell, CancellationToken.None);
|
|
|
|
|
|
|
|
|
|
// assert
|
2024-04-17 09:44:30 +05:00
|
|
|
|
var compositeWellOperations = result.WellOperationsComposite;
|
|
|
|
|
Assert.Single(compositeWellOperations);
|
|
|
|
|
Assert.Equal(5013, compositeWellOperations.FirstOrDefault()?.IdCategory);
|
|
|
|
|
Assert.Equal(1, compositeWellOperations.FirstOrDefault()?.DurationHours);
|
|
|
|
|
Assert.Equal(84, compositeWellOperations.FirstOrDefault()?.DepthStart);
|
|
|
|
|
|
|
|
|
|
var categoryName = compositeWellOperations.Select(o => o.OperationCategoryName).First();
|
2024-03-12 15:00:14 +05:00
|
|
|
|
Assert.Equal("Подъем КНБК", categoryName);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-13 14:30:54 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// На вход подаются 2 операции с одинаковыми секциями (id = 2) и категориями (id = 5003), но разными ключами скважин (ids = 55, 64)
|
2024-04-17 09:44:30 +05:00
|
|
|
|
/// Метод возвращает объект с одной композитной операцией и списком операций в разрезе 2-х скважин
|
2024-03-13 14:30:54 +05:00
|
|
|
|
/// Операция композитной скважины должна содержать данные той операции, которая содержит минимальный duration_hours
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2024-03-12 15:00:14 +05:00
|
|
|
|
[Fact]
|
2024-03-13 14:30:54 +05:00
|
|
|
|
public async Task GetAsync_return_composite_with_minimum_depth_start()
|
2024-03-12 15:00:14 +05:00
|
|
|
|
{
|
|
|
|
|
// arrange
|
2024-03-22 09:29:01 +05:00
|
|
|
|
wellOperationRepository.GetAsync(Arg.Any<WellOperationRequest>(), Arg.Any<CancellationToken>())
|
2024-03-12 15:00:14 +05:00
|
|
|
|
.Returns(wellOperations2);
|
|
|
|
|
|
|
|
|
|
var idsWell = new List<int>() { 55, 64 };
|
|
|
|
|
|
|
|
|
|
// act
|
|
|
|
|
var result = await service.GetAsync(idsWell, CancellationToken.None);
|
|
|
|
|
|
|
|
|
|
// assert
|
2024-04-17 09:44:30 +05:00
|
|
|
|
var compositeWellOperations = result.WellOperationsComposite;
|
2024-04-17 11:10:56 +05:00
|
|
|
|
Assert.Single(compositeWellOperations);
|
2024-04-17 09:44:30 +05:00
|
|
|
|
Assert.Equal(5003, compositeWellOperations.FirstOrDefault()!.IdCategory);
|
|
|
|
|
Assert.Equal(1.5, compositeWellOperations.FirstOrDefault()!.DurationHours);
|
|
|
|
|
Assert.Equal(10, compositeWellOperations.FirstOrDefault()!.DepthStart);
|
2024-03-12 15:00:14 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-13 14:30:54 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// На вход подаются 2 операции с одинаковыми секциями (id = 3) и категориями (id = 5036), но разными ключами скважин (ids = 55, 64)
|
2024-04-17 09:44:30 +05:00
|
|
|
|
/// Метод возвращает объект с одной композитной операцией и списком операций в разрезе 2-х скважин
|
2024-03-13 14:30:54 +05:00
|
|
|
|
/// Операция композитной скважины должна содержать данные той операции, которая содержит минимальный duration_hours
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2024-03-12 15:00:14 +05:00
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetAsync_return_data3()
|
|
|
|
|
{
|
|
|
|
|
// arrange
|
2024-03-22 09:29:01 +05:00
|
|
|
|
wellOperationRepository.GetAsync(Arg.Any<WellOperationRequest>(), Arg.Any<CancellationToken>())
|
2024-03-12 15:00:14 +05:00
|
|
|
|
.Returns(wellOperations3);
|
|
|
|
|
|
|
|
|
|
var idsWell = new List<int>() { 55, 64 };
|
|
|
|
|
|
|
|
|
|
// act
|
|
|
|
|
var result = await service.GetAsync(idsWell, CancellationToken.None);
|
|
|
|
|
|
|
|
|
|
// assert
|
2024-04-17 09:44:30 +05:00
|
|
|
|
var compositeWellOperations = result.WellOperationsComposite;
|
|
|
|
|
Assert.Single(compositeWellOperations);
|
|
|
|
|
Assert.Equal(5036, compositeWellOperations.FirstOrDefault()!.IdCategory);
|
|
|
|
|
Assert.Equal(3, compositeWellOperations.FirstOrDefault()!.DurationHours);
|
|
|
|
|
Assert.Equal(1372, compositeWellOperations.FirstOrDefault()!.DepthStart);
|
2024-03-12 15:00:14 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-13 14:30:54 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// На вход подаются 3 операции с одинаковыми секциями (id = 31), но разными категориями (ids = 5012, 5083) и ключами скважин (ids = 55, 64)
|
2024-04-17 09:44:30 +05:00
|
|
|
|
/// Метод возвращает объект с одной композитной операцией и списком операций в разрезе 2-х скважин
|
2024-03-13 14:30:54 +05:00
|
|
|
|
/// Операция композитной скважины должна содержать:
|
|
|
|
|
/// данные той операции, которая содержит минимальный duration_hours
|
|
|
|
|
/// категорию с ключом 5013
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2024-03-12 15:00:14 +05:00
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetAsync_return_data4()
|
|
|
|
|
{
|
|
|
|
|
// arrange
|
2024-03-22 09:29:01 +05:00
|
|
|
|
wellOperationRepository.GetAsync(Arg.Any<WellOperationRequest>(), Arg.Any<CancellationToken>())
|
2024-03-12 15:00:14 +05:00
|
|
|
|
.Returns(wellOperations4);
|
|
|
|
|
|
|
|
|
|
var idsWell = new List<int>() { 55, 64 };
|
|
|
|
|
|
|
|
|
|
// act
|
|
|
|
|
var result = await service.GetAsync(idsWell, CancellationToken.None);
|
|
|
|
|
|
|
|
|
|
// assert
|
2024-04-17 09:44:30 +05:00
|
|
|
|
var compositeWellOperations = result.WellOperationsComposite;
|
|
|
|
|
Assert.Single(compositeWellOperations);
|
|
|
|
|
Assert.Equal(5013, compositeWellOperations.FirstOrDefault()!.IdCategory);
|
|
|
|
|
Assert.Equal(5, compositeWellOperations.FirstOrDefault()!.DurationHours);
|
|
|
|
|
Assert.Equal(600, compositeWellOperations.FirstOrDefault()!.DepthStart);
|
2024-03-12 15:00:14 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-13 14:30:54 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// На вход подаются список разных операций с разными ключами скважин (ids = 55, 64)
|
2024-04-17 09:44:30 +05:00
|
|
|
|
/// Метод возвращает объект с одной композитной операцией и списком операций в разрезе 2-х скважин
|
2024-03-13 14:30:54 +05:00
|
|
|
|
/// Операция композитной скважины должна содержать глубину забоя = 1372
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2024-03-12 15:00:14 +05:00
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetAsync_return_data5()
|
|
|
|
|
{
|
|
|
|
|
// arrange
|
2024-03-22 09:29:01 +05:00
|
|
|
|
var wellOperations = new List<WellOperationDto>();
|
2024-03-12 15:00:14 +05:00
|
|
|
|
wellOperations.AddRange(wellOperations1);
|
|
|
|
|
wellOperations.AddRange(wellOperations2);
|
|
|
|
|
wellOperations.AddRange(wellOperations3);
|
|
|
|
|
wellOperations.AddRange(wellOperations4);
|
|
|
|
|
|
2024-03-22 09:29:01 +05:00
|
|
|
|
wellOperationRepository.GetAsync(Arg.Any<WellOperationRequest>(), Arg.Any<CancellationToken>())
|
2024-03-12 15:00:14 +05:00
|
|
|
|
.Returns(wellOperations);
|
|
|
|
|
|
|
|
|
|
var idsWell = new List<int>() { 55, 64 };
|
|
|
|
|
|
|
|
|
|
// act
|
|
|
|
|
var result = await service.GetAsync(idsWell, CancellationToken.None);
|
|
|
|
|
|
|
|
|
|
// assert
|
2024-04-17 11:10:56 +05:00
|
|
|
|
var wellOperationsCount = result.WellCompositeSourceOperations
|
|
|
|
|
.SelectMany(o => o.Operations).Count();
|
2024-04-17 09:44:30 +05:00
|
|
|
|
Assert.Equal(wellOperations.Count(), wellOperationsCount);
|
2024-03-12 15:00:14 +05:00
|
|
|
|
|
2024-04-17 09:44:30 +05:00
|
|
|
|
var lastOperationComposite = result.WellOperationsComposite.Last();
|
2024-03-12 15:00:14 +05:00
|
|
|
|
Assert.Equal(1372, lastOperationComposite.DepthStart);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|