From f570e82b410ecc8f5f254c4d5b061b666bfc59ae Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Wed, 28 Feb 2024 13:11:44 +0500 Subject: [PATCH 1/4] =?UTF-8?q?=D0=98=D0=BD=D1=82=D0=B5=D0=B3=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=BE=D0=BD=D0=BD=D1=8B=D0=B9=20=D1=82=D0=B5=D1=81?= =?UTF-8?q?=D1=82=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=80=D1=82=D0=BA-=D0=BE=D1=82?= =?UTF-8?q?=D1=87=D0=B5=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Clients/IProcessMapReportDrilling.cs | 16 ++ .../ProcessMapReportDrillingControllerTest.cs | 237 ++++++++++++++++++ 2 files changed, 253 insertions(+) create mode 100644 AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs create mode 100644 AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs diff --git a/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs b/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs new file mode 100644 index 00000000..b721df75 --- /dev/null +++ b/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs @@ -0,0 +1,16 @@ +using AsbCloudApp.Data; +using AsbCloudApp.Data.ProcessMaps; +using AsbCloudApp.Data.ProcessMaps.Report; +using AsbCloudApp.Requests; +using Microsoft.AspNetCore.Mvc; +using Refit; + +namespace AsbCloudWebApi.IntegrationTests.Clients; + +public interface IProcessMapReportDrilling +{ + private const string BaseRoute = "/api/well/{idWell}/ProcessMapReportDrilling"; + + [Get($"{BaseRoute}/report")] + Task>> GetReportAsync(int idWell, [FromQuery] DataSaubStatRequest request, CancellationToken cancellationToken); +} diff --git a/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs b/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs new file mode 100644 index 00000000..2d08b0c8 --- /dev/null +++ b/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs @@ -0,0 +1,237 @@ +using AsbCloudApp.Requests; +using AsbCloudDb.Model.ProcessMapPlan; +using AsbCloudWebApi.IntegrationTests.Clients; +using Mapster; +using Microsoft.EntityFrameworkCore; +using System.Net; +using System.Reflection; +using AsbCloudDb.Model.ProcessMaps; +using AsbCloudWebApi.IntegrationTests.Data; +using Refit; +using Xunit; +using AsbCloudApp.Data.ProcessMaps; +using AsbCloudDb.Model; + +namespace AsbCloudWebApi.IntegrationTests.Controllers.ProcessMapPlan; + +public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest +{ + + private readonly WellSectionType wellSection = new WellSectionType() + { + Id = 1, + Caption = "Секция 1", + Order = 1 + }; + + private readonly WellOperationCategory wellOperationCategory = new WellOperationCategory() + { + Id = 1, + IdParent = null, + KeyValueName = "Name", + Name = "Name" + }; + + private readonly WellOperation wellOperation = new WellOperation() + { + CategoryInfo= "CategoryInfo", + Id = 10, + Comment = "Comment", + DateStart = DateTimeOffset.UtcNow, + DepthEnd = 1, + DepthStart = 0.6, + DurationHours = 10, + IdCategory = 1, + IdPlan = null, + IdType = 1, + IdUser = 1, + IdWell = 1, + IdWellSectionType = 1, + LastUpdateDate = DateTimeOffset.UtcNow + }; + + private readonly List dataSaubStats = new List() + { + + new DataSaubStat() + { + AxialLoad = 0, + AxialLoadLimitMax = 10, + AxialLoadSp = 8, + BlockSpeedSp = 50.0, + DateEnd = DateTimeOffset.UtcNow, + DateStart = DateTimeOffset.UtcNow.AddDays(-1), + DepthEnd = 85.99299621582031, + DepthStart = 85.9260025024414, + EnabledSubsystems = 0, + Flow = 10, + HasOscillation = true, + Id = 1, + IdCategory = 1, + IdFeedRegulator = 0, + IdTelemetry = 1, + Pressure = 24, + PressureIdle = 0, + PressureSp = 40, + RotorSpeed = 11.3, + RotorTorque = 1, + RotorTorqueLimitMax = 26.5, + RotorTorqueSp = 5, + Speed = 80.3924560546875 + }, + new DataSaubStat() + { + AxialLoad = 2, + AxialLoadLimitMax = 10.0, + AxialLoadSp = 8, + BlockSpeedSp = 20, + DateEnd = DateTimeOffset.UtcNow.AddDays(-1), + DateStart = DateTimeOffset.UtcNow.AddDays(-2), + DepthEnd = 86.28099822998047, + DepthStart = 86.21900177001953, + EnabledSubsystems = 1, + Flow = 20, + HasOscillation = true, + Id = 2, + IdCategory = 1, + IdFeedRegulator = 1, + IdTelemetry = 1, + Pressure = 30, + PressureIdle = 20, + PressureSp = 40, + RotorSpeed = 11.251153300212916, + RotorTorque = 7, + RotorTorqueLimitMax = 26.5, + RotorTorqueSp = 9, + Speed = 74.395751953125 + }, + new DataSaubStat() + { + AxialLoad = 4, + AxialLoadLimitMax = 15.0, + AxialLoadSp = 8, + BlockSpeedSp = 110.0, + DateEnd = DateTimeOffset.UtcNow.AddDays(-2), + DateStart = DateTimeOffset.UtcNow.AddDays(-3), + DepthEnd = 106.7490005493164, + DepthStart = 106.47899627685547, + EnabledSubsystems = 1, + Flow = 30, + HasOscillation = true, + Id = 3, + IdCategory = 1, + IdFeedRegulator = 1, + IdTelemetry = 1, + Pressure = 36, + PressureIdle = 23.0, + PressureSp = 63.0, + RotorSpeed = 11.334207942999628, + RotorTorque = 14, + RotorTorqueLimitMax = 15.0, + RotorTorqueSp = 13, + Speed = 108.001708984375 + } + }; + + + + + private readonly ProcessMapPlanDrilling entity = new () + { + Id = 0, + IdAuthor = 1, + IdEditor = null, + Creation = DateTimeOffset.UtcNow, + Obsolete = null, + IdState = AsbCloudDb.Model.ChangeLogAbstract.IdStateActual, + IdPrevious = null, + + IdWell = 1, + IdWellSectionType = 1, + DepthStart = 0.5, + DepthEnd = 1.5, + + IdMode = 1, + AxialLoadPlan = 2.718281, + AxialLoadLimitMax = 3.1415926, + DeltaPressurePlan = 4, + DeltaPressureLimitMax = 5, + TopDriveTorquePlan = 6, + TopDriveTorqueLimitMax = 7, + TopDriveSpeedPlan = 8, + TopDriveSpeedLimitMax = 9, + FlowPlan = 10, + FlowLimitMax = 11, + RopPlan = 12, + UsageSaub = 13, + UsageSpin = 14, + Comment = "это тестовая запись", + }; + + private IProcessMapReportDrilling client; + + public ProcessMapReportDrillingControllerTest(WebAppFactoryFixture factory) : base(factory) + { + dbContext.CleanupDbSet(); + client = factory.GetAuthorizedHttpClient(); + } + + + + [Fact] + public async Task Get_rtk_report_returns_success() + { + //arrange + var dbset = dbContext.Set(); + dbset.Add(entity); + entity.Id = 1; + dbset.Add(entity); + entity.Id = 2; + dbset.Add(entity); + + var dbSetWellOperationCategory = dbContext.Set(); + dbSetWellOperationCategory.Add(wellOperationCategory); + + var dbSetWellOperation = dbContext.Set(); + dbSetWellOperation.Add(wellOperation); + + var dbSetDataSaubStat = dbContext.Set(); + dbSetDataSaubStat.AddRange(dataSaubStats); + + dbContext.SaveChanges(); + + //act + var request = new DataSaubStatRequest(); + var response = await client.GetReportAsync(1, request, CancellationToken.None); + + //assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.NotNull(response.Content); + Assert.Equal(dataSaubStats.Count() - 1, response.Content.Count()); + + //act + request = new DataSaubStatRequest() { + DeltaAxialLoad = 5, + DeltaPressure = 15, + DeltaRotorTorque = 10 + }; + response = await client.GetReportAsync(1, request, CancellationToken.None); + + //assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.NotNull(response.Content); + Assert.Equal(1, response.Content.Count()); + + //act + request = new DataSaubStatRequest() + { + DeltaAxialLoad = 15, + DeltaPressure = 25, + DeltaRotorTorque = 20 + }; + response = await client.GetReportAsync(1, request, CancellationToken.None); + + //assert + Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); + } +} From b389b181d5dd18379823dec7df08b0fd69bad6e0 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Thu, 29 Feb 2024 09:10:15 +0500 Subject: [PATCH 2/4] =?UTF-8?q?=D0=98=D0=BD=D1=82=D0=B5=D0=B3=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=BE=D0=BD=D0=BD=D1=8B=D0=B5=20=D1=82=D0=B5=D1=81?= =?UTF-8?q?=D1=82=20=D0=BD=D0=B0=20=D1=81=D0=BA=D0=B0=D0=B8=D1=87=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=A0=D0=A2=D0=9A-=D0=BE=D1=82?= =?UTF-8?q?=D1=87=D0=B5=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Clients/IProcessMapReportDrilling.cs | 4 ++ .../ProcessMapReportDrillingControllerTest.cs | 38 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs b/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs index b721df75..12adac91 100644 --- a/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs +++ b/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs @@ -13,4 +13,8 @@ public interface IProcessMapReportDrilling [Get($"{BaseRoute}/report")] Task>> GetReportAsync(int idWell, [FromQuery] DataSaubStatRequest request, CancellationToken cancellationToken); + + [Get($"{BaseRoute}/report/export")] + Task> ExportReportAsync(int idWell, [FromQuery] DataSaubStatRequest request, CancellationToken cancellationToken); + } diff --git a/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs b/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs index 2d08b0c8..77951c23 100644 --- a/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs +++ b/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs @@ -172,7 +172,6 @@ public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest public ProcessMapReportDrillingControllerTest(WebAppFactoryFixture factory) : base(factory) { - dbContext.CleanupDbSet(); client = factory.GetAuthorizedHttpClient(); } @@ -181,6 +180,9 @@ public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest [Fact] public async Task Get_rtk_report_returns_success() { + //clear + dbContext.CleanupDbSet(); + //arrange var dbset = dbContext.Set(); dbset.Add(entity); @@ -234,4 +236,38 @@ public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest //assert Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); } + + [Fact] + public async Task Export_rtk_report_returns_success() + { + //clear + dbContext.CleanupDbSet(); + + //arrange + var dbset = dbContext.Set(); + dbset.Add(entity); + entity.Id = 1; + dbset.Add(entity); + entity.Id = 2; + dbset.Add(entity); + + var dbSetWellOperationCategory = dbContext.Set(); + dbSetWellOperationCategory.Add(wellOperationCategory); + + var dbSetWellOperation = dbContext.Set(); + dbSetWellOperation.Add(wellOperation); + + var dbSetDataSaubStat = dbContext.Set(); + dbSetDataSaubStat.AddRange(dataSaubStats); + + dbContext.SaveChanges(); + + //act + var request = new DataSaubStatRequest(); + var response = await client.ExportReportAsync(1, request, CancellationToken.None); + + //assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.NotNull(response.Content); + } } From 2ece8cdb9f6d1055ce45db6a30aeab80f9fe2b72 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Thu, 29 Feb 2024 13:08:53 +0500 Subject: [PATCH 3/4] =?UTF-8?q?=D0=94=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=BE=D0=B4=D0=BD=D0=BE=D0=B3=D0=BE=20=D1=82=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D0=B0=20=D1=81=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=D0=BC=20=D1=80=D1=82=D0=BA-=D0=BE=D1=82?= =?UTF-8?q?=D1=87=D0=B5=D1=82=D0=B0=20=D0=BD=D0=B0=20=D0=BD=D0=B5=D1=81?= =?UTF-8?q?=D0=BA=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Clients/IProcessMapReportDrilling.cs | 2 +- .../ProcessMapReportDrillingControllerTest.cs | 114 ++++++++++++------ 2 files changed, 79 insertions(+), 37 deletions(-) diff --git a/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs b/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs index 12adac91..92a4353b 100644 --- a/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs +++ b/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs @@ -15,6 +15,6 @@ public interface IProcessMapReportDrilling Task>> GetReportAsync(int idWell, [FromQuery] DataSaubStatRequest request, CancellationToken cancellationToken); [Get($"{BaseRoute}/report/export")] - Task> ExportReportAsync(int idWell, [FromQuery] DataSaubStatRequest request, CancellationToken cancellationToken); + Task> ExportReportAsync(int idWell, [FromQuery] DataSaubStatRequest request, CancellationToken cancellationToken); } diff --git a/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs b/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs index 77951c23..3083d514 100644 --- a/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs +++ b/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs @@ -1,27 +1,22 @@ using AsbCloudApp.Requests; -using AsbCloudDb.Model.ProcessMapPlan; -using AsbCloudWebApi.IntegrationTests.Clients; -using Mapster; -using Microsoft.EntityFrameworkCore; -using System.Net; -using System.Reflection; -using AsbCloudDb.Model.ProcessMaps; -using AsbCloudWebApi.IntegrationTests.Data; -using Refit; -using Xunit; -using AsbCloudApp.Data.ProcessMaps; using AsbCloudDb.Model; +using AsbCloudDb.Model.ProcessMaps; +using AsbCloudWebApi.IntegrationTests.Clients; +using Org.BouncyCastle.Asn1.Ocsp; +using System.Net; +using System.Net.Http.Headers; +using Xunit; namespace AsbCloudWebApi.IntegrationTests.Controllers.ProcessMapPlan; -public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest +public class ProcessMapReportDrillingControllerTest : BaseIntegrationTest { private readonly WellSectionType wellSection = new WellSectionType() { - Id = 1, - Caption = "Секция 1", - Order = 1 + Id = 1, + Caption = "Секция 1", + Order = 1 }; private readonly WellOperationCategory wellOperationCategory = new WellOperationCategory() @@ -29,12 +24,12 @@ public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest Id = 1, IdParent = null, KeyValueName = "Name", - Name = "Name" + Name = "Name" }; private readonly WellOperation wellOperation = new WellOperation() { - CategoryInfo= "CategoryInfo", + CategoryInfo = "CategoryInfo", Id = 10, Comment = "Comment", DateStart = DateTimeOffset.UtcNow, @@ -59,8 +54,8 @@ public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest AxialLoadLimitMax = 10, AxialLoadSp = 8, BlockSpeedSp = 50.0, - DateEnd = DateTimeOffset.UtcNow, - DateStart = DateTimeOffset.UtcNow.AddDays(-1), + DateEnd = DateTimeOffset.UtcNow.AddMinutes(40), + DateStart = DateTimeOffset.UtcNow.AddMinutes(30), DepthEnd = 85.99299621582031, DepthStart = 85.9260025024414, EnabledSubsystems = 0, @@ -85,8 +80,8 @@ public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest AxialLoadLimitMax = 10.0, AxialLoadSp = 8, BlockSpeedSp = 20, - DateEnd = DateTimeOffset.UtcNow.AddDays(-1), - DateStart = DateTimeOffset.UtcNow.AddDays(-2), + DateEnd = DateTimeOffset.UtcNow.AddMinutes(30), + DateStart = DateTimeOffset.UtcNow.AddMinutes(20), DepthEnd = 86.28099822998047, DepthStart = 86.21900177001953, EnabledSubsystems = 1, @@ -111,8 +106,8 @@ public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest AxialLoadLimitMax = 15.0, AxialLoadSp = 8, BlockSpeedSp = 110.0, - DateEnd = DateTimeOffset.UtcNow.AddDays(-2), - DateStart = DateTimeOffset.UtcNow.AddDays(-3), + DateEnd = DateTimeOffset.UtcNow.AddMinutes(20), + DateStart = DateTimeOffset.UtcNow.AddMinutes(10), DepthEnd = 106.7490005493164, DepthStart = 106.47899627685547, EnabledSubsystems = 1, @@ -136,7 +131,7 @@ public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest - private readonly ProcessMapPlanDrilling entity = new () + private readonly ProcessMapPlanDrilling entity = new() { Id = 0, IdAuthor = 1, @@ -172,18 +167,15 @@ public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest public ProcessMapReportDrillingControllerTest(WebAppFactoryFixture factory) : base(factory) { - client = factory.GetAuthorizedHttpClient(); + client = factory.GetAuthorizedHttpClient(string.Empty); } - [Fact] - public async Task Get_rtk_report_returns_success() + public async Task Get_rtk_report_by_default_request_returns_success() { - //clear - dbContext.CleanupDbSet(); - //arrange + dbContext.CleanupDbSet(); var dbset = dbContext.Set(); dbset.Add(entity); entity.Id = 1; @@ -210,28 +202,77 @@ public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(response.Content); Assert.Equal(dataSaubStats.Count() - 1, response.Content.Count()); + } + + [Fact] + public async Task Get_rtk_report_by_parametrize_request_returns_success() + { + //arrange + dbContext.CleanupDbSet(); + var dbset = dbContext.Set(); + dbset.Add(entity); + entity.Id = 1; + dbset.Add(entity); + entity.Id = 2; + dbset.Add(entity); + + var dbSetWellOperationCategory = dbContext.Set(); + dbSetWellOperationCategory.Add(wellOperationCategory); + + var dbSetWellOperation = dbContext.Set(); + dbSetWellOperation.Add(wellOperation); + + var dbSetDataSaubStat = dbContext.Set(); + dbSetDataSaubStat.AddRange(dataSaubStats); + + dbContext.SaveChanges(); //act - request = new DataSaubStatRequest() { + var request = new DataSaubStatRequest() + { DeltaAxialLoad = 5, DeltaPressure = 15, DeltaRotorTorque = 10 }; - response = await client.GetReportAsync(1, request, CancellationToken.None); + var response = await client.GetReportAsync(1, request, CancellationToken.None); //assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(response.Content); - Assert.Equal(1, response.Content.Count()); + Assert.Equal(1, response.Content.Count()); + } + + [Fact] + public async Task Get_rtk_report_returns_BadRequest() + { + //arrange + dbContext.CleanupDbSet(); + var dbset = dbContext.Set(); + dbset.Add(entity); + entity.Id = 1; + dbset.Add(entity); + entity.Id = 2; + dbset.Add(entity); + + var dbSetWellOperationCategory = dbContext.Set(); + dbSetWellOperationCategory.Add(wellOperationCategory); + + var dbSetWellOperation = dbContext.Set(); + dbSetWellOperation.Add(wellOperation); + + var dbSetDataSaubStat = dbContext.Set(); + dbSetDataSaubStat.AddRange(dataSaubStats); + + dbContext.SaveChanges(); //act - request = new DataSaubStatRequest() + var request = new DataSaubStatRequest() { DeltaAxialLoad = 15, DeltaPressure = 25, DeltaRotorTorque = 20 }; - response = await client.GetReportAsync(1, request, CancellationToken.None); + var response = await client.GetReportAsync(1, request, CancellationToken.None); //assert Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); @@ -268,6 +309,7 @@ public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest //assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.NotNull(response.Content); + Assert.Equal("application/octet-stream", response.ContentHeaders?.ContentType?.MediaType); + Assert.True(response.ContentHeaders?.ContentLength > 0); } } From d55b9b41386e2506b914b0c0ec25d69a43b4e569 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Thu, 29 Feb 2024 13:45:28 +0500 Subject: [PATCH 4/4] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=BF=D0=B0=D0=B4=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B2=20WellOpera?= =?UTF-8?q?tionExportServiceTest=20(=D1=81=D1=80=D0=B0=D0=B2=D0=BD=D0=B8?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=D0=B8=D1=81=D1=8C=20=D0=B4=D0=B0=D1=82=D1=8B?= =?UTF-8?q?=20=D1=81=D0=BE=20=D1=81=D0=BC=D0=B5=D1=89=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=D0=BC=20=D0=B8=20=D0=B1=D0=B5=D0=B7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WellOperationExportServiceTest.cs | 102 ++++++++++-------- 1 file changed, 55 insertions(+), 47 deletions(-) diff --git a/AsbCloudWebApi.Tests/Services/WellOperationExport/WellOperationExportServiceTest.cs b/AsbCloudWebApi.Tests/Services/WellOperationExport/WellOperationExportServiceTest.cs index 0c8523c4..ad3d3895 100644 --- a/AsbCloudWebApi.Tests/Services/WellOperationExport/WellOperationExportServiceTest.cs +++ b/AsbCloudWebApi.Tests/Services/WellOperationExport/WellOperationExportServiceTest.cs @@ -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 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(); @@ -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", + } + }; + } } }