From 90a782826ca4985fc12da6398c9babcb92b6e2b1 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Mon, 19 Aug 2024 10:57:31 +0500 Subject: [PATCH] rename unit tests project --- AsbCloud.sln | 2 +- .../AsbCloudInfrastructure.Tests.csproj | 0 .../AspExtensions.cs | 2 +- .../Background/BackgroundWorkerTest.cs | 2 +- .../PeriodicBackgroundWorkerTest.cs | 4 +- .../Background/WorkTest.cs | 2 +- .../CommonExtensions.cs | 2 +- .../ReflectionExtensions.cs | 7 +- .../Services/DailyReportServiceTest.cs | 2 +- .../Services/DataSaubStatServiceTest.cs | 2 +- .../Detectors/DetectorConditioning.cs | 2 +- .../Detectors/DetectorDrillingTests.cs | 178 +++++++++--------- .../Detectors/DetectorFlashingTests.cs | 2 +- .../Detectors/DetectorSlipsTimeTests.cs | 87 +++++++++ .../EnabledSubsystemsTests.cs | 42 +++++ .../Services/FileServiceTest.cs | 2 +- .../Services/HelpPageServiceTest.cs | 2 +- .../EmailNotificationTransportServiceTests.cs | 2 +- ...ProcessMapReportDataSaubStatServiceTest.cs | 0 .../SAUB/TelemetryDataSaubCacheTests.cs | 4 +- .../TrajectoryFactManualTemplate.xlsx | Bin .../Templates/TrajectoryPlanTemplate.xlsx | Bin .../Trajectory/TrajectoryExportTest.cs | 10 +- .../Trajectory/TrajectoryParserTest.cs | 44 +++++ .../TrajectoryVisualizationServiceTest.cs | 4 +- .../WellCompositeOperationServiceTest.cs | 2 +- .../Services/WellFinalDocumentsServiceTest.cs | 2 +- .../Services/WellOperationServiceTest.cs | 4 +- .../Services/WellboreServiceTest.cs | 2 +- .../XLExtensionsTests.cs | 169 +++++++++++++++++ .../readme.md | 0 .../Detectors/DetectorSlipsTimeTests.cs | 86 --------- .../EnabledSubsystemsTests.cs | 42 ----- .../Trajectory/TrajectoryParserTest.cs | 45 ----- AsbCloudWebApi.Tests/XLExtensionsTests.cs | 170 ----------------- 35 files changed, 460 insertions(+), 466 deletions(-) rename AsbCloudWebApi.Tests/AsbCloudWebApi.Tests.csproj => AsbCloudInfrastructure.Tests/AsbCloudInfrastructure.Tests.csproj (100%) rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/AspExtensions.cs (92%) rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/Background/BackgroundWorkerTest.cs (98%) rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/Background/PeriodicBackgroundWorkerTest.cs (95%) rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/Background/WorkTest.cs (99%) rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/CommonExtensions.cs (88%) rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/ReflectionExtensions.cs (88%) rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/Services/DailyReportServiceTest.cs (99%) rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/Services/DataSaubStatServiceTest.cs (99%) rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/Services/DetectedOperations/Detectors/DetectorConditioning.cs (97%) rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/Services/DetectedOperations/Detectors/DetectorDrillingTests.cs (66%) rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/Services/DetectedOperations/Detectors/DetectorFlashingTests.cs (97%) create mode 100644 AsbCloudInfrastructure.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs create mode 100644 AsbCloudInfrastructure.Tests/Services/DetectedOperations/EnabledSubsystemsTests.cs rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/Services/FileServiceTest.cs (99%) rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/Services/HelpPageServiceTest.cs (98%) rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/Services/Notification/EmailNotificationTransportServiceTests.cs (97%) rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/Services/ProcessMaps/ProcessMapReportDataSaubStatServiceTest.cs (100%) rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/Services/SAUB/TelemetryDataSaubCacheTests.cs (95%) rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/Services/Trajectory/Templates/TrajectoryFactManualTemplate.xlsx (100%) rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/Services/Trajectory/Templates/TrajectoryPlanTemplate.xlsx (100%) rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/Services/Trajectory/TrajectoryExportTest.cs (98%) create mode 100644 AsbCloudInfrastructure.Tests/Services/Trajectory/TrajectoryParserTest.cs rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/Services/TrajectoryVisualizationServiceTest.cs (98%) rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/Services/WellCompositeOperation/WellCompositeOperationServiceTest.cs (99%) rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/Services/WellFinalDocumentsServiceTest.cs (99%) rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/Services/WellOperationServiceTest.cs (97%) rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/Services/WellboreServiceTest.cs (99%) create mode 100644 AsbCloudInfrastructure.Tests/XLExtensionsTests.cs rename {AsbCloudWebApi.Tests => AsbCloudInfrastructure.Tests}/readme.md (100%) delete mode 100644 AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs delete mode 100644 AsbCloudWebApi.Tests/Services/DetectedOperations/EnabledSubsystemsTests.cs delete mode 100644 AsbCloudWebApi.Tests/Services/Trajectory/TrajectoryParserTest.cs delete mode 100644 AsbCloudWebApi.Tests/XLExtensionsTests.cs diff --git a/AsbCloud.sln b/AsbCloud.sln index cbdae082..43aac10f 100644 --- a/AsbCloud.sln +++ b/AsbCloud.sln @@ -11,7 +11,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AsbCloudInfrastructure", "A EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AsbCloudDb", "AsbCloudDb\AsbCloudDb.csproj", "{40FBD29B-724B-4496-B5D9-1A5D14102456}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AsbCloudWebApi.Tests", "AsbCloudWebApi.Tests\AsbCloudWebApi.Tests.csproj", "{9CF6FBB1-9AF5-45AB-A521-24F11A79B540}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AsbCloudInfrastructure.Tests", "AsbCloudInfrastructure.Tests\AsbCloudInfrastructure.Tests.csproj", "{9CF6FBB1-9AF5-45AB-A521-24F11A79B540}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SignalRTestClient", "SignalRTestClient\SignalRTestClient.csproj", "{E6B97963-4CEA-47B6-A0C8-625FFA9B7D69}" EndProject diff --git a/AsbCloudWebApi.Tests/AsbCloudWebApi.Tests.csproj b/AsbCloudInfrastructure.Tests/AsbCloudInfrastructure.Tests.csproj similarity index 100% rename from AsbCloudWebApi.Tests/AsbCloudWebApi.Tests.csproj rename to AsbCloudInfrastructure.Tests/AsbCloudInfrastructure.Tests.csproj diff --git a/AsbCloudWebApi.Tests/AspExtensions.cs b/AsbCloudInfrastructure.Tests/AspExtensions.cs similarity index 92% rename from AsbCloudWebApi.Tests/AspExtensions.cs rename to AsbCloudInfrastructure.Tests/AspExtensions.cs index 4ccd8204..a0f03559 100644 --- a/AsbCloudWebApi.Tests/AspExtensions.cs +++ b/AsbCloudInfrastructure.Tests/AspExtensions.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using System.Linq; -namespace AsbCloudWebApi.Tests; +namespace AsbCloudInfrastructure.Tests; public static class AspExtensions { diff --git a/AsbCloudWebApi.Tests/Background/BackgroundWorkerTest.cs b/AsbCloudInfrastructure.Tests/Background/BackgroundWorkerTest.cs similarity index 98% rename from AsbCloudWebApi.Tests/Background/BackgroundWorkerTest.cs rename to AsbCloudInfrastructure.Tests/Background/BackgroundWorkerTest.cs index 3f8dc020..97ce8bf3 100644 --- a/AsbCloudWebApi.Tests/Background/BackgroundWorkerTest.cs +++ b/AsbCloudInfrastructure.Tests/Background/BackgroundWorkerTest.cs @@ -7,7 +7,7 @@ using Microsoft.Extensions.DependencyInjection; using NSubstitute; using Xunit; -namespace AsbCloudWebApi.Tests.Background; +namespace AsbCloudInfrastructure.Tests.Background; public class BackgroundWorkerTest { diff --git a/AsbCloudWebApi.Tests/Background/PeriodicBackgroundWorkerTest.cs b/AsbCloudInfrastructure.Tests/Background/PeriodicBackgroundWorkerTest.cs similarity index 95% rename from AsbCloudWebApi.Tests/Background/PeriodicBackgroundWorkerTest.cs rename to AsbCloudInfrastructure.Tests/Background/PeriodicBackgroundWorkerTest.cs index acdfad32..a4860a15 100644 --- a/AsbCloudWebApi.Tests/Background/PeriodicBackgroundWorkerTest.cs +++ b/AsbCloudInfrastructure.Tests/Background/PeriodicBackgroundWorkerTest.cs @@ -8,7 +8,7 @@ using Microsoft.Extensions.DependencyInjection; using NSubstitute; using Xunit; -namespace AsbCloudWebApi.Tests.Background; +namespace AsbCloudInfrastructure.Tests.Background; //TODO: нужно поправить тесты, иногда они не проходят public class PeriodicBackgroundWorkerTest @@ -55,7 +55,7 @@ public class PeriodicBackgroundWorkerTest var stopwatch = Stopwatch.StartNew(); service.Add(work, period); - var delay = (periodMs / 20) + (periodMs * workCount) - stopwatch.ElapsedMilliseconds; + var delay = periodMs / 20 + periodMs * workCount - stopwatch.ElapsedMilliseconds; await Task.Delay(TimeSpan.FromMilliseconds(delay)); //assert diff --git a/AsbCloudWebApi.Tests/Background/WorkTest.cs b/AsbCloudInfrastructure.Tests/Background/WorkTest.cs similarity index 99% rename from AsbCloudWebApi.Tests/Background/WorkTest.cs rename to AsbCloudInfrastructure.Tests/Background/WorkTest.cs index da1e417c..3514968b 100644 --- a/AsbCloudWebApi.Tests/Background/WorkTest.cs +++ b/AsbCloudInfrastructure.Tests/Background/WorkTest.cs @@ -7,7 +7,7 @@ using Microsoft.Extensions.DependencyInjection; using NSubstitute; using Xunit; -namespace AsbCloudWebApi.Tests.Background; +namespace AsbCloudInfrastructure.Tests.Background; public class WorkTest { diff --git a/AsbCloudWebApi.Tests/CommonExtensions.cs b/AsbCloudInfrastructure.Tests/CommonExtensions.cs similarity index 88% rename from AsbCloudWebApi.Tests/CommonExtensions.cs rename to AsbCloudInfrastructure.Tests/CommonExtensions.cs index 501fe0e9..d7e88aca 100644 --- a/AsbCloudWebApi.Tests/CommonExtensions.cs +++ b/AsbCloudInfrastructure.Tests/CommonExtensions.cs @@ -1,7 +1,7 @@ using Mapster; using System; -namespace AsbCloudWebApi.Tests; +namespace AsbCloudInfrastructure.Tests; public static class CommonExtensions { diff --git a/AsbCloudWebApi.Tests/ReflectionExtensions.cs b/AsbCloudInfrastructure.Tests/ReflectionExtensions.cs similarity index 88% rename from AsbCloudWebApi.Tests/ReflectionExtensions.cs rename to AsbCloudInfrastructure.Tests/ReflectionExtensions.cs index 86d99a1f..04e388dc 100644 --- a/AsbCloudWebApi.Tests/ReflectionExtensions.cs +++ b/AsbCloudInfrastructure.Tests/ReflectionExtensions.cs @@ -1,10 +1,7 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace AsbCloudWebApi.Tests; +namespace AsbCloudInfrastructure.Tests; public static class ReflectionExtensions { @@ -42,5 +39,5 @@ public static class ReflectionExtensions } public static bool IsDefaultValue(this Type type, object? value) - => (value?.Equals(type.GetDefaultValue()) != false); + => value?.Equals(type.GetDefaultValue()) != false; } diff --git a/AsbCloudWebApi.Tests/Services/DailyReportServiceTest.cs b/AsbCloudInfrastructure.Tests/Services/DailyReportServiceTest.cs similarity index 99% rename from AsbCloudWebApi.Tests/Services/DailyReportServiceTest.cs rename to AsbCloudInfrastructure.Tests/Services/DailyReportServiceTest.cs index 0bbcb431..63c07050 100644 --- a/AsbCloudWebApi.Tests/Services/DailyReportServiceTest.cs +++ b/AsbCloudInfrastructure.Tests/Services/DailyReportServiceTest.cs @@ -23,7 +23,7 @@ using System.Threading.Tasks; using AsbCloudApp.Data.WellOperation; using Xunit; -namespace AsbCloudWebApi.Tests.Services; +namespace AsbCloudInfrastructure.Tests.Services; public class DailyReportServiceTest { diff --git a/AsbCloudWebApi.Tests/Services/DataSaubStatServiceTest.cs b/AsbCloudInfrastructure.Tests/Services/DataSaubStatServiceTest.cs similarity index 99% rename from AsbCloudWebApi.Tests/Services/DataSaubStatServiceTest.cs rename to AsbCloudInfrastructure.Tests/Services/DataSaubStatServiceTest.cs index 6d65a1f2..486ddc97 100644 --- a/AsbCloudWebApi.Tests/Services/DataSaubStatServiceTest.cs +++ b/AsbCloudInfrastructure.Tests/Services/DataSaubStatServiceTest.cs @@ -14,7 +14,7 @@ using System.Threading; using System.Threading.Tasks; using Xunit; -namespace AsbCloudWebApi.Tests.Services; +namespace AsbCloudInfrastructure.Tests.Services; public class DataSaubStatServiceTest { diff --git a/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorConditioning.cs b/AsbCloudInfrastructure.Tests/Services/DetectedOperations/Detectors/DetectorConditioning.cs similarity index 97% rename from AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorConditioning.cs rename to AsbCloudInfrastructure.Tests/Services/DetectedOperations/Detectors/DetectorConditioning.cs index 0a9829f5..b4b9f820 100644 --- a/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorConditioning.cs +++ b/AsbCloudInfrastructure.Tests/Services/DetectedOperations/Detectors/DetectorConditioning.cs @@ -4,7 +4,7 @@ using AsbCloudInfrastructure.Services.DetectOperations.Detectors; using System; using Xunit; -namespace AsbCloudWebApi.Tests.Services.DetectedOperations.Detectors; +namespace AsbCloudInfrastructure.Tests.Services.DetectedOperations.Detectors; /// /// Тестирование автоопределения операции "Проработка" diff --git a/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorDrillingTests.cs b/AsbCloudInfrastructure.Tests/Services/DetectedOperations/Detectors/DetectorDrillingTests.cs similarity index 66% rename from AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorDrillingTests.cs rename to AsbCloudInfrastructure.Tests/Services/DetectedOperations/Detectors/DetectorDrillingTests.cs index 13ac5d48..096b54de 100644 --- a/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorDrillingTests.cs +++ b/AsbCloudInfrastructure.Tests/Services/DetectedOperations/Detectors/DetectorDrillingTests.cs @@ -4,97 +4,97 @@ using AsbCloudInfrastructure.Services.DetectOperations; using AsbCloudInfrastructure.Services.DetectOperations.Detectors; using Xunit; -namespace AsbCloudWebApi.Tests.Services.DetectedOperations.Detectors; +namespace AsbCloudInfrastructure.Tests.Services.DetectedOperations.Detectors; public class DetectorDrillingTests : DetectorDrilling { - private const int idSlide = 5002; - private const int idRotor = 5003; + private const int idSlide = 5002; + private const int idRotor = 5003; - [Theory] - [MemberData(nameof(TelemetryRangeDrillingRotor))] - public void DefineDrillingOperation_ShouldReturn_DrillingRotor(DetectableTelemetry[] telemetryRange) - { - //act - var result = GetSpecificInformation(telemetryRange, 0, telemetryRange.Length); + [Theory] + [MemberData(nameof(TelemetryRangeDrillingRotor))] + public void DefineDrillingOperation_ShouldReturn_DrillingRotor(DetectableTelemetry[] telemetryRange) + { + //act + var result = GetSpecificInformation(telemetryRange, 0, telemetryRange.Length); - //assert - Assert.Equal(idRotor, result.IdCategory); - } + //assert + Assert.Equal(idRotor, result.IdCategory); + } - [Theory] - [MemberData(nameof(TelemetryRangeDrillingSlide))] - public void DefineDrillingOperation_ShouldReturn_DrillingSlide(DetectableTelemetry[] telemetryRange) - { - //act - var result = GetSpecificInformation(telemetryRange, 0, telemetryRange.Length); + [Theory] + [MemberData(nameof(TelemetryRangeDrillingSlide))] + public void DefineDrillingOperation_ShouldReturn_DrillingSlide(DetectableTelemetry[] telemetryRange) + { + //act + var result = GetSpecificInformation(telemetryRange, 0, telemetryRange.Length); - //assert - Assert.Equal(idSlide, result.IdCategory); - } + //assert + Assert.Equal(idSlide, result.IdCategory); + } - [Theory] - [MemberData(nameof(TelemetryRangeDrillingSlideWithOscillation))] - public void DefineDrillingOperation_ShouldReturn_DrillingSlideWithOscillation(DetectableTelemetry[] telemetryRange) - { - //act - var result = GetSpecificInformation(telemetryRange, 0, telemetryRange.Length); + [Theory] + [MemberData(nameof(TelemetryRangeDrillingSlideWithOscillation))] + public void DefineDrillingOperation_ShouldReturn_DrillingSlideWithOscillation(DetectableTelemetry[] telemetryRange) + { + //act + var result = GetSpecificInformation(telemetryRange, 0, telemetryRange.Length); - //assert - var oHasOscillation = result.ExtraData[ExtraDataKeyHasOscillation]; + //assert + var oHasOscillation = result.ExtraData[ExtraDataKeyHasOscillation]; - Assert.Equal(idSlide, result.IdCategory); - Assert.True(oHasOscillation is bool hasOscillation && hasOscillation); - } + Assert.Equal(idSlide, result.IdCategory); + Assert.True(oHasOscillation is bool hasOscillation && hasOscillation); + } - [Fact] - public void IsValidOperationDetectorResult_ShouldReturn_True() - { - //arrange - var operationDetectorResult = new OperationDetectorResult - { - Operation = new DetectedOperationDto - { - DepthStart = 5000, - DepthEnd = 6000, - DateStart = System.DateTimeOffset.Now.AddMinutes(-1), - DateEnd = System.DateTimeOffset.Now, - } - }; - - //act - var result = IsValidOperationDetectorResult(operationDetectorResult); - - //assert - Assert.True(result); - } - - [Fact] - public void IsValidOperationDetectorResult_ShouldReturn_False() - { - //arrange - var operationDetectorResult = new OperationDetectorResult - { - Operation = new DetectedOperationDto - { - DepthStart = 5000, - DepthEnd = 5000, + [Fact] + public void IsValidOperationDetectorResult_ShouldReturn_True() + { + //arrange + var operationDetectorResult = new OperationDetectorResult + { + Operation = new DetectedOperationDto + { + DepthStart = 5000, + DepthEnd = 6000, DateStart = System.DateTimeOffset.Now.AddMinutes(-1), DateEnd = System.DateTimeOffset.Now, } - }; + }; - //act - var result = IsValidOperationDetectorResult(operationDetectorResult); - - //assert - Assert.False(result); - } + //act + var result = IsValidOperationDetectorResult(operationDetectorResult); - public static IEnumerable TelemetryRangeDrillingRotor() - { - yield return new object[] - { + //assert + Assert.True(result); + } + + [Fact] + public void IsValidOperationDetectorResult_ShouldReturn_False() + { + //arrange + var operationDetectorResult = new OperationDetectorResult + { + Operation = new DetectedOperationDto + { + DepthStart = 5000, + DepthEnd = 5000, + DateStart = System.DateTimeOffset.Now.AddMinutes(-1), + DateEnd = System.DateTimeOffset.Now, + } + }; + + //act + var result = IsValidOperationDetectorResult(operationDetectorResult); + + //assert + Assert.False(result); + } + + public static IEnumerable TelemetryRangeDrillingRotor() + { + yield return new object[] + { new[] { new DetectableTelemetry @@ -152,13 +152,13 @@ public class DetectorDrillingTests : DetectorDrilling RotorSpeed = 40.3f } } - }; - } + }; + } - public static IEnumerable TelemetryRangeDrillingSlide() - { - yield return new object[] - { + public static IEnumerable TelemetryRangeDrillingSlide() + { + yield return new object[] + { new[] { new DetectableTelemetry @@ -189,13 +189,13 @@ public class DetectorDrillingTests : DetectorDrilling RotorSpeed = 0.1f }, } - }; - } + }; + } - public static IEnumerable TelemetryRangeDrillingSlideWithOscillation() - { - yield return new object[] - { + public static IEnumerable TelemetryRangeDrillingSlideWithOscillation() + { + yield return new object[] + { new[] { new DetectableTelemetry @@ -280,6 +280,6 @@ public class DetectorDrillingTests : DetectorDrilling RotorSpeed = 71.5f } } - }; - } + }; + } } \ No newline at end of file diff --git a/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorFlashingTests.cs b/AsbCloudInfrastructure.Tests/Services/DetectedOperations/Detectors/DetectorFlashingTests.cs similarity index 97% rename from AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorFlashingTests.cs rename to AsbCloudInfrastructure.Tests/Services/DetectedOperations/Detectors/DetectorFlashingTests.cs index 43203db9..1bc9e2fb 100644 --- a/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorFlashingTests.cs +++ b/AsbCloudInfrastructure.Tests/Services/DetectedOperations/Detectors/DetectorFlashingTests.cs @@ -3,7 +3,7 @@ using AsbCloudInfrastructure.Services.DetectOperations; using AsbCloudInfrastructure.Services.DetectOperations.Detectors; using Xunit; -namespace AsbCloudWebApi.Tests.Services.DetectedOperations.Detectors; +namespace AsbCloudInfrastructure.Tests.Services.DetectedOperations.Detectors; /// /// Тестирование автоопределения операции "Промывка" diff --git a/AsbCloudInfrastructure.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs b/AsbCloudInfrastructure.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs new file mode 100644 index 00000000..c46f9ab4 --- /dev/null +++ b/AsbCloudInfrastructure.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs @@ -0,0 +1,87 @@ +using System; +using AsbCloudInfrastructure.Services.DetectOperations; +using AsbCloudInfrastructure.Services.DetectOperations.Detectors; +using Xunit; + +namespace AsbCloudInfrastructure.Tests.Services.DetectedOperations.Detectors; + +public class DetectorSlipsTimeTests +{ + private const int IdSlipsTime = 5011; + + private readonly DetectableTelemetry telemetry = new() + { + WellDepth = 300, + Pressure = 15, + HookWeight = 20, + BlockPosition = 20, + BitDepth = 151, + AxialLoad = 19, + }; + + private readonly DetectorSlipsTime sut = new(); + + [Fact] + public void DetectOperation_by_change_block_position_and_axial_load_less_hook_weight_is_success() + { + //arrange + var point0 = telemetry.Copy(); + + var point1 = telemetry.Copy(); + point1.BlockPosition = 21; + + var telemetries = new[] { point0, point1 }; + + //act + var isDetectOperation = sut.TryDetect(0, telemetries, 0, telemetries.Length - 1, null, out var result); + + //assert + Assert.True(isDetectOperation); + Assert.NotNull(result); + Assert.Equal(IdSlipsTime, result.Operation.IdCategory); + } + + [Fact] + public void DetectOperation_by_high_pressure_is_success() + { + //arrange + var point0 = telemetry.Copy(); + + var point1 = telemetry.Copy(); + point1.BlockPosition = 21; + point1.AxialLoad = 30; + point1.HookWeight = 20; + point1.Pressure = 23; + + var telemetries = new[] { point0, point1 }; + + //act + var isDetectOperation = sut.TryDetect(0, telemetries, 0, telemetries.Length - 1, null, out var result); + + //assert + Assert.True(isDetectOperation); + Assert.NotNull(result); + Assert.Equal(IdSlipsTime, result.Operation.IdCategory); + } + + [Fact] + public void ValidateOperation_with_duration_more_30_minutes_is_invalid() + { + //arrange + var point0 = telemetry.Copy(); + + var point1 = telemetry.Copy(); + point1.BlockPosition = 21; + point1.DateTime = DateTimeOffset.UtcNow.AddMinutes(30); + + var telemetries = new[] { point0, point1 }; + + //act + var isDetectOperation = sut.TryDetect(0, telemetries, 0, telemetries.Length - 1, null, out var result); + + //assert + Assert.False(isDetectOperation); + Assert.NotNull(result); + Assert.Equal(IdSlipsTime, result.Operation.IdCategory); + } +} \ No newline at end of file diff --git a/AsbCloudInfrastructure.Tests/Services/DetectedOperations/EnabledSubsystemsTests.cs b/AsbCloudInfrastructure.Tests/Services/DetectedOperations/EnabledSubsystemsTests.cs new file mode 100644 index 00000000..ddf0a66a --- /dev/null +++ b/AsbCloudInfrastructure.Tests/Services/DetectedOperations/EnabledSubsystemsTests.cs @@ -0,0 +1,42 @@ +using AsbCloudApp.Data.DetectedOperation; +using Xunit; + +namespace AsbCloudInfrastructure.Tests.Services.DetectedOperations; + +public class EnabledSubsystemsTests +{ + [Fact] + public void Create_enable_subsystem_with_the_systems_turned_off() + { + //act + EnabledSubsystems enableSubsystem = 0; + + //arrange + Assert.False(enableSubsystem.IsAutoRotor); + Assert.False(enableSubsystem.IsAutoSlide); + Assert.False(enableSubsystem.IsAutoConditionig); + Assert.False(enableSubsystem.IsAutoSinking); + Assert.False(enableSubsystem.IsAutoLifting); + Assert.False(enableSubsystem.IsAutoLiftingWithConditionig); + Assert.False(enableSubsystem.IsAutoBlocknig); + Assert.False(enableSubsystem.IsAutoOscillation); + } + + [Fact] + public void Create_enable_subsystem_with_the_auto_slide_subsystem() + { + //act + EnabledSubsystems enableSubsystem = 2; + + //arrange + Assert.True(enableSubsystem.IsAutoSlide); + + Assert.False(enableSubsystem.IsAutoRotor); + Assert.False(enableSubsystem.IsAutoConditionig); + Assert.False(enableSubsystem.IsAutoSinking); + Assert.False(enableSubsystem.IsAutoLifting); + Assert.False(enableSubsystem.IsAutoLiftingWithConditionig); + Assert.False(enableSubsystem.IsAutoBlocknig); + Assert.False(enableSubsystem.IsAutoOscillation); + } +} \ No newline at end of file diff --git a/AsbCloudWebApi.Tests/Services/FileServiceTest.cs b/AsbCloudInfrastructure.Tests/Services/FileServiceTest.cs similarity index 99% rename from AsbCloudWebApi.Tests/Services/FileServiceTest.cs rename to AsbCloudInfrastructure.Tests/Services/FileServiceTest.cs index 61dad20e..a8b76e4d 100644 --- a/AsbCloudWebApi.Tests/Services/FileServiceTest.cs +++ b/AsbCloudInfrastructure.Tests/Services/FileServiceTest.cs @@ -11,7 +11,7 @@ using AsbCloudApp.Services; using NSubstitute; using Xunit; -namespace AsbCloudWebApi.Tests.Services; +namespace AsbCloudInfrastructure.Tests.Services; public class FileServiceTest { diff --git a/AsbCloudWebApi.Tests/Services/HelpPageServiceTest.cs b/AsbCloudInfrastructure.Tests/Services/HelpPageServiceTest.cs similarity index 98% rename from AsbCloudWebApi.Tests/Services/HelpPageServiceTest.cs rename to AsbCloudInfrastructure.Tests/Services/HelpPageServiceTest.cs index 38fdf8bc..14cc5d74 100644 --- a/AsbCloudWebApi.Tests/Services/HelpPageServiceTest.cs +++ b/AsbCloudInfrastructure.Tests/Services/HelpPageServiceTest.cs @@ -10,7 +10,7 @@ using System.Threading; using System.Threading.Tasks; using Xunit; -namespace AsbCloudWebApi.Tests.Services; +namespace AsbCloudInfrastructure.Tests.Services; public class HelpPageServiceTest { diff --git a/AsbCloudWebApi.Tests/Services/Notification/EmailNotificationTransportServiceTests.cs b/AsbCloudInfrastructure.Tests/Services/Notification/EmailNotificationTransportServiceTests.cs similarity index 97% rename from AsbCloudWebApi.Tests/Services/Notification/EmailNotificationTransportServiceTests.cs rename to AsbCloudInfrastructure.Tests/Services/Notification/EmailNotificationTransportServiceTests.cs index b2b96735..9195dacb 100644 --- a/AsbCloudWebApi.Tests/Services/Notification/EmailNotificationTransportServiceTests.cs +++ b/AsbCloudInfrastructure.Tests/Services/Notification/EmailNotificationTransportServiceTests.cs @@ -12,7 +12,7 @@ using System.Threading; using System.Threading.Tasks; using Xunit; -namespace AsbCloudWebApi.Tests.Services.Notification; +namespace AsbCloudInfrastructure.Tests.Services.Notification; public class EmailNotificationTransportServiceTests { diff --git a/AsbCloudWebApi.Tests/Services/ProcessMaps/ProcessMapReportDataSaubStatServiceTest.cs b/AsbCloudInfrastructure.Tests/Services/ProcessMaps/ProcessMapReportDataSaubStatServiceTest.cs similarity index 100% rename from AsbCloudWebApi.Tests/Services/ProcessMaps/ProcessMapReportDataSaubStatServiceTest.cs rename to AsbCloudInfrastructure.Tests/Services/ProcessMaps/ProcessMapReportDataSaubStatServiceTest.cs diff --git a/AsbCloudWebApi.Tests/Services/SAUB/TelemetryDataSaubCacheTests.cs b/AsbCloudInfrastructure.Tests/Services/SAUB/TelemetryDataSaubCacheTests.cs similarity index 95% rename from AsbCloudWebApi.Tests/Services/SAUB/TelemetryDataSaubCacheTests.cs rename to AsbCloudInfrastructure.Tests/Services/SAUB/TelemetryDataSaubCacheTests.cs index 7e771fb2..53893067 100644 --- a/AsbCloudWebApi.Tests/Services/SAUB/TelemetryDataSaubCacheTests.cs +++ b/AsbCloudInfrastructure.Tests/Services/SAUB/TelemetryDataSaubCacheTests.cs @@ -10,7 +10,7 @@ using Microsoft.Extensions.DependencyInjection; using NSubstitute; using Xunit; -namespace AsbCloudWebApi.Tests.Services.SAUB; +namespace AsbCloudInfrastructure.Tests.Services.SAUB; public class TelemetryDataSaubCacheTests { @@ -60,6 +60,6 @@ public class TelemetryDataSaubCacheTests var lastTelemetry = telemetryDataCache.GetLastOrDefault(idTelemetry); //assert - Assert.Null(lastTelemetry ); + Assert.Null(lastTelemetry); } } \ No newline at end of file diff --git a/AsbCloudWebApi.Tests/Services/Trajectory/Templates/TrajectoryFactManualTemplate.xlsx b/AsbCloudInfrastructure.Tests/Services/Trajectory/Templates/TrajectoryFactManualTemplate.xlsx similarity index 100% rename from AsbCloudWebApi.Tests/Services/Trajectory/Templates/TrajectoryFactManualTemplate.xlsx rename to AsbCloudInfrastructure.Tests/Services/Trajectory/Templates/TrajectoryFactManualTemplate.xlsx diff --git a/AsbCloudWebApi.Tests/Services/Trajectory/Templates/TrajectoryPlanTemplate.xlsx b/AsbCloudInfrastructure.Tests/Services/Trajectory/Templates/TrajectoryPlanTemplate.xlsx similarity index 100% rename from AsbCloudWebApi.Tests/Services/Trajectory/Templates/TrajectoryPlanTemplate.xlsx rename to AsbCloudInfrastructure.Tests/Services/Trajectory/Templates/TrajectoryPlanTemplate.xlsx diff --git a/AsbCloudWebApi.Tests/Services/Trajectory/TrajectoryExportTest.cs b/AsbCloudInfrastructure.Tests/Services/Trajectory/TrajectoryExportTest.cs similarity index 98% rename from AsbCloudWebApi.Tests/Services/Trajectory/TrajectoryExportTest.cs rename to AsbCloudInfrastructure.Tests/Services/Trajectory/TrajectoryExportTest.cs index 4c5d76d9..449a55e3 100644 --- a/AsbCloudWebApi.Tests/Services/Trajectory/TrajectoryExportTest.cs +++ b/AsbCloudInfrastructure.Tests/Services/Trajectory/TrajectoryExportTest.cs @@ -9,12 +9,12 @@ using System.Threading.Tasks; using AsbCloudApp.Requests.ExportOptions; using Xunit; -namespace AsbCloudWebApi.Tests.Services.Trajectory; +namespace AsbCloudInfrastructure.Tests.Services.Trajectory; public class TrajectoryExportTest { private const int idWell = 4; - + private IWellService wellService; private readonly ITrajectoryEditableRepository trajectoryPlanRepository; private readonly TrajectoryPlanExportService trajectoryPlanExportService; @@ -101,7 +101,7 @@ public class TrajectoryExportTest { trajectoryPlanRepository.GetAsync(idWell, CancellationToken.None) .Returns(trajectoryPlanRows); - + var stream = await trajectoryPlanExportService.ExportAsync(exportOptions, CancellationToken.None); Assert.True(stream.File.Length > 0); } @@ -111,7 +111,7 @@ public class TrajectoryExportTest { trajectoryFactManualReposirory.GetAsync(idWell, CancellationToken.None) .Returns(trajectoryFactRows); - + var stream = await trajectoryFactManualExportService.ExportAsync(exportOptions, CancellationToken.None); Assert.True(stream.File.Length > 0); } @@ -121,7 +121,7 @@ public class TrajectoryExportTest { trajectoryFactNnbRepository.GetAsync(idWell, CancellationToken.None) .Returns(trajectoryFactRows); - + var stream = await trajectoryFactNnbExportService.ExportAsync(exportOptions, CancellationToken.None); Assert.True(stream.File.Length > 0); } diff --git a/AsbCloudInfrastructure.Tests/Services/Trajectory/TrajectoryParserTest.cs b/AsbCloudInfrastructure.Tests/Services/Trajectory/TrajectoryParserTest.cs new file mode 100644 index 00000000..e0e531f4 --- /dev/null +++ b/AsbCloudInfrastructure.Tests/Services/Trajectory/TrajectoryParserTest.cs @@ -0,0 +1,44 @@ +using System.Linq; +using AsbCloudApp.Requests.ParserOptions; +using AsbCloudInfrastructure.Services.Trajectory.Parser; +using Xunit; + +namespace AsbCloudInfrastructure.Tests.Services.Trajectory; + +public class TrajectoryParserTest +{ + private const string UsingTemplateFile = "AsbCloudWebApi.Tests.Services.Trajectory.Templates"; + + private readonly WellRelatedParserRequest options = new(1); + + private readonly TrajectoryPlanParser trajectoryPlanParser = new(); + private readonly TrajectoryFactManualParser trajectoryFactManualParser = new(); + + [Fact] + public void Parse_trajectory_plan() + { + var stream = System.Reflection.Assembly.GetExecutingAssembly() + .GetManifestResourceStream($"{UsingTemplateFile}.TrajectoryPlanTemplate.xlsx"); + + if (stream is null) + Assert.Fail("Файла для импорта не существует"); + + var trajectoryRows = trajectoryPlanParser.Parse(stream, options); + + Assert.Equal(3, trajectoryRows.Item.Count()); + } + + [Fact] + public void Parse_trajectory_fact_manual() + { + var stream = System.Reflection.Assembly.GetExecutingAssembly() + .GetManifestResourceStream($"{UsingTemplateFile}.TrajectoryFactManualTemplate.xlsx"); + + if (stream is null) + Assert.Fail("Файла для импорта не существует"); + + var trajectoryRows = trajectoryFactManualParser.Parse(stream, options); + + Assert.Equal(4, trajectoryRows.Item.Count()); + } +} \ No newline at end of file diff --git a/AsbCloudWebApi.Tests/Services/TrajectoryVisualizationServiceTest.cs b/AsbCloudInfrastructure.Tests/Services/TrajectoryVisualizationServiceTest.cs similarity index 98% rename from AsbCloudWebApi.Tests/Services/TrajectoryVisualizationServiceTest.cs rename to AsbCloudInfrastructure.Tests/Services/TrajectoryVisualizationServiceTest.cs index a2d31b40..28db971c 100644 --- a/AsbCloudWebApi.Tests/Services/TrajectoryVisualizationServiceTest.cs +++ b/AsbCloudInfrastructure.Tests/Services/TrajectoryVisualizationServiceTest.cs @@ -1,15 +1,13 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using AsbCloudApp.Data; using AsbCloudApp.Data.Trajectory; using AsbCloudApp.Repositories; -using AsbCloudApp.Requests; using AsbCloudInfrastructure.Services.Trajectory; using NSubstitute; using Xunit; -namespace AsbCloudWebApi.Tests.Services; +namespace AsbCloudInfrastructure.Tests.Services; public class TrajectoryVisualizationServiceTest { diff --git a/AsbCloudWebApi.Tests/Services/WellCompositeOperation/WellCompositeOperationServiceTest.cs b/AsbCloudInfrastructure.Tests/Services/WellCompositeOperation/WellCompositeOperationServiceTest.cs similarity index 99% rename from AsbCloudWebApi.Tests/Services/WellCompositeOperation/WellCompositeOperationServiceTest.cs rename to AsbCloudInfrastructure.Tests/Services/WellCompositeOperation/WellCompositeOperationServiceTest.cs index 8c5961ed..813cd815 100644 --- a/AsbCloudWebApi.Tests/Services/WellCompositeOperation/WellCompositeOperationServiceTest.cs +++ b/AsbCloudInfrastructure.Tests/Services/WellCompositeOperation/WellCompositeOperationServiceTest.cs @@ -12,7 +12,7 @@ using System.Threading; using System.Threading.Tasks; using Xunit; -namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation; +namespace AsbCloudInfrastructure.Tests.Services.WellCompositeOperation; public class WellCompositeOperationServiceTest { diff --git a/AsbCloudWebApi.Tests/Services/WellFinalDocumentsServiceTest.cs b/AsbCloudInfrastructure.Tests/Services/WellFinalDocumentsServiceTest.cs similarity index 99% rename from AsbCloudWebApi.Tests/Services/WellFinalDocumentsServiceTest.cs rename to AsbCloudInfrastructure.Tests/Services/WellFinalDocumentsServiceTest.cs index 18cca46b..92111ada 100644 --- a/AsbCloudWebApi.Tests/Services/WellFinalDocumentsServiceTest.cs +++ b/AsbCloudInfrastructure.Tests/Services/WellFinalDocumentsServiceTest.cs @@ -13,7 +13,7 @@ using Microsoft.Extensions.Configuration; using NSubstitute; using Xunit; -namespace AsbCloudWebApi.Tests.Services; +namespace AsbCloudInfrastructure.Tests.Services; public class WellFinalDocumentsServiceTest { diff --git a/AsbCloudWebApi.Tests/Services/WellOperationServiceTest.cs b/AsbCloudInfrastructure.Tests/Services/WellOperationServiceTest.cs similarity index 97% rename from AsbCloudWebApi.Tests/Services/WellOperationServiceTest.cs rename to AsbCloudInfrastructure.Tests/Services/WellOperationServiceTest.cs index b1d943c7..569ca63d 100644 --- a/AsbCloudWebApi.Tests/Services/WellOperationServiceTest.cs +++ b/AsbCloudInfrastructure.Tests/Services/WellOperationServiceTest.cs @@ -12,7 +12,7 @@ using System.Threading; using System.Threading.Tasks; using Xunit; -namespace AsbCloudWebApi.Tests.Services; +namespace AsbCloudInfrastructure.Tests.Services; public class WellOperationServiceTest { private const int idWell = 1; @@ -108,7 +108,7 @@ public class WellOperationServiceTest Assert.Equal(operationFactWithNpt.IdCategory, retrievedOperationFactWithNpt.IdCategory); var retrievedOperationFactRotor = facts.First(o => o.Id == operationFactRotor.Id); - var expectedDay = operationFactWithNpt.DurationHours / 24; + var expectedDay = operationFactWithNpt.DurationHours / 24; Assert.Equal(expectedDay, retrievedOperationFactRotor.Day, 0.001); Assert.Equal(operationFactWithNpt.DurationHours, retrievedOperationFactRotor.NptHours, 0.001); Assert.Equal(retrievedOperationPlanRotor.Id, retrievedOperationFactRotor.IdPlan); diff --git a/AsbCloudWebApi.Tests/Services/WellboreServiceTest.cs b/AsbCloudInfrastructure.Tests/Services/WellboreServiceTest.cs similarity index 99% rename from AsbCloudWebApi.Tests/Services/WellboreServiceTest.cs rename to AsbCloudInfrastructure.Tests/Services/WellboreServiceTest.cs index 32a1e2a5..af7734e7 100644 --- a/AsbCloudWebApi.Tests/Services/WellboreServiceTest.cs +++ b/AsbCloudInfrastructure.Tests/Services/WellboreServiceTest.cs @@ -12,7 +12,7 @@ using AsbCloudInfrastructure.Services; using NSubstitute; using Xunit; -namespace AsbCloudWebApi.Tests.Services; +namespace AsbCloudInfrastructure.Tests.Services; public class WellboreServiceTest { diff --git a/AsbCloudInfrastructure.Tests/XLExtensionsTests.cs b/AsbCloudInfrastructure.Tests/XLExtensionsTests.cs new file mode 100644 index 00000000..d66862bd --- /dev/null +++ b/AsbCloudInfrastructure.Tests/XLExtensionsTests.cs @@ -0,0 +1,169 @@ +using System; +using System.IO; +using ClosedXML.Excel; +using Xunit; + +namespace AsbCloudInfrastructure.Tests; + +public class XLExtensionsTests +{ + private const string cellUsed = "A1"; + private const string sheetName = "test"; + + private readonly IXLWorkbook workbook; + + public XLExtensionsTests() + { + workbook = new XLWorkbook(); + workbook.Worksheets.Add(sheetName); + } + + [Fact] + public void GetWorksheet_returns_sheet() + { + //act + var sheet = workbook.GetWorksheet(sheetName); + + //assert + Assert.NotNull(sheet); + } + + [Theory] + [MemberData(nameof(valueTypesToSet))] + public void SetCellValue_returns_success(object value, XLDataType expectedDataType) + { + //act + var cell = GetCell(cellUsed); + cell.SetCellValue(value); + + //assert + Assert.Equal(expectedDataType, cell.DataType); + } + + [Fact] + public void GetCellValue_returns_double() + { + //arrange + const double expectedValue = 2.0d; + SetCellValue(expectedValue); + + //act + var actualValue = GetCell(cellUsed).GetCellValue(); + + //assert + Assert.Equal(expectedValue, actualValue); + } + + [Fact] + public void GetCellValue_returns_float() + { + //arrange + const float expectedValue = 2.0f; + SetCellValue(expectedValue); + + //act + var actualValue = GetCell(cellUsed).GetCellValue(); + + //assert + Assert.Equal(expectedValue, actualValue); + } + + [Theory] + [InlineData("test")] + [InlineData(null)] + public void GetCellValue_returns_string(string? expectedValue) + { + //arrange + SetCellValue(expectedValue); + + //act + var actualValue = GetCell(cellUsed).GetCellValue(); + + //assert + Assert.Equal(expectedValue, actualValue); + } + + [Fact] + public void GetCellValue_returns_bool() + { + //arrange + const bool expectedValue = true; + SetCellValue(expectedValue); + + //act + var actualValue = GetCell(cellUsed).GetCellValue(); + + //assert + Assert.Equal(expectedValue, actualValue); + } + + [Fact] + public void GetCellValue_returns_dateTime() + { + //arrange + var expectedValue = DateTime.Parse("2023-01-01"); + SetCellValue(expectedValue); + + //act + var actualValue = GetCell(cellUsed).GetCellValue(); + + //assert + Assert.Equal(expectedValue, actualValue); + Assert.Equal(DateTimeKind.Unspecified, actualValue.Kind); + } + + [Fact] + public void GetCellValue_returns_exception() + { + //arrange + SetCellValue("test"); + + //assert + Assert.Throws(() => GetCell(cellUsed).GetCellValue()); + } + + [Fact] + public void GetCellValue_returns_nullable() + { + //act + var actualValue = GetCell(cellUsed).GetCellValue(); + + //assert + Assert.Null(actualValue); + } + + [Fact] + public void SetHyperlink_returns_success() + { + //arrange + const string link = "http://test.ru"; + + //act + GetCell(cellUsed).SetHyperlink(link); + + //assert + var hyperLink = GetCell(cellUsed).GetHyperlink(); + Assert.NotNull(hyperLink); + } + + private void SetCellValue(T value) + { + var cell = GetCell(cellUsed); + cell.SetCellValue(value); + } + + public static readonly object[][] valueTypesToSet = + { + new object[] { 2.0d, XLDataType.Number }, + new object[] { 2.0f, XLDataType.Number }, + new object[] { "test", XLDataType.Text }, + new object[] { true, XLDataType.Boolean }, + new object[] { DateTime.UtcNow, XLDataType.DateTime } + }; + + private IXLCell GetCell(string cellAddressInRange) + { + var sheet = workbook.GetWorksheet(sheetName); + return sheet.Cell(cellAddressInRange); + } +} \ No newline at end of file diff --git a/AsbCloudWebApi.Tests/readme.md b/AsbCloudInfrastructure.Tests/readme.md similarity index 100% rename from AsbCloudWebApi.Tests/readme.md rename to AsbCloudInfrastructure.Tests/readme.md diff --git a/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs b/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs deleted file mode 100644 index 17029194..00000000 --- a/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System; -using AsbCloudInfrastructure.Services.DetectOperations; -using AsbCloudInfrastructure.Services.DetectOperations.Detectors; -using Xunit; - -namespace AsbCloudWebApi.Tests.Services.DetectedOperations.Detectors; - -public class DetectorSlipsTimeTests -{ - private const int IdSlipsTime = 5011; - - private readonly DetectableTelemetry telemetry = new() { - WellDepth = 300, - Pressure = 15, - HookWeight = 20, - BlockPosition = 20, - BitDepth = 151, - AxialLoad = 19, - }; - - private readonly DetectorSlipsTime sut = new(); - - [Fact] - public void DetectOperation_by_change_block_position_and_axial_load_less_hook_weight_is_success() - { - //arrange - var point0 = telemetry.Copy(); - - var point1 = telemetry.Copy(); - point1.BlockPosition = 21; - - var telemetries = new[] { point0, point1 }; - - //act - var isDetectOperation = sut.TryDetect(0, telemetries, 0, telemetries.Length - 1, null, out var result); - - //assert - Assert.True(isDetectOperation); - Assert.NotNull(result); - Assert.Equal(IdSlipsTime, result.Operation.IdCategory); - } - - [Fact] - public void DetectOperation_by_high_pressure_is_success() - { - //arrange - var point0 = telemetry.Copy(); - - var point1 = telemetry.Copy(); - point1.BlockPosition = 21; - point1.AxialLoad = 30; - point1.HookWeight = 20; - point1.Pressure = 23; - - var telemetries = new[] { point0, point1 }; - - //act - var isDetectOperation = sut.TryDetect(0, telemetries, 0, telemetries.Length - 1, null, out var result); - - //assert - Assert.True(isDetectOperation); - Assert.NotNull(result); - Assert.Equal(IdSlipsTime, result.Operation.IdCategory); - } - - [Fact] - public void ValidateOperation_with_duration_more_30_minutes_is_invalid() - { - //arrange - var point0 = telemetry.Copy(); - - var point1 = telemetry.Copy(); - point1.BlockPosition = 21; - point1.DateTime = DateTimeOffset.UtcNow.AddMinutes(30); - - var telemetries = new[] { point0, point1 }; - - //act - var isDetectOperation = sut.TryDetect(0, telemetries, 0, telemetries.Length - 1, null, out var result); - - //assert - Assert.False(isDetectOperation); - Assert.NotNull(result); - Assert.Equal(IdSlipsTime, result.Operation.IdCategory); - } -} \ No newline at end of file diff --git a/AsbCloudWebApi.Tests/Services/DetectedOperations/EnabledSubsystemsTests.cs b/AsbCloudWebApi.Tests/Services/DetectedOperations/EnabledSubsystemsTests.cs deleted file mode 100644 index 791a86d8..00000000 --- a/AsbCloudWebApi.Tests/Services/DetectedOperations/EnabledSubsystemsTests.cs +++ /dev/null @@ -1,42 +0,0 @@ -using AsbCloudApp.Data.DetectedOperation; -using Xunit; - -namespace AsbCloudWebApi.Tests.Services.DetectedOperations; - -public class EnabledSubsystemsTests -{ - [Fact] - public void Create_enable_subsystem_with_the_systems_turned_off() - { - //act - EnabledSubsystems enableSubsystem = 0; - - //arrange - Assert.False(enableSubsystem.IsAutoRotor); - Assert.False(enableSubsystem.IsAutoSlide); - Assert.False(enableSubsystem.IsAutoConditionig); - Assert.False(enableSubsystem.IsAutoSinking); - Assert.False(enableSubsystem.IsAutoLifting); - Assert.False(enableSubsystem.IsAutoLiftingWithConditionig); - Assert.False(enableSubsystem.IsAutoBlocknig); - Assert.False(enableSubsystem.IsAutoOscillation); - } - - [Fact] - public void Create_enable_subsystem_with_the_auto_slide_subsystem() - { - //act - EnabledSubsystems enableSubsystem = 2; - - //arrange - Assert.True(enableSubsystem.IsAutoSlide); - - Assert.False(enableSubsystem.IsAutoRotor); - Assert.False(enableSubsystem.IsAutoConditionig); - Assert.False(enableSubsystem.IsAutoSinking); - Assert.False(enableSubsystem.IsAutoLifting); - Assert.False(enableSubsystem.IsAutoLiftingWithConditionig); - Assert.False(enableSubsystem.IsAutoBlocknig); - Assert.False(enableSubsystem.IsAutoOscillation); - } -} \ No newline at end of file diff --git a/AsbCloudWebApi.Tests/Services/Trajectory/TrajectoryParserTest.cs b/AsbCloudWebApi.Tests/Services/Trajectory/TrajectoryParserTest.cs deleted file mode 100644 index 64a3caca..00000000 --- a/AsbCloudWebApi.Tests/Services/Trajectory/TrajectoryParserTest.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System.Linq; -using AsbCloudApp.Data.Trajectory; -using AsbCloudApp.Requests.ParserOptions; -using AsbCloudInfrastructure.Services.Trajectory.Parser; -using Xunit; - -namespace AsbCloudWebApi.Tests.Services.Trajectory; - -public class TrajectoryParserTest -{ - private const string UsingTemplateFile = "AsbCloudWebApi.Tests.Services.Trajectory.Templates"; - - private readonly WellRelatedParserRequest options = new(1); - - private readonly TrajectoryPlanParser trajectoryPlanParser = new(); - private readonly TrajectoryFactManualParser trajectoryFactManualParser = new(); - - [Fact] - public void Parse_trajectory_plan() - { - var stream = System.Reflection.Assembly.GetExecutingAssembly() - .GetManifestResourceStream($"{UsingTemplateFile}.TrajectoryPlanTemplate.xlsx"); - - if (stream is null) - Assert.Fail("Файла для импорта не существует"); - - var trajectoryRows = trajectoryPlanParser.Parse(stream, options); - - Assert.Equal(3, trajectoryRows.Item.Count()); - } - - [Fact] - public void Parse_trajectory_fact_manual() - { - var stream = System.Reflection.Assembly.GetExecutingAssembly() - .GetManifestResourceStream($"{UsingTemplateFile}.TrajectoryFactManualTemplate.xlsx"); - - if (stream is null) - Assert.Fail("Файла для импорта не существует"); - - var trajectoryRows = trajectoryFactManualParser.Parse(stream, options); - - Assert.Equal(4, trajectoryRows.Item.Count()); - } -} \ No newline at end of file diff --git a/AsbCloudWebApi.Tests/XLExtensionsTests.cs b/AsbCloudWebApi.Tests/XLExtensionsTests.cs deleted file mode 100644 index 87a13dad..00000000 --- a/AsbCloudWebApi.Tests/XLExtensionsTests.cs +++ /dev/null @@ -1,170 +0,0 @@ -using System; -using System.IO; -using AsbCloudInfrastructure; -using ClosedXML.Excel; -using Xunit; - -namespace AsbCloudWebApi.Tests; - -public class XLExtensionsTests -{ - private const string cellUsed = "A1"; - private const string sheetName = "test"; - - private readonly IXLWorkbook workbook; - - public XLExtensionsTests() - { - workbook = new XLWorkbook(); - workbook.Worksheets.Add(sheetName); - } - - [Fact] - public void GetWorksheet_returns_sheet() - { - //act - var sheet = workbook.GetWorksheet(sheetName); - - //assert - Assert.NotNull(sheet); - } - - [Theory] - [MemberData(nameof(valueTypesToSet))] - public void SetCellValue_returns_success(object value, XLDataType expectedDataType) - { - //act - var cell = GetCell(cellUsed); - cell.SetCellValue(value); - - //assert - Assert.Equal(expectedDataType, cell.DataType); - } - - [Fact] - public void GetCellValue_returns_double() - { - //arrange - const double expectedValue = 2.0d; - SetCellValue(expectedValue); - - //act - var actualValue = GetCell(cellUsed).GetCellValue(); - - //assert - Assert.Equal(expectedValue, actualValue); - } - - [Fact] - public void GetCellValue_returns_float() - { - //arrange - const float expectedValue = 2.0f; - SetCellValue(expectedValue); - - //act - var actualValue = GetCell(cellUsed).GetCellValue(); - - //assert - Assert.Equal(expectedValue, actualValue); - } - - [Theory] - [InlineData("test")] - [InlineData(null)] - public void GetCellValue_returns_string(string? expectedValue) - { - //arrange - SetCellValue(expectedValue); - - //act - var actualValue = GetCell(cellUsed).GetCellValue(); - - //assert - Assert.Equal(expectedValue, actualValue); - } - - [Fact] - public void GetCellValue_returns_bool() - { - //arrange - const bool expectedValue = true; - SetCellValue(expectedValue); - - //act - var actualValue = GetCell(cellUsed).GetCellValue(); - - //assert - Assert.Equal(expectedValue, actualValue); - } - - [Fact] - public void GetCellValue_returns_dateTime() - { - //arrange - var expectedValue = DateTime.Parse("2023-01-01"); - SetCellValue(expectedValue); - - //act - var actualValue = GetCell(cellUsed).GetCellValue(); - - //assert - Assert.Equal(expectedValue, actualValue); - Assert.Equal(DateTimeKind.Unspecified, actualValue.Kind); - } - - [Fact] - public void GetCellValue_returns_exception() - { - //arrange - SetCellValue("test"); - - //assert - Assert.Throws(() => GetCell(cellUsed).GetCellValue()); - } - - [Fact] - public void GetCellValue_returns_nullable() - { - //act - var actualValue = GetCell(cellUsed).GetCellValue(); - - //assert - Assert.Null(actualValue); - } - - [Fact] - public void SetHyperlink_returns_success() - { - //arrange - const string link = "http://test.ru"; - - //act - GetCell(cellUsed).SetHyperlink(link); - - //assert - var hyperLink = GetCell(cellUsed).GetHyperlink(); - Assert.NotNull(hyperLink); - } - - private void SetCellValue(T value) - { - var cell = GetCell(cellUsed); - cell.SetCellValue(value); - } - - public static readonly object[][] valueTypesToSet = - { - new object[] { 2.0d, XLDataType.Number }, - new object[] { 2.0f, XLDataType.Number }, - new object[] { "test", XLDataType.Text }, - new object[] { true, XLDataType.Boolean }, - new object[] { DateTime.UtcNow, XLDataType.DateTime } - }; - - private IXLCell GetCell(string cellAddressInRange) - { - var sheet = workbook.GetWorksheet(sheetName); - return sheet.Cell(cellAddressInRange); - } -} \ No newline at end of file