forked from ddrilling/AsbCloudServer
Правка автотестов по результатам ревью + отдельный хелпер для извлечения замоканных данных
This commit is contained in:
parent
edb7d93a62
commit
f0f8044e77
46
AsbCloudInfrastructure.Tests/CsvMockHelper.cs
Normal file
46
AsbCloudInfrastructure.Tests/CsvMockHelper.cs
Normal file
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Хелпер, который помогает получать мок-данные из csv файла
|
||||
/// </summary>
|
||||
public static class CsvMockHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// метод получения данных из файла
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="path">путь до файла</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentInvalidException"></exception>
|
||||
public static IEnumerable<T> Get<T>(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<T>().ToArray();
|
||||
return dataSaubMaps;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -39,56 +39,24 @@ 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();
|
||||
|
||||
if (String.IsNullOrEmpty(resourceName))
|
||||
Assert.Fail("No mock data for test");
|
||||
|
||||
using var stream = Assembly.GetExecutingAssembly()
|
||||
.GetManifestResourceStream(resourceName)!;
|
||||
|
||||
var actualData = Enumerable.Empty<DataSaubStatDrillingQualityDto>();
|
||||
|
||||
using (var reader = new StreamReader(stream))
|
||||
using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
|
||||
{
|
||||
var dataSaubMaps = csv.GetRecords<TelemetryDataSaubMap>().ToList();
|
||||
|
||||
var dtos = dataSaubMaps.Select(x => x.Adapt<TelemetryDataSaubDto>()).ToArray();
|
||||
var mockData = CsvMockHelper.Get<TelemetryDataSaubMap>(pathMockData);
|
||||
var dtoMockData = mockData.Select(x => x.Adapt<TelemetryDataSaubDto>()).ToArray();
|
||||
|
||||
dataSaubServiceMock
|
||||
.Get(Arg.Any<int>(), Arg.Any<bool>(), Arg.Any<DateTimeOffset>(), Arg.Any<DateTimeOffset>(), Arg.Any<int>(), Arg.Any<CancellationToken>())
|
||||
.Returns(dtos);
|
||||
.Returns(dtoMockData);
|
||||
|
||||
//act
|
||||
actualData = await dataSaubStatService.CreateStatDrillingQualityForTelemetry(1, DateTimeOffset.UnixEpoch, CancellationToken.None);
|
||||
}
|
||||
var 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<DataSaubStatDrillingQualityDtoMap>().ToList();
|
||||
var expectedData = dataSaubMaps.Select(x => x.Adapt<DataSaubStatDrillingQualityDto>()).ToArray();
|
||||
var mockDataResult = CsvMockHelper.Get<DataSaubStatDrillingQualityDtoMap>(pathResult);
|
||||
var expectedData = mockDataResult.Select(x => x.Adapt<DataSaubStatDrillingQualityDto>()).ToArray();
|
||||
|
||||
//assert
|
||||
var actual = actualData
|
||||
@ -110,9 +78,6 @@ public class DataSaubStatDtillingQualityServiceTest
|
||||
Assert.True(Math.Abs(expectedItem.DepthEnd - actualItem.DepthEnd) < 0.000001);
|
||||
Assert.True(Math.Abs(expectedItem.DepthDrillingQuality - actualItem.DepthDrillingQuality) < 0.000001);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user