diff --git a/AsbCloudWebApi.Tests/UnitTests/Services/WellOperationExport/WellOperationExportServiceTest.cs b/AsbCloudWebApi.Tests/UnitTests/Services/WellOperationExport/WellOperationExportServiceTest.cs index 919dda4d..c22c5fa0 100644 --- a/AsbCloudWebApi.Tests/UnitTests/Services/WellOperationExport/WellOperationExportServiceTest.cs +++ b/AsbCloudWebApi.Tests/UnitTests/Services/WellOperationExport/WellOperationExportServiceTest.cs @@ -9,7 +9,7 @@ using AsbCloudInfrastructure.Services.WellOperationImport; using AsbCloudInfrastructure.Services.WellOperationImport.FileParser; using NSubstitute; using System; -using System.Linq; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -27,49 +27,31 @@ namespace AsbCloudWebApi.Tests.UnitTests.Services.WellOperationExport private WellOperationImportService wellOperationImportService; private IWellOperationExcelParser wellOperationDefaultExcelParser; - public WellOperationExportServiceTest() - { - wellService = Substitute.For(); - wellOperationRepository = Substitute.For(); - wellOperationImportTemplateService = new WellOperationImportTemplateService(); - wellOperationExportService = new WellOperationExportService(wellOperationRepository, wellService, wellOperationImportTemplateService); - - wellOperationImportService = new WellOperationImportService(wellOperationRepository); - wellOperationDefaultExcelParser = new WellOperationDefaultExcelParser(); - } private readonly WellOperationDto[] operations = new WellOperationDto[2] { new WellOperationDto() { - CategoryInfo = "1", - Comment = "1", - DateStart = DateTime.Now, - Day = 0, - DepthStart = 10, - DurationHours = 10, - DepthEnd = 20, - IdCategory = 1, - Id = 1, - IdPlan = 1, - IdType = 0, IdWell = idWell, + IdUser = 1, + IdType = 0, IdWellSectionType = 1, - NptHours = 10 + IdCategory = 1, + CategoryInfo = "1", + DepthStart = 10, + DepthEnd = 20, + DateStart = getDate(days: 0), + DurationHours = 10, }, new WellOperationDto() { - CategoryInfo = "2", - Comment = "2", - DateStart = DateTime.Now.AddDays(1), - Day = 0, - DepthStart = 20, - DurationHours = 20, - DepthEnd = 30, - IdCategory = 2, - Id = 2, - IdPlan = 1, - IdType = 0, IdWell = idWell, + IdUser = 1, + IdType = 0, IdWellSectionType = 2, - NptHours = 20 + IdCategory = 2, + CategoryInfo = "2", + DepthStart = 20, + DepthEnd = 30, + DateStart = getDate(days: 1), + DurationHours = 20, } }; @@ -109,9 +91,30 @@ namespace AsbCloudWebApi.Tests.UnitTests.Services.WellOperationExport } }; - [Fact] - public async Task Check_exported_dates() + 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() + { + wellService = Substitute.For(); + wellOperationRepository = Substitute.For(); + wellOperationImportTemplateService = new WellOperationImportTemplateService(); + wellOperationExportService = new WellOperationExportService(wellOperationRepository, wellService, wellOperationImportTemplateService); + + wellOperationImportService = new WellOperationImportService(wellOperationRepository); + wellOperationDefaultExcelParser = new WellOperationDefaultExcelParser(); + } + + [Fact] + public async Task Check_Exported_WellOperations_With_Operations_In_Db() + { + wellService.GetTimezone(idWell).Returns(new SimpleTimezoneDto() + { + Hours = 5 + }); wellOperationRepository.GetAsync(Arg.Any(), Arg.Any()) .ReturnsForAnyArgs(operations); wellOperationRepository.GetSectionTypes().Returns(sectionTypes); @@ -126,9 +129,10 @@ namespace AsbCloudWebApi.Tests.UnitTests.Services.WellOperationExport var sheet = wellOperationDefaultExcelParser.Parse(stream, options); var result = wellOperationImportService.Import(idWell, 1, options.IdType, sheet); - var expectedDates = operations.Select(o => o.DateStart.ToString("yyyy-MM-dd HH:mm:ss")); - var realDates = result.Select(o => o.DateStart.ToString("yyyy-MM-dd HH:mm:ss")); - Assert.Equal(expectedDates, realDates); + var expected = JsonSerializer.Serialize(operations); + var actual = JsonSerializer.Serialize(result); + + Assert.Equal(expected, actual); } }