From 97179fac12ad3d211c6269afd65c431909d9ddb3 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Wed, 20 Dec 2023 10:51:42 +0500 Subject: [PATCH 1/2] =?UTF-8?q?=D0=A2=D0=B5=D1=81=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=B0=D1=82=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=20=D0=B2=D1=8B=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B5?= =?UTF-8?q?=20=D0=BE=D1=82=D1=87=D0=B5=D1=82=D0=B0=20=D0=93=D0=93=D0=94=20?= =?UTF-8?q?(=D0=BF=D0=BB=D0=B0=D0=BD)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WellOperationExportServiceTest.cs | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 AsbCloudWebApi.Tests/UnitTests/Services/WellOperationExport/WellOperationExportServiceTest.cs diff --git a/AsbCloudWebApi.Tests/UnitTests/Services/WellOperationExport/WellOperationExportServiceTest.cs b/AsbCloudWebApi.Tests/UnitTests/Services/WellOperationExport/WellOperationExportServiceTest.cs new file mode 100644 index 00000000..919dda4d --- /dev/null +++ b/AsbCloudWebApi.Tests/UnitTests/Services/WellOperationExport/WellOperationExportServiceTest.cs @@ -0,0 +1,135 @@ +using AsbCloudApp.Data; +using AsbCloudApp.Data.WellOperationImport.Options; +using AsbCloudApp.Repositories; +using AsbCloudApp.Requests; +using AsbCloudApp.Services; +using AsbCloudApp.Services.WellOperationImport; +using AsbCloudDb.Model; +using AsbCloudInfrastructure.Services.WellOperationImport; +using AsbCloudInfrastructure.Services.WellOperationImport.FileParser; +using NSubstitute; +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace AsbCloudWebApi.Tests.UnitTests.Services.WellOperationExport +{ + public class WellOperationExportServiceTest + { + private const int idWell = 4; + + private IWellService wellService; + private IWellOperationRepository wellOperationRepository; + private IWellOperationImportTemplateService wellOperationImportTemplateService; + private WellOperationExportService wellOperationExportService; + 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, + IdWellSectionType = 1, + NptHours = 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, + IdWellSectionType = 2, + NptHours = 20 + } + }; + + private readonly WellSectionTypeDto[] sectionTypes = new WellSectionTypeDto[2] + { + new WellSectionTypeDto() + { + Caption = "1", + Id = 1, + Order = 0 + }, + new WellSectionTypeDto() + { + Caption = "2", + Id = 2, + Order = 1 + } + }; + + private readonly WellOperationCategoryDto[] categories = new WellOperationCategoryDto[2] + { + new WellOperationCategoryDto() + { + Id = 1, + IdParent = 1, + KeyValueName = "1", + KeyValueUnits = "1", + Name = "1" + }, + new WellOperationCategoryDto() + { + Id = 2, + IdParent = 2, + KeyValueName = "2", + KeyValueUnits = "2", + Name = "2" + } + }; + + [Fact] + public async Task Check_exported_dates() + { + wellOperationRepository.GetAsync(Arg.Any(), Arg.Any()) + .ReturnsForAnyArgs(operations); + wellOperationRepository.GetSectionTypes().Returns(sectionTypes); + wellOperationRepository.GetCategories(false).Returns(categories); + + var stream = await wellOperationExportService.ExportAsync(idWell, CancellationToken.None); + + var options = new WellOperationImportDefaultOptionsDto + { + IdType = WellOperation.IdOperationTypePlan + }; + 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); + } + } + +} From 39742b505d7e62a43edb8ba27e39dde74467b4f5 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Wed, 20 Dec 2023 14:04:00 +0500 Subject: [PATCH 2/2] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B2=D1=81=D0=B5=D1=85=20=D0=BF=D0=BE=D0=BB=D0=B5?= =?UTF-8?q?=D0=B9=20=D0=BF=D1=80=D0=B8=20=D1=8D=D0=BA=D1=81=D0=BF=D0=BE?= =?UTF-8?q?=D1=80=D1=82=D0=B5=20=D0=B8=20=D0=B8=D0=BC=D0=BF=D0=BE=D1=80?= =?UTF-8?q?=D1=82=D0=B5=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B9?= =?UTF-8?q?=20=D0=93=D0=93=D0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WellOperationExportServiceTest.cs | 84 ++++++++++--------- 1 file changed, 44 insertions(+), 40 deletions(-) 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); } }