From 4b3bdef885dc16a6febf35e297c844d1ae92e6ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Mon, 5 Feb 2024 08:54:18 +0500 Subject: [PATCH 1/3] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B1=D0=BB=D0=B5=D0=BC=D1=8B=20=D1=87=D0=B0=D1=81=D0=BE?= =?UTF-8?q?=D0=B2=D1=8B=D1=85=20=D0=BF=D0=BE=D1=8F=D1=81=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Добавлены тесты 2. При добавлении новой скважины, дата начала операции приводится ко времени скважины --- .../Repository/WellOperationRepository.cs | 26 +++-- .../Clients/IWellOperationClient.cs | 8 +- .../WellOperationControllerTest.cs | 102 +++++++++++------- .../Controllers/WellOperationController.cs | 1 - 4 files changed, 86 insertions(+), 51 deletions(-) diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index ea9a6975..fe6cdeb9 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -223,8 +223,10 @@ public class WellOperationRepository : IWellOperationRepository { var query = BuildQuery(request) .AsNoTracking(); - var result = await query.ToArrayAsync(token); - return result; + + var dtos = await query.ToArrayAsync(token); + + return dtos; } /// @@ -411,8 +413,9 @@ public class WellOperationRepository : IWellOperationRepository { var entity = dto.Adapt(); entity.Id = default; - entity.DateStart = dto.DateStart.ToUniversalTime(); + entity.DateStart = dto.DateStart.DateTime.ToUtcDateTimeOffset(timezone.Hours); entity.IdWell = idWell; + entity.LastUpdateDate = DateTimeOffset.UtcNow; db.WellOperations.Add(entity); } @@ -429,7 +432,8 @@ public class WellOperationRepository : IWellOperationRepository { var timezone = wellService.GetTimezone(dto.IdWell); var entity = dto.Adapt(); - entity.DateStart = dto.DateStart.ToUniversalTime(); + entity.DateStart = dto.DateStart.DateTime.ToUtcDateTimeOffset(timezone.Hours); + entity.LastUpdateDate = DateTimeOffset.UtcNow; db.WellOperations.Update(entity); var result = await db.SaveChangesAsync(token); @@ -501,7 +505,7 @@ public class WellOperationRepository : IWellOperationRepository .Where(subOp => subOp.IdType == 1) .Where(subOp => WellOperationCategory.NonProductiveTimeSubIds.Contains(subOp.IdCategory)); - var result = query.Select(o => new WellOperationDto + var dtos = query.Select(o => new WellOperationDto { Id = o.Id, IdPlan = o.IdPlan, @@ -531,21 +535,21 @@ public class WellOperationRepository : IWellOperationRepository .Min(subOp => subOp.DateStart)) .TotalDays, IdUser = o.IdUser, - LastUpdateDate = o.LastUpdateDate.ToOffset(TimeSpan.FromHours(timezone.Hours)) + LastUpdateDate = DateTime.SpecifyKind(o.LastUpdateDate.UtcDateTime + timeZoneOffset, DateTimeKind.Unspecified) }); if (request.SortFields?.Any() == true) { - result = result.SortBy(request.SortFields); + dtos = dtos.SortBy(request.SortFields); } else { - result = result + dtos = dtos .OrderBy(e => e.DateStart) .ThenBy(e => e.DepthEnd) .ThenBy(e => e.Id); - }; - - return result; + } + + return dtos; } } diff --git a/AsbCloudWebApi.IntegrationTests/Clients/IWellOperationClient.cs b/AsbCloudWebApi.IntegrationTests/Clients/IWellOperationClient.cs index 2db55d36..07754ed1 100644 --- a/AsbCloudWebApi.IntegrationTests/Clients/IWellOperationClient.cs +++ b/AsbCloudWebApi.IntegrationTests/Clients/IWellOperationClient.cs @@ -1,5 +1,5 @@ using AsbCloudApp.Data; -using Microsoft.AspNetCore.Mvc; +using AsbCloudApp.Requests; using Refit; namespace AsbCloudWebApi.IntegrationTests.Clients; @@ -12,6 +12,10 @@ public interface IWellOperationClient Task> InsertRangeAsync(int idWell, int idType, bool deleteBeforeInsert, [Body] IEnumerable dtos); [Put(BaseRoute + "/{idOperation}")] - Task> UpdateAsync(int idWell, int idOperation, [FromBody] WellOperationDto value, CancellationToken token); + Task> UpdateAsync(int idWell, int idOperation, [Body] WellOperationDto value, CancellationToken token); + [Get(BaseRoute + "/plan")] + Task>> GetPageOperationsPlanAsync(int idWell, + [Query] WellOperationRequestBase request, + CancellationToken token); } \ No newline at end of file diff --git a/AsbCloudWebApi.IntegrationTests/Controllers/WellOperationControllerTest.cs b/AsbCloudWebApi.IntegrationTests/Controllers/WellOperationControllerTest.cs index 3ac32e40..a5e0064a 100644 --- a/AsbCloudWebApi.IntegrationTests/Controllers/WellOperationControllerTest.cs +++ b/AsbCloudWebApi.IntegrationTests/Controllers/WellOperationControllerTest.cs @@ -2,45 +2,43 @@ using AsbCloudApp.Data; using AsbCloudDb.Model; using AsbCloudWebApi.IntegrationTests.Clients; using System.Net; +using AsbCloudApp.Requests; using Xunit; namespace AsbCloudWebApi.IntegrationTests.Controllers; - public class WellOperationControllerTest : BaseIntegrationTest { private static int idWell = 1; - private readonly WellOperationDto[] dtos = new WellOperationDto[] - { - new WellOperationDto() - { - Id = 2, - IdWell = idWell, - IdType = 1, - DateStart = DateTimeOffset.Now, - CategoryInfo = "1", - CategoryName = "1", - Comment = "1", - Day = 1, - DepthEnd = 20, - DepthStart = 10, - DurationHours = 1, - IdCategory = 5000, - IdParentCategory = null, - IdPlan = null, - IdUser = 1, - IdWellSectionType = 1, - LastUpdateDate = DateTimeOffset.Now, - NptHours = 1, - WellSectionTypeName = null, - UserName = null - } - }; + private readonly WellOperationDto[] dtos = new WellOperationDto[] + { + new() + { + IdWell = 1, + IdWellSectionType = 1, + WellSectionTypeName = "Пилотный ствол", + IdCategory = 5000, + IdPlan = null, + CategoryName = "Разборка КНБК", + IdParentCategory = 4000, + CategoryInfo = "1", + IdType = 0, + DepthStart = 10.0, + DepthEnd = 20.0, + Day = 0.0, + NptHours = 0.0, + DateStart = new DateTimeOffset(new DateTime(2023, 02, 03, 1, 0, 0, DateTimeKind.Unspecified)), + DurationHours = 1.0, + Comment = "1", + IdUser = 1, + UserName = null, + } + }; private readonly WellOperationDto[] dtosWithError = new WellOperationDto[] { - new WellOperationDto() + new() { Id = 3, IdWell = idWell, @@ -63,7 +61,7 @@ public class WellOperationControllerTest : BaseIntegrationTest WellSectionTypeName = null, UserName = null }, - new WellOperationDto() + new() { Id = 4, IdWell = idWell, @@ -88,12 +86,12 @@ public class WellOperationControllerTest : BaseIntegrationTest } }; - private IWellOperationClient wellOperationClient; + private IWellOperationClient client; public WellOperationControllerTest(WebAppFactoryFixture factory) : base(factory) { - wellOperationClient = factory.GetAuthorizedHttpClient(); + client = factory.GetAuthorizedHttpClient(); } /// @@ -105,7 +103,7 @@ public class WellOperationControllerTest : BaseIntegrationTest { dbContext.CleanupDbSet(); //act - var response = await wellOperationClient.InsertRangeAsync(idWell, 1, false, dtos); + var response = await client.InsertRangeAsync(idWell, 1, false, dtos); //assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -120,7 +118,7 @@ public class WellOperationControllerTest : BaseIntegrationTest public async Task InsertRange_returns_error() { //act - var response = await wellOperationClient.InsertRangeAsync(idWell, 1, false, dtosWithError); + var response = await client.InsertRangeAsync(idWell, 1, false, dtosWithError); //assert Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); @@ -134,7 +132,7 @@ public class WellOperationControllerTest : BaseIntegrationTest public async Task InsertRangeWithDeleteBefore_returns_success() { //act - var response = await wellOperationClient.InsertRangeAsync(idWell, 1, true, dtos); + var response = await client.InsertRangeAsync(idWell, 1, true, dtos); //assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -148,7 +146,7 @@ public class WellOperationControllerTest : BaseIntegrationTest public async Task InsertRangeWithDeleteBefore_returns_error() { //act - var response = await wellOperationClient.InsertRangeAsync(idWell, 1, true, dtosWithError); + var response = await client.InsertRangeAsync(idWell, 1, true, dtosWithError); //assert Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); @@ -163,7 +161,7 @@ public class WellOperationControllerTest : BaseIntegrationTest { //act var dto = dtos.FirstOrDefault()!; - var response = await wellOperationClient.UpdateAsync(idWell, 1, dto, CancellationToken.None); + var response = await client.UpdateAsync(idWell, 1, dto, CancellationToken.None); //assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -178,9 +176,39 @@ public class WellOperationControllerTest : BaseIntegrationTest { //act var dto = dtosWithError.LastOrDefault()!; - var response = await wellOperationClient.UpdateAsync(idWell, 1, dto, CancellationToken.None); + var response = await client.UpdateAsync(idWell, 1, dto, CancellationToken.None); //assert Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); } + + /// + /// Получение плановых операций + /// + /// + [Fact] + public async Task GetPageOperationsPlanAsync_returns_success() + { + //arrange + dbContext.CleanupDbSet(); + await client.InsertRangeAsync(idWell, WellOperation.IdOperationTypePlan, false, dtos); + + var request = new WellOperationRequestBase + { + OperationType = WellOperation.IdOperationTypePlan + }; + + //act + var response = await client.GetPageOperationsPlanAsync(idWell, request, CancellationToken.None); + + //assert + Assert.NotNull(response.Content); + Assert.Single(response.Content.Items); + + var dto = dtos[0]; + var wellOperation = response.Content.Items.First(); + + var excludeProps = new[] { nameof(WellOperationDto.Id) }; + MatchHelper.Match(dto, wellOperation, excludeProps); + } } \ No newline at end of file diff --git a/AsbCloudWebApi/Controllers/WellOperationController.cs b/AsbCloudWebApi/Controllers/WellOperationController.cs index 74d4e16f..27827a62 100644 --- a/AsbCloudWebApi/Controllers/WellOperationController.cs +++ b/AsbCloudWebApi/Controllers/WellOperationController.cs @@ -233,7 +233,6 @@ namespace AsbCloudWebApi.Controllers return Forbid(); wellOperation.IdWell = idWell; - wellOperation.LastUpdateDate = DateTimeOffset.UtcNow; wellOperation.IdUser = User.GetUserId(); wellOperation.IdType = idType; From 1b01e88040b35f2f0fb0f992a4a74fb1f03b18b3 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Mon, 5 Feb 2024 09:32:14 +0500 Subject: [PATCH 2/3] remove comment --- .../Repository/WellOperationRepository.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index fe6cdeb9..c9d3c7fc 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -385,13 +385,6 @@ public class WellOperationRepository : IWellOperationRepository new[] { nameof(wellOperationDtos) }); } - //if (previousDateEnd > currentDateStart) - //{ - // yield return new ValidationResult( - // "Предыдущая операция не завершена", - // new[] { nameof(wellOperationDtos) }); - //} - previous = current; } } From e409bd440514c7769721157cd7a060f0fd99f77f Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Mon, 5 Feb 2024 10:38:57 +0500 Subject: [PATCH 3/3] Add logging record --- AsbCloudDb/EFExtensionsInitialization.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/AsbCloudDb/EFExtensionsInitialization.cs b/AsbCloudDb/EFExtensionsInitialization.cs index 7f9ba0ea..b2f41aff 100644 --- a/AsbCloudDb/EFExtensionsInitialization.cs +++ b/AsbCloudDb/EFExtensionsInitialization.cs @@ -10,6 +10,8 @@ namespace AsbCloudDb { public static void EnsureCreatedAndMigrated(this DatabaseFacade db) { + var connectionString = db.GetConnectionString(); + Trace.TraceInformation($"connectionString: {connectionString}"); db.SetCommandTimeout(TimeSpan.FromMinutes(5)); if (db.EnsureCreated()) {