From 97179fac12ad3d211c6269afd65c431909d9ddb3 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Wed, 20 Dec 2023 10:51:42 +0500 Subject: [PATCH] =?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); + } + } + +}