forked from ddrilling/AsbCloudServer
rename unit tests project
This commit is contained in:
parent
bc1c5fa00f
commit
90a782826c
@ -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
|
||||
|
@ -1,7 +1,7 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Linq;
|
||||
|
||||
namespace AsbCloudWebApi.Tests;
|
||||
namespace AsbCloudInfrastructure.Tests;
|
||||
|
||||
public static class AspExtensions
|
||||
{
|
@ -7,7 +7,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
|
||||
namespace AsbCloudWebApi.Tests.Background;
|
||||
namespace AsbCloudInfrastructure.Tests.Background;
|
||||
|
||||
public class BackgroundWorkerTest
|
||||
{
|
@ -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
|
@ -7,7 +7,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
|
||||
namespace AsbCloudWebApi.Tests.Background;
|
||||
namespace AsbCloudInfrastructure.Tests.Background;
|
||||
|
||||
public class WorkTest
|
||||
{
|
@ -1,7 +1,7 @@
|
||||
using Mapster;
|
||||
using System;
|
||||
|
||||
namespace AsbCloudWebApi.Tests;
|
||||
namespace AsbCloudInfrastructure.Tests;
|
||||
|
||||
public static class CommonExtensions
|
||||
{
|
@ -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;
|
||||
}
|
@ -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
|
||||
{
|
@ -14,7 +14,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace AsbCloudWebApi.Tests.Services;
|
||||
namespace AsbCloudInfrastructure.Tests.Services;
|
||||
|
||||
public class DataSaubStatServiceTest
|
||||
{
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Тестирование автоопределения операции "Проработка"
|
@ -4,7 +4,7 @@ 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
|
||||
{
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Тестирование автоопределения операции "Промывка"
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ using AsbCloudApp.Services;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
|
||||
namespace AsbCloudWebApi.Tests.Services;
|
||||
namespace AsbCloudInfrastructure.Tests.Services;
|
||||
|
||||
public class FileServiceTest
|
||||
{
|
@ -10,7 +10,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace AsbCloudWebApi.Tests.Services;
|
||||
namespace AsbCloudInfrastructure.Tests.Services;
|
||||
|
||||
public class HelpPageServiceTest
|
||||
{
|
@ -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
|
||||
{
|
@ -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
|
||||
{
|
@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
using AsbCloudApp.Requests.ExportOptions;
|
||||
using Xunit;
|
||||
|
||||
namespace AsbCloudWebApi.Tests.Services.Trajectory;
|
||||
namespace AsbCloudInfrastructure.Tests.Services.Trajectory;
|
||||
|
||||
public class TrajectoryExportTest
|
||||
{
|
@ -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());
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
@ -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
|
||||
{
|
@ -13,7 +13,7 @@ using Microsoft.Extensions.Configuration;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
|
||||
namespace AsbCloudWebApi.Tests.Services;
|
||||
namespace AsbCloudInfrastructure.Tests.Services;
|
||||
|
||||
public class WellFinalDocumentsServiceTest
|
||||
{
|
@ -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;
|
@ -12,7 +12,7 @@ using AsbCloudInfrastructure.Services;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
|
||||
namespace AsbCloudWebApi.Tests.Services;
|
||||
namespace AsbCloudInfrastructure.Tests.Services;
|
||||
|
||||
public class WellboreServiceTest
|
||||
{
|
169
AsbCloudInfrastructure.Tests/XLExtensionsTests.cs
Normal file
169
AsbCloudInfrastructure.Tests/XLExtensionsTests.cs
Normal file
@ -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<double>();
|
||||
|
||||
//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<float>();
|
||||
|
||||
//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<string>();
|
||||
|
||||
//assert
|
||||
Assert.Equal(expectedValue, actualValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetCellValue_returns_bool()
|
||||
{
|
||||
//arrange
|
||||
const bool expectedValue = true;
|
||||
SetCellValue(expectedValue);
|
||||
|
||||
//act
|
||||
var actualValue = GetCell(cellUsed).GetCellValue<bool>();
|
||||
|
||||
//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<DateTime>();
|
||||
|
||||
//assert
|
||||
Assert.Equal(expectedValue, actualValue);
|
||||
Assert.Equal(DateTimeKind.Unspecified, actualValue.Kind);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetCellValue_returns_exception()
|
||||
{
|
||||
//arrange
|
||||
SetCellValue("test");
|
||||
|
||||
//assert
|
||||
Assert.Throws<FileFormatException>(() => GetCell(cellUsed).GetCellValue<double>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetCellValue_returns_nullable()
|
||||
{
|
||||
//act
|
||||
var actualValue = GetCell(cellUsed).GetCellValue<object?>();
|
||||
|
||||
//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>(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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -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<double>();
|
||||
|
||||
//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<float>();
|
||||
|
||||
//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<string>();
|
||||
|
||||
//assert
|
||||
Assert.Equal(expectedValue, actualValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetCellValue_returns_bool()
|
||||
{
|
||||
//arrange
|
||||
const bool expectedValue = true;
|
||||
SetCellValue(expectedValue);
|
||||
|
||||
//act
|
||||
var actualValue = GetCell(cellUsed).GetCellValue<bool>();
|
||||
|
||||
//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<DateTime>();
|
||||
|
||||
//assert
|
||||
Assert.Equal(expectedValue, actualValue);
|
||||
Assert.Equal(DateTimeKind.Unspecified, actualValue.Kind);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetCellValue_returns_exception()
|
||||
{
|
||||
//arrange
|
||||
SetCellValue("test");
|
||||
|
||||
//assert
|
||||
Assert.Throws<FileFormatException>(() => GetCell(cellUsed).GetCellValue<double>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetCellValue_returns_nullable()
|
||||
{
|
||||
//act
|
||||
var actualValue = GetCell(cellUsed).GetCellValue<object?>();
|
||||
|
||||
//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>(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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user