2024-08-16 18:02:12 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Data.WellOperation;
|
|
|
|
|
using AsbCloudApp.Repositories;
|
|
|
|
|
using AsbCloudApp.Requests;
|
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
using AsbCloudInfrastructure.Services.WellOperationService.WellOperationService;
|
|
|
|
|
using NSubstitute;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
2024-08-19 10:57:31 +05:00
|
|
|
|
namespace AsbCloudInfrastructure.Tests.Services;
|
2024-08-16 18:02:12 +05:00
|
|
|
|
public class WellOperationServiceTest
|
|
|
|
|
{
|
|
|
|
|
private const int idWell = 1;
|
|
|
|
|
private readonly IWellOperationService wellOperationServiceMock = Substitute.For<IWellOperationService>();
|
|
|
|
|
private readonly IWellOperationRepository wellOperationRepositoryMock = Substitute.For<IWellOperationRepository>();
|
|
|
|
|
private readonly IWellService wellServiceMock = Substitute.For<IWellService>();
|
|
|
|
|
private readonly IWellOperationCategoryRepository wellOperationCategoryRepositoryMock = Substitute.For<IWellOperationCategoryRepository>();
|
|
|
|
|
|
2024-08-19 10:51:09 +05:00
|
|
|
|
private readonly SimpleTimezoneDto timeZone = new()
|
2024-08-16 18:02:12 +05:00
|
|
|
|
{
|
|
|
|
|
Hours = 5,
|
|
|
|
|
};
|
2024-08-19 10:51:09 +05:00
|
|
|
|
|
|
|
|
|
private readonly WellOperationBaseDto operation = new WellOperationBaseDto()
|
2024-08-16 18:02:12 +05:00
|
|
|
|
{
|
|
|
|
|
IdWell = idWell,
|
|
|
|
|
Id = 1,
|
|
|
|
|
IdType = WellOperation.IdOperationTypeFact,
|
|
|
|
|
DepthStart = 1,
|
|
|
|
|
DepthEnd = 2,
|
|
|
|
|
DateStart = DateTimeOffset.UtcNow,
|
|
|
|
|
DurationHours = 3,
|
2024-08-19 10:51:09 +05:00
|
|
|
|
IdCategory = WellOperationCategory.NonProductiveTimeSubIds.First(),
|
2024-08-16 18:02:12 +05:00
|
|
|
|
IdWellSectionType = 1
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public WellOperationServiceTest()
|
|
|
|
|
{
|
|
|
|
|
wellServiceMock
|
|
|
|
|
.GetTimezone(Arg.Any<int>())
|
|
|
|
|
.Returns(timeZone);
|
|
|
|
|
|
|
|
|
|
wellOperationServiceMock = new WellOperationService(wellServiceMock, wellOperationRepositoryMock, wellOperationCategoryRepositoryMock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetTvdAsync_ShouldReturn_Success()
|
|
|
|
|
{
|
2024-08-19 10:51:09 +05:00
|
|
|
|
//arrange
|
|
|
|
|
var id = operation.Id;
|
|
|
|
|
//плановая операция
|
|
|
|
|
var operationPlanRotor = new WellOperationBaseDto(operation)
|
|
|
|
|
{
|
|
|
|
|
Id = id++,
|
|
|
|
|
IdType = WellOperation.IdOperationTypePlan,
|
|
|
|
|
IdCategory = WellOperationCategory.IdRotor,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//фактическая операция, с нпв
|
|
|
|
|
var operationFactWithNpt = new WellOperationBaseDto(operation)
|
|
|
|
|
{
|
|
|
|
|
Id = id++,
|
|
|
|
|
DateStart = operationPlanRotor.DateStart.AddDays(1),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//фактическая операция, у которой есть плановая для сопоставления
|
|
|
|
|
var operationFactRotor = new WellOperationBaseDto(operation)
|
|
|
|
|
{
|
|
|
|
|
Id = id++,
|
|
|
|
|
IdPlan = operationPlanRotor.Id,
|
|
|
|
|
DateStart = operationFactWithNpt.DateStart.AddHours(operationFactWithNpt.DurationHours),
|
|
|
|
|
IdCategory = WellOperationCategory.IdRotor,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
WellOperationBaseDto[] factOperations = [operationFactWithNpt, operationFactRotor];
|
|
|
|
|
WellOperationBaseDto[] operations = [operationFactRotor, operationFactWithNpt, operationPlanRotor];
|
|
|
|
|
|
|
|
|
|
wellOperationRepositoryMock
|
|
|
|
|
.GetAll(Arg.Any<WellOperationRepositoryRequest>(), Arg.Any<CancellationToken>())
|
|
|
|
|
.Returns(operations);
|
2024-08-16 18:02:12 +05:00
|
|
|
|
|
|
|
|
|
//act
|
|
|
|
|
var data = await wellOperationServiceMock.GetTvdAsync(idWell, CancellationToken.None);
|
|
|
|
|
|
2024-08-19 10:51:09 +05:00
|
|
|
|
//assert
|
|
|
|
|
var plans = data
|
|
|
|
|
.Where(pfb => pfb.Plan is not null)
|
|
|
|
|
.Select(pfb => pfb.Plan!)
|
2024-08-16 18:02:12 +05:00
|
|
|
|
.ToArray();
|
|
|
|
|
|
2024-08-19 10:51:09 +05:00
|
|
|
|
var facts = data
|
|
|
|
|
.Where(pfb => pfb.Fact is not null)
|
|
|
|
|
.Select(pfb => pfb.Fact!)
|
|
|
|
|
.ToArray();
|
2024-08-16 18:02:12 +05:00
|
|
|
|
|
2024-08-19 10:51:09 +05:00
|
|
|
|
var retrievedOperationPlanRotor = plans.First(o => o.Id == operationPlanRotor.Id);
|
|
|
|
|
Assert.Equal(0, retrievedOperationPlanRotor.Day);
|
|
|
|
|
Assert.Equal(0, retrievedOperationPlanRotor.NptHours);
|
|
|
|
|
Assert.Equal(operationPlanRotor.IdCategory, retrievedOperationPlanRotor.IdCategory);
|
|
|
|
|
|
|
|
|
|
var retrievedOperationFactWithNpt = facts.First(o => o.Id == operationFactWithNpt.Id);
|
|
|
|
|
Assert.Equal(0, retrievedOperationFactWithNpt.Day);
|
|
|
|
|
Assert.Equal(operationFactWithNpt.IdCategory, retrievedOperationFactWithNpt.IdCategory);
|
|
|
|
|
|
|
|
|
|
var retrievedOperationFactRotor = facts.First(o => o.Id == operationFactRotor.Id);
|
2024-08-19 10:57:31 +05:00
|
|
|
|
var expectedDay = operationFactWithNpt.DurationHours / 24;
|
2024-08-19 10:51:09 +05:00
|
|
|
|
Assert.Equal(expectedDay, retrievedOperationFactRotor.Day, 0.001);
|
|
|
|
|
Assert.Equal(operationFactWithNpt.DurationHours, retrievedOperationFactRotor.NptHours, 0.001);
|
|
|
|
|
Assert.Equal(retrievedOperationPlanRotor.Id, retrievedOperationFactRotor.IdPlan);
|
|
|
|
|
Assert.Equal(operationFactRotor.IdCategory, retrievedOperationFactRotor.IdCategory);
|
2024-08-16 18:02:12 +05:00
|
|
|
|
}
|
|
|
|
|
}
|