Пока законмментированный ProcessMapReportDataSaubStatServiceTest (чтобы проект собрался)

This commit is contained in:
Olga Nemt 2024-06-21 10:29:06 +05:00
parent 627d388c9b
commit cbe439ff1a

View File

@ -1,297 +1,297 @@
using AsbCloudApp.Data; //using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMaps; //using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Data.WellOperation; //using AsbCloudApp.Data.WellOperation;
using AsbCloudApp.Repositories; //using AsbCloudApp.Repositories;
using AsbCloudApp.Requests; //using AsbCloudApp.Requests;
using AsbCloudApp.Services; //using AsbCloudApp.Services;
using AsbCloudDb.Model; //using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services.ProcessMaps.Report; //using AsbCloudInfrastructure.Services.ProcessMaps.Report;
using NSubstitute; //using NSubstitute;
using System; //using System;
using System.Collections.Generic; //using System.Collections.Generic;
using System.Linq; //using System.Linq;
using System.Threading; //using System.Threading;
using System.Threading.Tasks; //using System.Threading.Tasks;
using Xunit; //using Xunit;
namespace AsbCloudWebApi.Tests.Services.ProcessMaps; //namespace AsbCloudWebApi.Tests.Services.ProcessMaps;
public class ProcessMapReportDataSaubStatServiceTest //public class ProcessMapReportDataSaubStatServiceTest
{ //{
private IWellService wellService // private IWellService wellService
= Substitute.For<IWellService>(); // = Substitute.For<IWellService>();
private IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanBaseRepository // private IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanBaseRepository
= Substitute.For<IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell>>(); // = Substitute.For<IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell>>();
private IWellOperationRepository wellOperationRepository // private IWellOperationRepository wellOperationRepository
= Substitute.For<IWellOperationRepository>(); // = Substitute.For<IWellOperationRepository>();
private IWellOperationCategoryRepository wellOperationCategoryRepository // private IWellOperationCategoryRepository wellOperationCategoryRepository
= Substitute.For<IWellOperationCategoryRepository>(); // = Substitute.For<IWellOperationCategoryRepository>();
private IDataSaubStatRepository dataSaubStatRepository // private IDataSaubStatRepository dataSaubStatRepository
= Substitute.For<IDataSaubStatRepository>(); // = Substitute.For<IDataSaubStatRepository>();
private ProcessMapReportDrillingService service; // private ProcessMapReportDrillingService service;
private readonly static SimpleTimezoneDto timezone = new() { Hours = 2 }; // private readonly static SimpleTimezoneDto timezone = new() { Hours = 2 };
private static readonly DateTimeOffset dateStart = new(2024, 01, 01, 00, 11, 11, timezone.Offset); // private static readonly DateTimeOffset dateStart = new(2024, 01, 01, 00, 11, 11, timezone.Offset);
private readonly static WellDto well = new() // private readonly static WellDto well = new()
{ // {
Id = 1, // Id = 1,
IdTelemetry = 1, // IdTelemetry = 1,
Timezone = timezone // Timezone = timezone
}; // };
private readonly static IEnumerable<ProcessMapPlanDrillingDto> processMapPlan = new List<ProcessMapPlanDrillingDto>() // private readonly static IEnumerable<ProcessMapPlanBaseDto> processMapPlan = new List<ProcessMapPlanBaseDto>()
{ // {
new() { // new() {
DepthStart = 0, // DepthStart = 0,
DepthEnd = 100, // DepthEnd = 100,
IdMode = 1, // IdMode = 1,
IdWell = well.Id, // IdWell = well.Id,
IdWellSectionType = 1, // IdWellSectionType = 1,
AxialLoadPlan = 0.2, // AxialLoadPlan = 0.2,
AxialLoadLimitMax = 0.3, // AxialLoadLimitMax = 0.3,
DeltaPressurePlan = 0.4, // DeltaPressurePlan = 0.4,
DeltaPressureLimitMax = 0.5, // DeltaPressureLimitMax = 0.5,
TopDriveTorquePlan = 0.6, // TopDriveTorquePlan = 0.6,
TopDriveTorqueLimitMax = 0.7, // TopDriveTorqueLimitMax = 0.7,
TopDriveSpeedPlan = 0.8, // TopDriveSpeedPlan = 0.8,
TopDriveSpeedLimitMax = 0.9, // TopDriveSpeedLimitMax = 0.9,
FlowPlan = 0.10, // FlowPlan = 0.10,
FlowLimitMax = 0.11, // FlowLimitMax = 0.11,
RopPlan = 0.12, // RopPlan = 0.12,
UsageSaub = 0.12, // UsageSaub = 0.12,
UsageSpin = 0.14, // UsageSpin = 0.14,
Comment = "r", // Comment = "r",
}, // },
new() { // new() {
DepthStart = 0, // DepthStart = 0,
DepthEnd = 100, // DepthEnd = 100,
IdMode = 2, // IdMode = 2,
IdWell = well.Id, // IdWell = well.Id,
IdWellSectionType = 1, // IdWellSectionType = 1,
AxialLoadPlan = 0.12, // AxialLoadPlan = 0.12,
AxialLoadLimitMax = 0.13, // AxialLoadLimitMax = 0.13,
DeltaPressurePlan = 0.14, // DeltaPressurePlan = 0.14,
DeltaPressureLimitMax = 0.15, // DeltaPressureLimitMax = 0.15,
TopDriveTorquePlan = 0.16, // TopDriveTorquePlan = 0.16,
TopDriveTorqueLimitMax = 0.17, // TopDriveTorqueLimitMax = 0.17,
TopDriveSpeedPlan = 0.18, // TopDriveSpeedPlan = 0.18,
TopDriveSpeedLimitMax = 0.19, // TopDriveSpeedLimitMax = 0.19,
FlowPlan = 0.110, // FlowPlan = 0.110,
FlowLimitMax = 0.111, // FlowLimitMax = 0.111,
RopPlan = 0.112, // RopPlan = 0.112,
UsageSaub = 0.112, // UsageSaub = 0.112,
UsageSpin = 0.114, // UsageSpin = 0.114,
Comment = "s", // Comment = "s",
}, // },
new() { // new() {
DepthStart = 100, // DepthStart = 100,
DepthEnd = 200, // DepthEnd = 200,
IdMode = 1, // IdMode = 1,
IdWell = well.Id, // IdWell = well.Id,
IdWellSectionType = 1, // IdWellSectionType = 1,
AxialLoadPlan = 0.22, // AxialLoadPlan = 0.22,
AxialLoadLimitMax = 0.23, // AxialLoadLimitMax = 0.23,
DeltaPressurePlan = 0.24, // DeltaPressurePlan = 0.24,
DeltaPressureLimitMax = 0.25, // DeltaPressureLimitMax = 0.25,
TopDriveTorquePlan = 0.26, // TopDriveTorquePlan = 0.26,
TopDriveTorqueLimitMax = 0.27, // TopDriveTorqueLimitMax = 0.27,
TopDriveSpeedPlan = 0.28, // TopDriveSpeedPlan = 0.28,
TopDriveSpeedLimitMax = 0.29, // TopDriveSpeedLimitMax = 0.29,
FlowPlan = 0.210, // FlowPlan = 0.210,
FlowLimitMax = 0.211, // FlowLimitMax = 0.211,
RopPlan = 0.212, // RopPlan = 0.212,
UsageSaub = 0.212, // UsageSaub = 0.212,
UsageSpin = 0.214, // UsageSpin = 0.214,
Comment = "r", // Comment = "r",
}, // },
new() { // new() {
DepthStart = 100, // DepthStart = 100,
DepthEnd = 200, // DepthEnd = 200,
IdMode = 2, // IdMode = 2,
IdWell = well.Id, // IdWell = well.Id,
IdWellSectionType = 1, // IdWellSectionType = 1,
AxialLoadPlan = 0.32, // AxialLoadPlan = 0.32,
AxialLoadLimitMax = 0.33, // AxialLoadLimitMax = 0.33,
DeltaPressurePlan = 0.34, // DeltaPressurePlan = 0.34,
DeltaPressureLimitMax = 0.35, // DeltaPressureLimitMax = 0.35,
TopDriveTorquePlan = 0.36, // TopDriveTorquePlan = 0.36,
TopDriveTorqueLimitMax = 0.37, // TopDriveTorqueLimitMax = 0.37,
TopDriveSpeedPlan = 0.38, // TopDriveSpeedPlan = 0.38,
TopDriveSpeedLimitMax = 0.39, // TopDriveSpeedLimitMax = 0.39,
FlowPlan = 0.310, // FlowPlan = 0.310,
FlowLimitMax = 0.311, // FlowLimitMax = 0.311,
RopPlan = 0.312, // RopPlan = 0.312,
UsageSaub = 0.312, // UsageSaub = 0.312,
UsageSpin = 0.314, // UsageSpin = 0.314,
Comment = "s", // Comment = "s",
}, // },
}; // };
private readonly static IEnumerable<ChangeLogDto<ProcessMapPlanDrillingDto>> processMapPlanChangeLog = processMapPlan.Select(p => new ChangeLogDto<ProcessMapPlanDrillingDto>() // private readonly static IEnumerable<ChangeLogDto<ProcessMapPlanDrillingDto>> processMapPlanChangeLog = processMapPlan.Select(p => new ChangeLogDto<ProcessMapPlanDrillingDto>()
{ // {
Item = p, // Item = p,
}); // });
private readonly static IEnumerable<WellOperationDto> operations = new List<WellOperationDto>() // private readonly static IEnumerable<WellOperationDto> operations = new List<WellOperationDto>()
{ // {
new() // new()
{ // {
Id = 1, // Id = 1,
IdWell = well.Id, // IdWell = well.Id,
IdWellSectionType = 1, // IdWellSectionType = 1,
IdCategory = WellOperationCategory.IdRotor, // IdCategory = WellOperationCategory.IdRotor,
IdParentCategory = WellOperationCategory.IdMechanicalDrilling, // IdParentCategory = WellOperationCategory.IdMechanicalDrilling,
IdType = WellOperation.IdOperationTypeFact, // IdType = WellOperation.IdOperationTypeFact,
DepthStart = 0, // DepthStart = 0,
DepthEnd = 10, // DepthEnd = 10,
DateStart = dateStart, // DateStart = dateStart,
DurationHours = 1, // DurationHours = 1,
}, // },
new() // new()
{ // {
Id = 1, // Id = 1,
IdWell = well.Id, // IdWell = well.Id,
IdWellSectionType = 2, // IdWellSectionType = 2,
IdCategory = WellOperationCategory.IdRotor, // IdCategory = WellOperationCategory.IdRotor,
IdParentCategory = WellOperationCategory.IdMechanicalDrilling, // IdParentCategory = WellOperationCategory.IdMechanicalDrilling,
IdType = WellOperation.IdOperationTypeFact, // IdType = WellOperation.IdOperationTypeFact,
DepthStart = 50, // DepthStart = 50,
DepthEnd = 100, // DepthEnd = 100,
DateStart = dateStart, // DateStart = dateStart,
DurationHours = 1, // DurationHours = 1,
} // }
}; // };
private readonly static IEnumerable<WellOperationCategoryDto> operationCategories = new List<WellOperationCategoryDto>() // private readonly static IEnumerable<WellOperationCategoryDto> operationCategories = new List<WellOperationCategoryDto>()
{ // {
new(){Id = WellOperationCategory.IdRotor, IdParent = WellOperationCategory.IdMechanicalDrilling, Name = "РОТОР"}, // new(){Id = WellOperationCategory.IdRotor, IdParent = WellOperationCategory.IdMechanicalDrilling, Name = "РОТОР"},
new(){Id = WellOperationCategory.IdSlide, IdParent = WellOperationCategory.IdMechanicalDrilling, Name = "СЛАЙД"}, // new(){Id = WellOperationCategory.IdSlide, IdParent = WellOperationCategory.IdMechanicalDrilling, Name = "СЛАЙД"},
}; // };
private readonly static IEnumerable<WellSectionTypeDto> sectionTypes = new List<WellSectionTypeDto>() { // private readonly static IEnumerable<WellSectionTypeDto> sectionTypes = new List<WellSectionTypeDto>() {
new(){ Id = 1, Caption = "Секция 1"}, // new(){ Id = 1, Caption = "Секция 1"},
new(){ Id = 2, Caption = "Секция 2"}, // new(){ Id = 2, Caption = "Секция 2"},
new(){ Id = 3, Caption = "Секция 3"}, // new(){ Id = 3, Caption = "Секция 3"},
new(){ Id = 4, Caption = "Секция 4"}, // new(){ Id = 4, Caption = "Секция 4"},
}; // };
private readonly static IEnumerable<DataSaubStatDto> dataSaubStat = new List<DataSaubStatDto>() { // private readonly static IEnumerable<DataSaubStatDto> dataSaubStat = new List<DataSaubStatDto>() {
new(){ // new(){
Id = 1, // Id = 1,
IdTelemetry = 1, // IdTelemetry = 1,
IdCategory = WellOperationCategory.IdRotor, // IdCategory = WellOperationCategory.IdRotor,
DateStart = dateStart, // DateStart = dateStart,
DateEnd = dateStart.AddHours(3.25), // DateEnd = dateStart.AddHours(3.25),
DepthStart = 0, // DepthStart = 0,
DepthEnd = 20, // DepthEnd = 20,
Speed = 0.1, // Speed = 0.1,
BlockSpeedSp = 0.2, // BlockSpeedSp = 0.2,
Pressure = 0.3, // Pressure = 0.3,
PressureIdle = 0.4, // PressureIdle = 0.4,
PressureSp = 0.5, // PressureSp = 0.5,
AxialLoad = 0.6, // AxialLoad = 0.6,
AxialLoadSp = 0.7, // AxialLoadSp = 0.7,
AxialLoadLimitMax = 0.8, // AxialLoadLimitMax = 0.8,
RotorTorque = 0.9, // RotorTorque = 0.9,
RotorTorqueSp = 0.11, // RotorTorqueSp = 0.11,
RotorTorqueLimitMax = 0.12, // RotorTorqueLimitMax = 0.12,
RotorSpeed = 0.14, // RotorSpeed = 0.14,
Flow = 0.17, // Flow = 0.17,
IdFeedRegulator = LimitingParameterDto.AxialLoad, // IdFeedRegulator = LimitingParameterDto.AxialLoad,
EnabledSubsystems = 15, // EnabledSubsystems = 15,
HasOscillation = false, // HasOscillation = false,
}, // },
new(){ // new(){
Id = 1, // Id = 1,
IdTelemetry = 1, // IdTelemetry = 1,
IdCategory = WellOperationCategory.IdRotor, // IdCategory = WellOperationCategory.IdRotor,
DateStart = dateStart.AddHours(3.25), // DateStart = dateStart.AddHours(3.25),
DateEnd = dateStart.AddHours(4.25), // DateEnd = dateStart.AddHours(4.25),
DepthStart = 20, // DepthStart = 20,
DepthEnd = 190, // DepthEnd = 190,
Speed = 0.21, // Speed = 0.21,
BlockSpeedSp = 0.22, // BlockSpeedSp = 0.22,
Pressure = 0.23, // Pressure = 0.23,
PressureIdle = 0.24, // PressureIdle = 0.24,
PressureSp = 0.25, // PressureSp = 0.25,
AxialLoad = 0.26, // AxialLoad = 0.26,
AxialLoadSp = 0.27, // AxialLoadSp = 0.27,
AxialLoadLimitMax = 0.28, // AxialLoadLimitMax = 0.28,
RotorTorque = 0.29, // RotorTorque = 0.29,
RotorTorqueSp = 0.211, // RotorTorqueSp = 0.211,
RotorTorqueLimitMax = 0.212, // RotorTorqueLimitMax = 0.212,
RotorSpeed = 0.214, // RotorSpeed = 0.214,
Flow = 0.217, // Flow = 0.217,
IdFeedRegulator = LimitingParameterDto.AxialLoad, // IdFeedRegulator = LimitingParameterDto.AxialLoad,
EnabledSubsystems = 15, // EnabledSubsystems = 15,
HasOscillation = false, // HasOscillation = false,
}, // },
new(){ // new(){
Id = 1, // Id = 1,
IdTelemetry = 1, // IdTelemetry = 1,
IdCategory = WellOperationCategory.IdRotor, // IdCategory = WellOperationCategory.IdRotor,
DateStart = dateStart.AddHours(4.25), // DateStart = dateStart.AddHours(4.25),
DateEnd = dateStart.AddHours(16), // DateEnd = dateStart.AddHours(16),
DepthStart = 190, // DepthStart = 190,
DepthEnd = 290, // DepthEnd = 290,
Speed = 0.31, // Speed = 0.31,
BlockSpeedSp = 0.32, // BlockSpeedSp = 0.32,
Pressure = 0.33, // Pressure = 0.33,
PressureIdle = 0.34, // PressureIdle = 0.34,
PressureSp = 0.35, // PressureSp = 0.35,
AxialLoad = 0.36, // AxialLoad = 0.36,
AxialLoadSp = 0.37, // AxialLoadSp = 0.37,
AxialLoadLimitMax = 0.38, // AxialLoadLimitMax = 0.38,
RotorTorque = 0.39, // RotorTorque = 0.39,
RotorTorqueSp = 0.231, // RotorTorqueSp = 0.231,
RotorTorqueLimitMax = 0.232, // RotorTorqueLimitMax = 0.232,
RotorSpeed = 0.234, // RotorSpeed = 0.234,
Flow = 0.237, // Flow = 0.237,
IdFeedRegulator = LimitingParameterDto.AxialLoad, // IdFeedRegulator = LimitingParameterDto.AxialLoad,
EnabledSubsystems = 15, // EnabledSubsystems = 15,
HasOscillation = false, // HasOscillation = false,
} // }
}; // };
public ProcessMapReportDataSaubStatServiceTest() // public ProcessMapReportDataSaubStatServiceTest()
{ // {
wellService.GetOrDefaultAsync(Arg.Any<int>(), Arg.Any<CancellationToken>()) // wellService.GetOrDefaultAsync(Arg.Any<int>(), Arg.Any<CancellationToken>())
.Returns(well); // .Returns(well);
processMapPlanBaseRepository.GetCurrent(Arg.Any<ProcessMapPlanBaseRequestWithWell>(), Arg.Any<CancellationToken>()) // processMapPlanBaseRepository.GetCurrent(Arg.Any<ProcessMapPlanBaseRequestWithWell>(), Arg.Any<CancellationToken>())
.Returns(processMapPlan); // .Returns(processMapPlan);
processMapPlanBaseRepository.GetChangeLogForDate(Arg.Any<ProcessMapPlanBaseRequestWithWell>(), null, Arg.Any<CancellationToken>()) // processMapPlanBaseRepository.GetChangeLogForDate(Arg.Any<ProcessMapPlanBaseRequestWithWell>(), null, Arg.Any<CancellationToken>())
.Returns(processMapPlanChangeLog); // .Returns(processMapPlanChangeLog);
wellOperationRepository.GetAsync(Arg.Any<WellOperationRequest>(), Arg.Any<CancellationToken>()) // wellOperationRepository.GetAsync(Arg.Any<WellOperationRequest>(), Arg.Any<CancellationToken>())
.Returns(operations); // .Returns(operations);
wellOperationRepository.GetSectionTypes() // wellOperationRepository.GetSectionTypes()
.Returns(sectionTypes); // .Returns(sectionTypes);
wellOperationCategoryRepository.Get(Arg.Any<bool>()) // wellOperationCategoryRepository.Get(Arg.Any<bool>())
.Returns(operationCategories); // .Returns(operationCategories);
dataSaubStatRepository.GetAsync(Arg.Any<int>(), Arg.Any<DateTimeOffset>(), Arg.Any<DateTimeOffset>(), Arg.Any<CancellationToken>()) // dataSaubStatRepository.GetAsync(Arg.Any<int>(), Arg.Any<DateTimeOffset>(), Arg.Any<DateTimeOffset>(), Arg.Any<CancellationToken>())
.Returns(dataSaubStat); // .Returns(dataSaubStat);
service = new ProcessMapReportDrillingService(wellService, processMapPlanBaseRepository, dataSaubStatRepository, wellOperationRepository, wellOperationCategoryRepository); // service = new ProcessMapReportDrillingService(wellService, processMapPlanBaseRepository, dataSaubStatRepository, wellOperationRepository, wellOperationCategoryRepository);
} // }
[Fact] // [Fact]
public async Task GetAsync_return_data() // public async Task GetAsync_return_data()
{ // {
// arrange // // arrange
DataSaubStatRequest request = new() { }; // DataSaubStatRequest request = new() { };
// act // // act
var result = await service.GetAsync(well.Id, request, CancellationToken.None); // var result = await service.GetAsync(well.Id, request, CancellationToken.None);
// assert // // assert
Assert.NotEmpty(result); // Assert.NotEmpty(result);
} // }
} //}