Правка падения в WellOperationExportServiceTest (сравнивались даты со смещением и без)

This commit is contained in:
Olga Nemt 2024-02-29 13:45:28 +05:00
parent 2ece8cdb9f
commit d55b9b4138

View File

@ -5,11 +5,9 @@ using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudApp.Services.WellOperationImport;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Repository;
using AsbCloudInfrastructure.Services.WellOperationImport;
using AsbCloudInfrastructure.Services.WellOperationImport.FileParser;
using NSubstitute;
using SignalRSwaggerGen.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
@ -34,41 +32,6 @@ namespace AsbCloudWebApi.Tests.Services.WellOperationExport
private WellOperationImportService wellOperationImportService;
private IWellOperationExcelParser<WellOperationImportDefaultOptionsDto> wellOperationDefaultExcelParser;
private readonly WellOperationDto[] operations = new WellOperationDto[2] {
new WellOperationDto() {
Id = 5,
IdWell = idWell,
IdUser = 1,
IdType = 0,
IdWellSectionType = 1,
WellSectionTypeName = "1",
IdCategory = 1,
CategoryName = "1",
CategoryInfo = "CategoryInfo 1",
DepthStart = 10,
DepthEnd = 20,
DateStart = GetDate(days: 0),
DurationHours = 10,
Comment = "Комментарий 1",
},
new WellOperationDto() {
Id = 6,
IdWell = idWell,
IdUser = 1,
IdType = 0,
IdWellSectionType = 2,
WellSectionTypeName = "2",
IdCategory = 2,
CategoryName = "2",
CategoryInfo = "CategoryInfo 2",
DepthStart = 20,
DepthEnd = 30,
DateStart = GetDate(days: 1),
DurationHours = 20,
Comment = "Комментарий 2",
}
};
private readonly WellSectionTypeDto[] sectionTypes = new WellSectionTypeDto[2]
{
new WellSectionTypeDto()
@ -106,12 +69,6 @@ namespace AsbCloudWebApi.Tests.Services.WellOperationExport
};
private readonly ITestOutputHelper output;
private static DateTime GetDate(int days)
{
var date = DateTime.Now.AddDays(days);
return new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second);
}
public WellOperationExportServiceTest(ITestOutputHelper output)
{
wellService = Substitute.For<IWellService>();
@ -123,17 +80,20 @@ namespace AsbCloudWebApi.Tests.Services.WellOperationExport
wellOperationImportService = new WellOperationImportService(wellService, wellOperationRepository, wellOperationCategoryRepository);
wellOperationDefaultExcelParser = new WellOperationDefaultExcelParser();
this.output = output;
wellService.GetTimezone(idWell).Returns(new SimpleTimezoneDto()
{
Hours = 5
});
}
[Fact]
public async Task Check_Exported_WellOperations_With_Operations_In_Db()
{
wellService.GetTimezone(idWell).Returns(new SimpleTimezoneDto()
{
Hours = 5
});
var operations = getOperations();
var localOperations = operations.ToArray();
foreach (var operation in localOperations)
operation.Id = 0;
@ -161,6 +121,7 @@ namespace AsbCloudWebApi.Tests.Services.WellOperationExport
public void TestDataContainsNotDefaultProps()
{
var initOk = true;
var operations = getOperations();
for (int i = 0; i < operations.Length; i++)
{
var operation = operations[i];
@ -204,5 +165,52 @@ namespace AsbCloudWebApi.Tests.Services.WellOperationExport
yield return prop.Name;
}
}
private WellOperationDto[] getOperations()
{
var timezone = wellService.GetTimezone(idWell);
DateTimeOffset GetDate(int days)
{
var date = DateTimeOffset.UtcNow.AddDays(days);
return new DateTimeOffset(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, TimeSpan.FromHours(timezone.Hours));
}
return new WellOperationDto[2] {
new WellOperationDto() {
Id = 5,
IdWell = idWell,
IdUser = 1,
IdType = 0,
IdWellSectionType = 1,
WellSectionTypeName = "1",
IdCategory = 1,
CategoryName = "1",
CategoryInfo = "CategoryInfo 1",
DepthStart = 10,
DepthEnd = 20,
DateStart = GetDate(days: 0),
DurationHours = 10,
Comment = "Комментарий 1",
},
new WellOperationDto() {
Id = 6,
IdWell = idWell,
IdUser = 1,
IdType = 0,
IdWellSectionType = 2,
WellSectionTypeName = "2",
IdCategory = 2,
CategoryName = "2",
CategoryInfo = "CategoryInfo 2",
DepthStart = 20,
DepthEnd = 30,
DateStart = GetDate(days: 1),
DurationHours = 20,
Comment = "Комментарий 2",
}
};
}
}
}