2023-11-03 19:24:58 +05:00
|
|
|
using System;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
using AsbCloudApp.Data.DailyReport;
|
|
|
|
using AsbCloudApp.Data.DailyReport.Blocks.Sign;
|
|
|
|
using AsbCloudApp.Data.DailyReport.Blocks.Subsystems;
|
|
|
|
using AsbCloudApp.Data.DailyReport.Blocks.TimeBalance;
|
|
|
|
using AsbCloudApp.Exceptions;
|
|
|
|
using AsbCloudApp.Repositories;
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
using AsbCloudApp.Services.ProcessMaps.WellDrilling;
|
|
|
|
using AsbCloudApp.Services.Subsystems;
|
|
|
|
using AsbCloudInfrastructure.Services.DailyReport;
|
|
|
|
using NSubstitute;
|
|
|
|
using Xunit;
|
|
|
|
|
2023-11-07 16:05:24 +05:00
|
|
|
namespace AsbCloudWebApi.Tests.Services;
|
2023-11-03 19:24:58 +05:00
|
|
|
|
|
|
|
public class DailyReportServiceTest
|
|
|
|
{
|
|
|
|
private const int idDailyReport = 1;
|
|
|
|
private const int idWell = 2;
|
|
|
|
private const int idUser = 3;
|
|
|
|
|
|
|
|
private readonly DateTime dateStart = new DateOnly(2023, 10, 26).ToDateTime(TimeOnly.MinValue);
|
|
|
|
|
|
|
|
private readonly IWellService wellServiceMock = Substitute.For<IWellService>();
|
|
|
|
private readonly ITrajectoryFactRepository trajectoryFactRepositoryMock = Substitute.For<ITrajectoryFactRepository>();
|
|
|
|
private readonly IDailyReportRepository dailyReportRepositoryMock = Substitute.For<IDailyReportRepository>();
|
|
|
|
private readonly IScheduleRepository scheduleRepositoryMock = Substitute.For<IScheduleRepository>();
|
|
|
|
private readonly IWellOperationRepository wellOperationRepositoryMock = Substitute.For<IWellOperationRepository>();
|
|
|
|
private readonly ISubsystemOperationTimeService subsystemOperationTimeServiceMock = Substitute.For<ISubsystemOperationTimeService>();
|
|
|
|
private readonly IProcessMapReportWellDrillingService processMapReportWellDrillingServiceMock = Substitute.For<IProcessMapReportWellDrillingService>();
|
|
|
|
private readonly IDetectedOperationService detectedOperationServiceMock = Substitute.For<IDetectedOperationService>();
|
|
|
|
|
|
|
|
private readonly DailyReportService dailyReportService;
|
|
|
|
|
|
|
|
private readonly DailyReportDto fakeDailyReport;
|
|
|
|
|
|
|
|
public DailyReportServiceTest()
|
|
|
|
{
|
|
|
|
fakeDailyReport = new()
|
|
|
|
{
|
|
|
|
Id = idDailyReport,
|
|
|
|
IdWell = idWell,
|
|
|
|
DateStart = dateStart
|
|
|
|
};
|
|
|
|
|
|
|
|
dailyReportService = new DailyReportService(wellServiceMock,
|
|
|
|
trajectoryFactRepositoryMock,
|
|
|
|
dailyReportRepositoryMock,
|
|
|
|
scheduleRepositoryMock,
|
|
|
|
wellOperationRepositoryMock,
|
|
|
|
subsystemOperationTimeServiceMock,
|
|
|
|
processMapReportWellDrillingServiceMock,
|
|
|
|
detectedOperationServiceMock);
|
|
|
|
|
|
|
|
dailyReportRepositoryMock.InsertAsync(Arg.Any<DailyReportDto>(), Arg.Any<CancellationToken>())
|
|
|
|
.ReturnsForAnyArgs(idDailyReport);
|
|
|
|
|
|
|
|
dailyReportRepositoryMock.GetOrDefaultAsync(idDailyReport, Arg.Any<CancellationToken>())
|
|
|
|
.Returns(fakeDailyReport);
|
|
|
|
|
|
|
|
dailyReportRepositoryMock.UpdateAsync(Arg.Any<DailyReportDto>(), Arg.Any<CancellationToken>())
|
|
|
|
.ReturnsForAnyArgs(idDailyReport);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public async Task InsertAsync_ShouldReturn_ExceptionAboutDuplicate()
|
|
|
|
{
|
|
|
|
//arrange
|
|
|
|
dailyReportRepositoryMock.AnyAsync(Arg.Any<int>(), Arg.Any<DateTime>(), Arg.Any<CancellationToken>())
|
|
|
|
.ReturnsForAnyArgs(true);
|
|
|
|
|
|
|
|
//act
|
|
|
|
Task Result() => dailyReportService.InsertAsync(idWell, dateStart, CancellationToken.None);
|
|
|
|
|
|
|
|
//assert
|
|
|
|
var exception = await Assert.ThrowsAsync<ArgumentInvalidException>(Result);
|
|
|
|
Assert.Equal("Суточный отчёт уже существует", exception.Message);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public async Task InsertAsync_ShouldReturn_PositiveId()
|
|
|
|
{
|
|
|
|
//arrange
|
|
|
|
dailyReportRepositoryMock.AnyAsync(Arg.Any<int>(), Arg.Any<DateTime>(), Arg.Any<CancellationToken>())
|
|
|
|
.ReturnsForAnyArgs(false);
|
|
|
|
|
|
|
|
//act
|
|
|
|
var result = await dailyReportService.InsertAsync(idWell, dateStart, CancellationToken.None);
|
|
|
|
|
|
|
|
//assert
|
|
|
|
Assert.Equal(idDailyReport, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public async Task UpdateSubsystemBlock_ShouldReturn_Success()
|
|
|
|
{
|
|
|
|
//arrange
|
|
|
|
var fakeSubsystemBlock = new SubsystemBlockDto
|
|
|
|
{
|
|
|
|
IdUser = idUser,
|
2023-11-09 15:01:29 +05:00
|
|
|
WellBore = 999,
|
|
|
|
MeasurementsPerDay = 999,
|
2023-11-03 19:24:58 +05:00
|
|
|
TotalRopPlan = 999,
|
|
|
|
Comment = "Увеличить обороты",
|
2023-11-09 15:01:29 +05:00
|
|
|
Subsystems = new[]
|
2023-11-03 19:24:58 +05:00
|
|
|
{
|
|
|
|
new SubsystemRecordDto
|
|
|
|
{
|
2023-11-07 15:57:15 +05:00
|
|
|
SubsystemName = "АвтоСПО",
|
2023-11-03 19:24:58 +05:00
|
|
|
IdTimeInterval = 1,
|
|
|
|
UsedTimeHours = 24,
|
|
|
|
SumDepthInterval = 1500,
|
|
|
|
KUsage = 100
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//act
|
|
|
|
var result = await dailyReportService.UpdateBlockAsync(idDailyReport, idUser, fakeSubsystemBlock, CancellationToken.None);
|
|
|
|
|
|
|
|
//assert
|
2023-11-09 15:01:29 +05:00
|
|
|
Assert.NotNull(fakeSubsystemBlock.DateLastUpdate);
|
2023-11-03 19:24:58 +05:00
|
|
|
Assert.NotNull(fakeDailyReport.DateLastUpdate);
|
|
|
|
Assert.Equal(fakeDailyReport.SubsystemBlock, fakeSubsystemBlock);
|
|
|
|
Assert.Equal(idDailyReport, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public async Task UpdateSignBlock_ShouldReturn_Success()
|
|
|
|
{
|
|
|
|
//arrange
|
|
|
|
var fakeSignBlock = new SignBlockDto
|
|
|
|
{
|
|
|
|
IdUser = idUser,
|
|
|
|
DrillingMaster = new SignRecordDto()
|
|
|
|
{
|
|
|
|
Name = "Иван",
|
|
|
|
Patronymic = "Иванович",
|
|
|
|
Surname = "Иванов"
|
|
|
|
},
|
|
|
|
Supervisor = new SignRecordDto()
|
|
|
|
{
|
|
|
|
Name = "Илья",
|
|
|
|
Patronymic = "Ильич",
|
|
|
|
Surname = "Бурилов"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//act
|
|
|
|
var result = await dailyReportService.UpdateBlockAsync(idDailyReport, idUser, fakeSignBlock, CancellationToken.None);
|
|
|
|
|
|
|
|
//assert
|
2023-11-09 15:01:29 +05:00
|
|
|
Assert.NotNull(fakeSignBlock.DateLastUpdate);
|
2023-11-03 19:24:58 +05:00
|
|
|
Assert.NotNull(fakeDailyReport.DateLastUpdate);
|
|
|
|
Assert.Equal(fakeDailyReport.SignBlock, fakeSignBlock);
|
|
|
|
Assert.Equal(idDailyReport, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public async Task UpdateTimeBalance_ShouldReturn_Success()
|
|
|
|
{
|
|
|
|
//arrange
|
|
|
|
var fakeTimeBalanceBlock = new TimeBalanceBlockDto
|
|
|
|
{
|
|
|
|
IdUser = idUser,
|
|
|
|
IdSection = 1,
|
|
|
|
WellDepthPlan = 2000,
|
|
|
|
WellOperations = new[]
|
|
|
|
{
|
|
|
|
new TimeBalanceRecordDto()
|
|
|
|
{
|
|
|
|
DurationHours = new PlanFactDto<double>()
|
|
|
|
{
|
|
|
|
Fact = 100,
|
|
|
|
Plan = 150,
|
|
|
|
},
|
|
|
|
DrillingDeviationPerSection = 90,
|
|
|
|
DrillingDeviationPerDaily = 100,
|
|
|
|
ReasonDeviation = "Отклонение"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//act
|
|
|
|
var result = await dailyReportService.UpdateBlockAsync(idDailyReport, idUser, fakeTimeBalanceBlock, CancellationToken.None);
|
|
|
|
|
|
|
|
//assert
|
2023-11-09 15:01:29 +05:00
|
|
|
Assert.NotNull(fakeTimeBalanceBlock.DateLastUpdate);
|
2023-11-03 19:24:58 +05:00
|
|
|
Assert.NotNull(fakeDailyReport.DateLastUpdate);
|
|
|
|
Assert.Equal(fakeDailyReport.TimeBalanceBlock, fakeTimeBalanceBlock);
|
|
|
|
Assert.Equal(idDailyReport, result);
|
|
|
|
}
|
|
|
|
}
|