From e2e861262809566f49d7a76b34050a6d01bc9054 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Tue, 8 Oct 2024 12:14:10 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A2=D0=B5=D1=81=D1=82=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20DataSaubStatDrillingQuality.=20=D0=9D=D0=B0=D1=87=D0=B0?= =?UTF-8?q?=D0=BB=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataSaubStatDtillingQualityServiceTest.cs | 269 ++++++++++++++++++ .../DataSaubStatServiceTest.cs | 2 +- 2 files changed, 270 insertions(+), 1 deletion(-) create mode 100644 AsbCloudInfrastructure.Tests/Services/DataSaubStat/DataSaubStatDtillingQualityServiceTest.cs rename AsbCloudInfrastructure.Tests/Services/{ => DataSaubStat}/DataSaubStatServiceTest.cs (99%) diff --git a/AsbCloudInfrastructure.Tests/Services/DataSaubStat/DataSaubStatDtillingQualityServiceTest.cs b/AsbCloudInfrastructure.Tests/Services/DataSaubStat/DataSaubStatDtillingQualityServiceTest.cs new file mode 100644 index 00000000..4a6b876b --- /dev/null +++ b/AsbCloudInfrastructure.Tests/Services/DataSaubStat/DataSaubStatDtillingQualityServiceTest.cs @@ -0,0 +1,269 @@ +using AsbCloudApp.Data; +using AsbCloudApp.Data.DetectedOperation; +using AsbCloudApp.Data.SAUB; +using AsbCloudApp.Repositories; +using AsbCloudApp.Requests; +using AsbCloudApp.Services; +using AsbCloudInfrastructure.Services; +using Mapster; +using NSubstitute; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace AsbCloudInfrastructure.Tests.Services; + +public class DataSaubStatDtillingQualityServiceTest +{ + private readonly int Gap = 5; + private readonly IDataSaubStatRepository dataSaubStatRepositoryMock = Substitute.For>(); + private readonly ITelemetryDataCache telemetryDataCacheMock = Substitute.For>(); + private readonly IDetectedOperationRepository detectedOperationRepositoryMock = Substitute.For(); + private readonly ITelemetryDataSaubService dataSaubServiceMock = Substitute.For(); + + private DataSaubStatDrillingQualityService dataSaubStatService; + + private int[] idTelemetries = [1]; + private IEnumerable dataSaubStatDrillingQualityDtos = new List() + { + new DataSaubStatDrillingQualityDto { + Id = 1, + DateEnd = DateTime.UtcNow, + DateStart = DateTime.UtcNow.AddHours(-1), + DepthEnd = 2, + DepthStart = 1, + IdFeedRegulator = 1, + IdTelemetry = 1 + }, + new DataSaubStatDrillingQualityDto { + Id = 2, + DateEnd = DateTime.UtcNow, + DateStart = DateTime.UtcNow.AddHours(-1), + DepthEnd = 3, + DepthStart = 2, + IdFeedRegulator = 2, + IdTelemetry = 2, + }, + new DataSaubStatDrillingQualityDto { + Id = 3, + DateEnd = DateTime.UtcNow, + DateStart = DateTime.UtcNow.AddHours(-1), + DepthEnd = 4, + DepthStart = 3, + IdFeedRegulator = 3, + IdTelemetry = 3, + }, + }; + + private List detectedOperationDtos = new List() { + new DetectedOperationDto { + Id = 1, + DateEnd = DateTimeOffset.UtcNow, + DateStart = DateTimeOffset.UtcNow.AddHours(-1), + DepthStart = 1, + DepthEnd = 2, + IdCategory = 5002, + IdTelemetry = 1, + Value = 1, + IdEditor = 1, + IdUserAtStart = 1 + } + }; + + private List telemetryDataSaubDtos = new List { + new TelemetryDataSaubDto() + { + IdTelemetry = 1, + DateTime = DateTime.UtcNow.AddMinutes(-30), + AxialLoad = 1, + AxialLoadLimitMax = 1, + AxialLoadSp = 1, + BitDepth = 1, + BlockPosition = 1, + BlockPositionMax = 1, + BlockPositionMin = 1, + BlockSpeed = 1, + BlockSpeedSp = 1, + BlockSpeedSpDevelop = 1, + BlockSpeedSpRotor = 1, + BlockSpeedSpSlide = 1, + Flow = 1, + FlowDeltaLimitMax = 1, + FlowIdle = 1, + HookWeight = 1, + HookWeightIdle = 1, + HookWeightLimitMax = 1, + HookWeightLimitMin = 1, + IdFeedRegulator = 1, + IdUser = 1, + Mode = 1, + Mse = 1, + MseState = 1, + Pressure = 1, + PressureDeltaLimitMax = 1, + PressureIdle = 1, + PressureSp = 1, + PressureSpDevelop = 1, + PressureSpRotor = 1, + PressureSpSlide = 1, + Pump0Flow = 1, + Pump1Flow = 1, + Pump2Flow = 1, + RotorSpeed = 1, + RotorTorque = 1, + RotorTorqueIdle = 1, + RotorTorqueSp = 1, + RotorTorqueLimitMax = 1, + WellDepth = 10, + } + }; + + public DataSaubStatDtillingQualityServiceTest() + { + telemetryDataCacheMock + .GetIds(Arg.Any()) + .Returns(idTelemetries); + + dataSaubStatRepositoryMock + .GetLastsAsync(Arg.Any(), Arg.Any()) + .Returns(dataSaubStatDrillingQualityDtos); + + var telemetrySaubDto = telemetryDataSaubDtos.FirstOrDefault(); + if (telemetrySaubDto != null) + { + var telemetrySaubDto1 = CreateTelemetryDataSaubItem(telemetrySaubDto, 1, 1); + telemetryDataSaubDtos.Add(telemetrySaubDto1); + + var telemetrySaubDto2 = telemetrySaubDto.Adapt(); + telemetrySaubDto2.WellDepth = 2; + telemetrySaubDto2.BitDepth = 2; + telemetrySaubDto2.IdFeedRegulator = 1; + telemetrySaubDto2.DateTime = telemetrySaubDto1.DateTime.AddMinutes(20); + telemetryDataSaubDtos.Add(telemetrySaubDto2); + + var telemetrySaubDto3 = telemetrySaubDto.Adapt(); + telemetrySaubDto3.WellDepth = 2; + telemetrySaubDto3.BitDepth = 2; + telemetrySaubDto3.IdFeedRegulator = 1; + telemetrySaubDto3.DateTime = telemetrySaubDto2.DateTime.AddMinutes(20); + telemetryDataSaubDtos.Add(telemetrySaubDto3); + + + } + + dataSaubServiceMock + .Get(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()) + .Returns(telemetryDataSaubDtos); + + dataSaubStatService = new DataSaubStatDrillingQualityService( + dataSaubStatRepositoryMock, + telemetryDataCacheMock, + dataSaubServiceMock); + } + + private TelemetryDataSaubDto CreateTelemetryDataSaubItem( + TelemetryDataSaubDto telemetrySaubDto, + float wellDepth, + float bitDepth) + { + var telemetrySaubDto1 = telemetrySaubDto.Adapt(); + telemetrySaubDto1.WellDepth = wellDepth; + telemetrySaubDto1.BitDepth = bitDepth; + telemetrySaubDto1.IdFeedRegulator = 1; + telemetrySaubDto1.DateTime = DateTime.UtcNow.AddMinutes(20); + + return telemetrySaubDto1; + } + + [Fact] + public async Task Create_1DataSaubStatItems_ShouldReturn__Success() + { + var insertedDataSaubStatCount = 1; + + + + + dataSaubStatRepositoryMock + .InsertRangeAsync(Arg.Any>(), Arg.Any()) + .Returns(insertedDataSaubStatCount); + + Action action = (message, percent) => + { + //assert + Assert.NotNull(percent); + Assert.InRange(percent.Value, 0.0, 1.0); + }; + + //act + await dataSaubStatService.CreateStatAsync(Gap, action, CancellationToken.None); + + //assert + await dataSaubStatRepositoryMock.Received().InsertRangeAsync( + Arg.Is>(l => l.Count() == insertedDataSaubStatCount), + Arg.Any()); + } + + + + //[Fact] + //public async Task Create_2DataSaubStatItems_ShouldReturn__Success() + //{ + // var insertedDataSaubStatCount = 2; + + // var detectedOperationDto = detectedOperationDtos.FirstOrDefault(); + // if (detectedOperationDto != null) + // { + // var detectedOperationDto1 = detectedOperationDto.Adapt(); + // detectedOperationDto1.DateStart = DateTimeOffset.UtcNow.AddMinutes(1); + // detectedOperationDto1.DateEnd = DateTimeOffset.UtcNow.AddHours(1); + + // detectedOperationDtos.Add(detectedOperationDto1); + // } + + // var telemetryDataSaubDto = telemetryDataSaubDtos.LastOrDefault(); + // if (telemetryDataSaubDto != null) + // { + // var telemetryDataSaubDto1 = telemetryDataSaubDto.Adapt(); + // telemetryDataSaubDto1.DateTime = DateTime.UtcNow.AddMinutes(10); + // telemetryDataSaubDto1.WellDepth = telemetryDataSaubDto.WellDepth + 1; + + // var telemetryDataSaubDto2 = telemetryDataSaubDto.Adapt(); + // telemetryDataSaubDto2.DateTime = DateTime.UtcNow.AddMinutes(20); + // telemetryDataSaubDto2.WellDepth = telemetryDataSaubDto1.WellDepth + 1; + + // var telemetryDataSaubDto3 = telemetryDataSaubDto.Adapt(); + // telemetryDataSaubDto3.DateTime = DateTime.UtcNow.AddMinutes(30); + // telemetryDataSaubDto3.WellDepth = telemetryDataSaubDto2.WellDepth + 1; + + // telemetryDataSaubDtos.Add(telemetryDataSaubDto1); + // telemetryDataSaubDtos.Add(telemetryDataSaubDto2); + // telemetryDataSaubDtos.Add(telemetryDataSaubDto3); + // } + + // detectedOperationRepositoryMock + // .Get(Arg.Any(), Arg.Any()) + // .Returns(detectedOperationDtos); + + // dataSaubStatRepositoryMock + // .InsertRangeAsync(Arg.Any>(), Arg.Any()) + // .Returns(insertedDataSaubStatCount); + + // Action action = (message, percent) => + // { + // //assert + // Assert.NotNull(percent); + // Assert.InRange(percent.Value, 0.0, 1.0); + // }; + + // //act + // await dataSaubStatService.CreateStatAsync(Gap, action, CancellationToken.None); + + // //assert + // await dataSaubStatRepositoryMock.Received().InsertRangeAsync( + // Arg.Is>(l => l.Count() == insertedDataSaubStatCount), + // Arg.Any()); + //} +} \ No newline at end of file diff --git a/AsbCloudInfrastructure.Tests/Services/DataSaubStatServiceTest.cs b/AsbCloudInfrastructure.Tests/Services/DataSaubStat/DataSaubStatServiceTest.cs similarity index 99% rename from AsbCloudInfrastructure.Tests/Services/DataSaubStatServiceTest.cs rename to AsbCloudInfrastructure.Tests/Services/DataSaubStat/DataSaubStatServiceTest.cs index 2c7cf7ce..3842026e 100644 --- a/AsbCloudInfrastructure.Tests/Services/DataSaubStatServiceTest.cs +++ b/AsbCloudInfrastructure.Tests/Services/DataSaubStat/DataSaubStatServiceTest.cs @@ -14,7 +14,7 @@ using System.Threading; using System.Threading.Tasks; using Xunit; -namespace AsbCloudInfrastructure.Tests.Services; +namespace AsbCloudInfrastructure.Tests.Services.DataSaubStat; public class DataSaubStatServiceTest {