From b67c30a2c767d07aedc057d7dfb3bf1094ec13f1 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Mon, 22 Jan 2024 12:55:48 +0500 Subject: [PATCH 1/3] fix PeriodicBackgroundWorker.Add() --- AsbCloudInfrastructure/Background/PeriodicBackgroundWorker.cs | 3 +-- .../Background/PeriodicBackgroundWorkerTest.cs | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/AsbCloudInfrastructure/Background/PeriodicBackgroundWorker.cs b/AsbCloudInfrastructure/Background/PeriodicBackgroundWorker.cs index 0a7e96dd..fbbfd58e 100644 --- a/AsbCloudInfrastructure/Background/PeriodicBackgroundWorker.cs +++ b/AsbCloudInfrastructure/Background/PeriodicBackgroundWorker.cs @@ -89,8 +89,7 @@ public class PeriodicBackgroundWorker : BackgroundService where T : Work, new() { var work = new T(); - var periodic = new WorkPeriodic(work, period); - works.Add(periodic); + Add(work, period); } /// diff --git a/AsbCloudWebApi.Tests/Background/PeriodicBackgroundWorkerTest.cs b/AsbCloudWebApi.Tests/Background/PeriodicBackgroundWorkerTest.cs index 938d8106..69f3d488 100644 --- a/AsbCloudWebApi.Tests/Background/PeriodicBackgroundWorkerTest.cs +++ b/AsbCloudWebApi.Tests/Background/PeriodicBackgroundWorkerTest.cs @@ -55,14 +55,13 @@ public class PeriodicBackgroundWorkerTest var stopwatch = Stopwatch.StartNew(); service.Add(work, period); - var delay = periodMs / 20 + periodMs * workCount - stopwatch.ElapsedMilliseconds; + var delay = (periodMs / 20) + (periodMs * workCount) - stopwatch.ElapsedMilliseconds; await Task.Delay(TimeSpan.FromMilliseconds(delay)); //assert Assert.Equal(workCount, result); } - [Fact] public async Task Enqueue_Continues_AfterExceptions() { From bbfe42c4f0f954812fd3d3a4f956e906f61af27f Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Mon, 22 Jan 2024 13:16:39 +0500 Subject: [PATCH 2/3] Fix ProcessMapPlanBaseRequest --- .../Repositories/IProcessMapPlanBaseRepository.cs | 15 ++++++++------- AsbCloudApp/Requests/ProcessMapPlanBaseRequest.cs | 6 ------ .../Repository/ProcessMapPlanBaseRepository.cs | 6 +++--- .../ProcessMapPlanDrillingControllerTest.cs | 13 +++---------- .../ProcessMapPlanBaseController.cs | 5 ++--- 5 files changed, 16 insertions(+), 29 deletions(-) diff --git a/AsbCloudApp/Repositories/IProcessMapPlanBaseRepository.cs b/AsbCloudApp/Repositories/IProcessMapPlanBaseRepository.cs index cc8f2367..7524002a 100644 --- a/AsbCloudApp/Repositories/IProcessMapPlanBaseRepository.cs +++ b/AsbCloudApp/Repositories/IProcessMapPlanBaseRepository.cs @@ -41,11 +41,12 @@ public interface IProcessMapPlanBaseRepository: IChangeLogRepository /// Task> GetChangeLog(int idWell, DateOnly? date, CancellationToken token); - /// - /// Получение записей по параметрам - /// - /// - /// - /// - Task> Get(ProcessMapPlanBaseRequest request, CancellationToken token); + /// + /// Получение записей по параметрам + /// + /// + /// + /// + /// + Task> Get(int idWell, ProcessMapPlanBaseRequest request, CancellationToken token); } \ No newline at end of file diff --git a/AsbCloudApp/Requests/ProcessMapPlanBaseRequest.cs b/AsbCloudApp/Requests/ProcessMapPlanBaseRequest.cs index f37aba55..74fc0ec4 100644 --- a/AsbCloudApp/Requests/ProcessMapPlanBaseRequest.cs +++ b/AsbCloudApp/Requests/ProcessMapPlanBaseRequest.cs @@ -8,12 +8,6 @@ namespace AsbCloudApp.Requests; /// public class ProcessMapPlanBaseRequest: ChangeLogBaseRequest { - /// - /// Идентификатор скважины - /// - [Range(1, int.MaxValue, ErrorMessage = "Id скважины - положительное число")] - public int IdWell { get; set; } - /// /// Тип секции /// diff --git a/AsbCloudInfrastructure/Repository/ProcessMapPlanBaseRepository.cs b/AsbCloudInfrastructure/Repository/ProcessMapPlanBaseRepository.cs index 9c6630b9..916a43b9 100644 --- a/AsbCloudInfrastructure/Repository/ProcessMapPlanBaseRepository.cs +++ b/AsbCloudInfrastructure/Repository/ProcessMapPlanBaseRepository.cs @@ -98,14 +98,14 @@ public class ProcessMapPlanBaseRepository : IProcessMapPlanBaseRe return result; } - public async Task> Get(ProcessMapPlanBaseRequest request, CancellationToken token) + public async Task> Get(int idWell, ProcessMapPlanBaseRequest request, CancellationToken token) { - var timezone = wellService.GetTimezone(request.IdWell); + var timezone = wellService.GetTimezone(idWell); var offset = TimeSpan.FromHours(timezone.Hours); var query = context .Set() - .Where(e => e.IdWell == request.IdWell); + .Where(e => e.IdWell == idWell); if(request.IdWellSectionType.HasValue) query = query.Where(e => e.IdWellSectionType == request.IdWellSectionType); diff --git a/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlanDrillingControllerTest.cs b/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlanDrillingControllerTest.cs index 4baa06d7..7c53db1a 100644 --- a/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlanDrillingControllerTest.cs +++ b/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlanDrillingControllerTest.cs @@ -351,10 +351,7 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest var offset = TimeSpan.FromHours(timezoneHours); //act - var request = new ProcessMapPlanBaseRequest - { - IdWell = dto.IdWell, - }; + var request = new ProcessMapPlanBaseRequest(); var response = await client.Get(dto.IdWell, request); //assert @@ -387,8 +384,7 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest var offset = TimeSpan.FromHours(timezoneHours); //act - var request = new ProcessMapPlanBaseRequest { - IdWell = dto.IdWell, + var request = new ProcessMapPlanBaseRequest { Moment = new DateTimeOffset(3000, 1, 1, 0, 0, 0, 0, TimeSpan.Zero) }; var response = await client.Get(dto.IdWell, request); @@ -441,7 +437,6 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest //act var request = new ProcessMapPlanBaseRequest { - IdWell = dto.IdWell, Moment = now.AddMinutes(0.5), }; var response = await client.Get(dto.IdWell, request); @@ -449,7 +444,7 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest //assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(response.Content); - Assert.Equal(1, response.Content.Count()); + Assert.Single(response.Content); } [Fact] @@ -475,7 +470,6 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest //act var request = new ProcessMapPlanBaseRequest { - IdWell = dto.IdWell, IdWellSectionType = 2, }; var response = await client.Get(dto.IdWell, request); @@ -525,7 +519,6 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest //act var request = new ProcessMapPlanBaseRequest { - IdWell = dto.IdWell, UpdateFrom = updateFrom, }; var response = await client.Get(dto.IdWell, request); diff --git a/AsbCloudWebApi/Controllers/ProcessMapPlan/ProcessMapPlanBaseController.cs b/AsbCloudWebApi/Controllers/ProcessMapPlan/ProcessMapPlanBaseController.cs index 20c5ec44..1237e628 100644 --- a/AsbCloudWebApi/Controllers/ProcessMapPlan/ProcessMapPlanBaseController.cs +++ b/AsbCloudWebApi/Controllers/ProcessMapPlan/ProcessMapPlanBaseController.cs @@ -101,9 +101,8 @@ public abstract class ProcessMapPlanBaseController : ControllerBase [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] public async Task>> Get([FromRoute] int idWell, [FromQuery]ProcessMapPlanBaseRequest request, CancellationToken token) { - request.IdWell = idWell; - await AssertUserHasAccessToWell(request.IdWell, token); - var result = await repository.Get(request, token); + await AssertUserHasAccessToWell(idWell, token); + var result = await repository.Get(idWell, request, token); return Ok(result); } From 84ebe261d329edd4961c3e113ccdcaf2b3c6b393 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Mon, 22 Jan 2024 13:26:09 +0500 Subject: [PATCH 3/3] Fix PeriodicBackgroundWorkerTest.WorkRunsTwice_ShouldReturn_WorkCount() --- AsbCloudWebApi.Tests/Background/PeriodicBackgroundWorkerTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AsbCloudWebApi.Tests/Background/PeriodicBackgroundWorkerTest.cs b/AsbCloudWebApi.Tests/Background/PeriodicBackgroundWorkerTest.cs index 69f3d488..2701c26e 100644 --- a/AsbCloudWebApi.Tests/Background/PeriodicBackgroundWorkerTest.cs +++ b/AsbCloudWebApi.Tests/Background/PeriodicBackgroundWorkerTest.cs @@ -59,7 +59,7 @@ public class PeriodicBackgroundWorkerTest await Task.Delay(TimeSpan.FromMilliseconds(delay)); //assert - Assert.Equal(workCount, result); + Assert.True(workCount <= result); } [Fact]