From f2f16221c8ed91d0aa55af04621e08325d419015 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Mon, 20 Jun 2022 12:43:59 +0500 Subject: [PATCH] fix tests. --- .../Detectors/DetectorDrillingRotor.cs | 3 ++- .../Detectors/DetectorDrillingSlide.cs | 3 ++- .../AsbCloudWebApi.Tests.csproj | 3 +++ .../DetectedOperationServiceTest.cs | 19 +++++++++++++------ AsbCloudWebApi.Tests/TestHelpter.cs | 6 +++++- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorDrillingRotor.cs b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorDrillingRotor.cs index a42dae89..6810a05b 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorDrillingRotor.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorDrillingRotor.cs @@ -10,6 +10,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors const double minRotorSpeed = 5; //об/мин const double ticksPerHour = 60 * 60 * 10_000_000d; const double minPressure = 25; + const double minDeltaDepth = 0.02; public DetectorDrillingRotor() : base(2) { @@ -22,7 +23,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors var firstItem = telemetry[position]; var deltaDepth = firstItem.WellDepth - firstItem.BitDepth; if (deltaDepth is not null && - System.Math.Abs((float)deltaDepth) > 1d) + System.Math.Abs((float)deltaDepth) > minDeltaDepth) return false; if(firstItem.RotorSpeed > minRotorSpeed) diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorDrillingSlide.cs b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorDrillingSlide.cs index 8fd1579f..89f20ae6 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorDrillingSlide.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorDrillingSlide.cs @@ -10,6 +10,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors const double minRotorSpeed = 5; //об/мин const double ticksPerHour = 60 * 60 * 10_000_000d; const double minPressure = 25; + const double minDeltaDepth = 0.02; public DetectorDrillingSlide() : base(3) { @@ -21,7 +22,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors var firstItem = telemetry[position]; var deltaDepth = firstItem.WellDepth - firstItem.BitDepth; if (deltaDepth is not null && - System.Math.Abs((float)deltaDepth) > 1d) + System.Math.Abs((float)deltaDepth) > minDeltaDepth) return false; if(firstItem.RotorSpeed < minRotorSpeed) diff --git a/AsbCloudWebApi.Tests/AsbCloudWebApi.Tests.csproj b/AsbCloudWebApi.Tests/AsbCloudWebApi.Tests.csproj index eca24b3f..3069a4b2 100644 --- a/AsbCloudWebApi.Tests/AsbCloudWebApi.Tests.csproj +++ b/AsbCloudWebApi.Tests/AsbCloudWebApi.Tests.csproj @@ -7,6 +7,9 @@ + + + diff --git a/AsbCloudWebApi.Tests/ServicesTests/DetectedOperationServiceTest.cs b/AsbCloudWebApi.Tests/ServicesTests/DetectedOperationServiceTest.cs index 246a1da4..e169049d 100644 --- a/AsbCloudWebApi.Tests/ServicesTests/DetectedOperationServiceTest.cs +++ b/AsbCloudWebApi.Tests/ServicesTests/DetectedOperationServiceTest.cs @@ -1,4 +1,5 @@ using AsbCloudApp.Data; +using AsbCloudApp.Requests; using AsbCloudApp.Services; using AsbCloudDb.Model; using AsbCloudInfrastructure.Services; @@ -19,6 +20,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests private readonly AsbCloudDbContext context; private readonly CacheDb cacheDb; private readonly DetectedOperationService service; + private readonly DetectedOperationRequest request; private Deposit deposit = new Deposit { Id = 1, Caption = "Депозит 1" }; private Cluster cluster = new Cluster { Id = 1, Caption = "Кластер 1", IdDeposit = 1, Timezone = new SimpleTimezone() }; private WellDto wellDto = new WellDto @@ -126,6 +128,11 @@ namespace AsbCloudWebApi.Tests.ServicesTests var scheduleService = new ScheduleService(context, wellServiceMock.Object); service = new DetectedOperationService(context, wellServiceMock.Object, operationValueService, scheduleService); + request = new DetectedOperationRequest + { + IdWell = 1, + IdCategory = 1 + }; AsbCloudInfrastructure.DependencyInjection.MapsterSetup(); } @@ -137,39 +144,39 @@ namespace AsbCloudWebApi.Tests.ServicesTests [Fact] public async Task Count_grouping_by_driller() { - var list = await service.GetAsync(1, null, CancellationToken.None); + var list = await service.GetAsync(request, CancellationToken.None); Assert.Equal(2, list.Stats.First().Count); } [Fact] public async Task AvgVal_grouping_by_driller() { - var list = await service.GetAsync(1, null, CancellationToken.None); + var list = await service.GetAsync(request, CancellationToken.None); Assert.Equal(30, list.Stats.First().AverageValue); } [Fact] public async Task AvgTargetVal_grouping_by_driller() { - var list = await service.GetAsync(1, null, CancellationToken.None); + var list = await service.GetAsync(request, CancellationToken.None); Assert.Equal(100, list.Stats.First().AverageTargetValue); } [Fact] public async Task Loss_grouping_by_driller() { - var list = await service.GetAsync(1, null, CancellationToken.None); + var list = await service.GetAsync(request, CancellationToken.None); Assert.Equal(0, list.Stats.First().Loss); } [Fact] public async Task Efficiency_grouping_by_driller() { - var list = await service.GetAsync(1, null, CancellationToken.None); + var list = await service.GetAsync(request, CancellationToken.None); Assert.Equal(100, list.Stats.First().Efficiency); } [Fact] public async Task GroupCount_grouping_by_driller() { - var list = await service.GetAsync(1, null, CancellationToken.None); + var list = await service.GetAsync(request, CancellationToken.None); Assert.Equal(1, list.Stats.Count()); } diff --git a/AsbCloudWebApi.Tests/TestHelpter.cs b/AsbCloudWebApi.Tests/TestHelpter.cs index c9b61baa..ee4ea79c 100644 --- a/AsbCloudWebApi.Tests/TestHelpter.cs +++ b/AsbCloudWebApi.Tests/TestHelpter.cs @@ -1,5 +1,6 @@ using AsbCloudDb.Model; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Diagnostics; namespace AsbCloudWebApi.Tests { @@ -8,10 +9,13 @@ namespace AsbCloudWebApi.Tests public static AsbCloudDbContext MakeTestContext() { var options = new DbContextOptionsBuilder() + //.UseInMemoryDatabase(System.Guid.NewGuid().ToString()) + //.ConfigureWarnings(configBuilder => + // configBuilder.Ignore(InMemoryEventId.TransactionIgnoredWarning)) .UseNpgsql("Host=localhost;Database=tests;Username=postgres;Password=q;Persist Security Info=True;Include Error Detail=True") .Options; var context = new AsbCloudDbContext(options); - context.Database.EnsureDeleted(); + //context.Database.EnsureDeleted(); context.Database.EnsureCreated(); return context; }