diff --git a/AsbCloudInfrastructure.Tests/CsvMockHelper.cs b/AsbCloudInfrastructure.Tests/CsvMockHelper.cs
new file mode 100644
index 00000000..2c9f2228
--- /dev/null
+++ b/AsbCloudInfrastructure.Tests/CsvMockHelper.cs
@@ -0,0 +1,46 @@
+using AsbCloudApp.Exceptions;
+using CsvHelper;
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+
+namespace AsbCloudInfrastructure.Tests;
+
+///
+/// Хелпер, который помогает получать мок-данные из csv файла
+///
+public static class CsvMockHelper
+{
+ ///
+ /// метод получения данных из файла
+ ///
+ ///
+ /// путь до файла
+ ///
+ ///
+ public static IEnumerable Get(string path)
+ {
+ var resourceName = Assembly.GetExecutingAssembly()
+ .GetManifestResourceNames()
+ .Where(r => r.Contains(path))
+ .FirstOrDefault();
+
+ if (String.IsNullOrEmpty(resourceName))
+ throw new ArgumentInvalidException(nameof(path), "Файл с mock-данными не найден");
+
+ using var stream = Assembly.GetExecutingAssembly()
+ .GetManifestResourceStream(resourceName)!;
+
+ using (var reader = new StreamReader(stream))
+ {
+ using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
+ {
+ var dataSaubMaps = csv.GetRecords().ToArray();
+ return dataSaubMaps;
+ }
+ }
+ }
+}
diff --git a/AsbCloudInfrastructure.Tests/Services/DataSaubStat/DataSaubStatDtillingQualityServiceTest.cs b/AsbCloudInfrastructure.Tests/Services/DataSaubStat/DataSaubStatDtillingQualityServiceTest.cs
index 0ad9700c..0a3d4192 100644
--- a/AsbCloudInfrastructure.Tests/Services/DataSaubStat/DataSaubStatDtillingQualityServiceTest.cs
+++ b/AsbCloudInfrastructure.Tests/Services/DataSaubStat/DataSaubStatDtillingQualityServiceTest.cs
@@ -39,79 +39,44 @@ public class DataSaubStatDtillingQualityServiceTest
[Theory]
[InlineData("DataSaubStat.test3.csv", "DataSaubStat.test3_result.csv")]
[InlineData("DataSaubStat.test2.csv", "DataSaubStat.test2_result.csv")]
- //[InlineData("DataSaubStat.test1.csv", "DataSaubStat.test1_result.csv")]
+ [InlineData("DataSaubStat.test1.csv", "DataSaubStat.test1_result.csv")]
public async Task Create_DataSaubStatDrillingQuality_From_CSVFile_ShouldReturn_Success(
string pathMockData,
string pathResult
)
{
- var resourceName = Assembly.GetExecutingAssembly()
- .GetManifestResourceNames()
- .Where(r => r.Contains(pathMockData))
- .FirstOrDefault();
+ var mockData = CsvMockHelper.Get(pathMockData);
+ var dtoMockData = mockData.Select(x => x.Adapt()).ToArray();
- if (String.IsNullOrEmpty(resourceName))
- Assert.Fail("No mock data for test");
+ dataSaubServiceMock
+ .Get(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any())
+ .Returns(dtoMockData);
- using var stream = Assembly.GetExecutingAssembly()
- .GetManifestResourceStream(resourceName)!;
+ //act
+ var actualData = await dataSaubStatService.CreateStatDrillingQualityForTelemetry(1, DateTimeOffset.UnixEpoch, CancellationToken.None);
- var actualData = Enumerable.Empty();
+ var mockDataResult = CsvMockHelper.Get(pathResult);
+ var expectedData = mockDataResult.Select(x => x.Adapt()).ToArray();
- using (var reader = new StreamReader(stream))
- using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
+ //assert
+ var actual = actualData
+ .OrderBy(d => d.IdFeedRegulator)
+ .ToArray();
+
+ var expected = expectedData
+ .OrderBy(d => d.IdFeedRegulator)
+ .ToArray();
+
+ Assert.Equal(expected.Count(), actual.Count());
+
+ for (var i = 0; i < actual.Count(); i++)
{
- var dataSaubMaps = csv.GetRecords().ToList();
-
- var dtos = dataSaubMaps.Select(x => x.Adapt()).ToArray();
-
- dataSaubServiceMock
- .Get(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any())
- .Returns(dtos);
-
- //act
- actualData = await dataSaubStatService.CreateStatDrillingQualityForTelemetry(1, DateTimeOffset.UnixEpoch, CancellationToken.None);
- }
-
- resourceName = Assembly.GetExecutingAssembly()
- .GetManifestResourceNames()
- .Where(r => r.Contains(pathResult))
- .FirstOrDefault();
-
- if (String.IsNullOrEmpty(resourceName))
- Assert.Fail("No mock data for test");
-
- using var stream2 = Assembly.GetExecutingAssembly()
- .GetManifestResourceStream(resourceName)!;
-
- using (var reader = new StreamReader(stream2))
- using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
- {
- var dataSaubMaps = csv.GetRecords().ToList();
- var expectedData = dataSaubMaps.Select(x => x.Adapt()).ToArray();
-
- //assert
- var actual = actualData
- .OrderBy(d => d.IdFeedRegulator)
- .ToArray();
-
- var expected = expectedData
- .OrderBy(d => d.IdFeedRegulator)
- .ToArray();
-
- Assert.Equal(expected.Count(), actual.Count());
-
- for (var i = 0; i < actual.Count(); i++)
- {
- var expectedItem = expected[i];
- var actualItem = actual[i];
-
- Assert.True(Math.Abs(expectedItem.DepthStart - actualItem.DepthStart) < 0.000001);
- Assert.True(Math.Abs(expectedItem.DepthEnd - actualItem.DepthEnd) < 0.000001);
- Assert.True(Math.Abs(expectedItem.DepthDrillingQuality - actualItem.DepthDrillingQuality) < 0.000001);
- }
-
+ var expectedItem = expected[i];
+ var actualItem = actual[i];
+ Assert.True(Math.Abs(expectedItem.DepthStart - actualItem.DepthStart) < 0.000001);
+ Assert.True(Math.Abs(expectedItem.DepthEnd - actualItem.DepthEnd) < 0.000001);
+ Assert.True(Math.Abs(expectedItem.DepthDrillingQuality - actualItem.DepthDrillingQuality) < 0.000001);
}
}
}
diff --git a/AsbCloudInfrastructure.Tests/Services/DataSaubStat/test1_result.csv b/AsbCloudInfrastructure.Tests/Services/DataSaubStat/test1_result.csv
index 64c49983..fe77a356 100644
--- a/AsbCloudInfrastructure.Tests/Services/DataSaubStat/test1_result.csv
+++ b/AsbCloudInfrastructure.Tests/Services/DataSaubStat/test1_result.csv
@@ -1,2 +1,2 @@
-"id_telemetry","depth_start","depth_end","depth_drilling_quality"
-419,46,251.279998779297,0.0
+"id_telemetry","depth_start","depth_end","id_feed_regulator","depth_drilling_quality"
+618,303.545989990234,493.545989990234,1,50.00