From c66d937e7aa9eb9798ea80d6d0a7601804f735fb Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Mon, 13 May 2024 11:06:41 +0500 Subject: [PATCH 1/2] =?UTF-8?q?=D0=90=D0=B2=D1=82=D0=BE=D1=82=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D1=8B=20=D0=BF=D1=80=D0=B8=20=D1=85=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B8=20=D0=BF=D0=B5=D1=80=D0=B2=D0=BE=D0=B9?= =?UTF-8?q?=20=D0=B8=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D0=BD=D0=B5?= =?UTF-8?q?=D0=B9=20=D0=B4=D0=B0=D1=82=D1=8B=20=D0=BE=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D0=B8=20=D0=B2=20=D0=BA=D0=B5=D1=88=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository/WellOperationRepository.cs | 20 +++++- .../Clients/IWellClient.cs | 12 ++++ .../Controllers/WellControllerTest.cs | 67 +++++++++++++++++++ 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 AsbCloudWebApi.IntegrationTests/Clients/IWellClient.cs create mode 100644 AsbCloudWebApi.IntegrationTests/Controllers/WellControllerTest.cs diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index 9bcc718b..920702b1 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -135,8 +135,18 @@ public class WellOperationRepository : CrudRepositoryBase 0) + memoryCache.Remove(cacheKeyWellOperations); + + return result; + } + var idType = dtos.First().IdType; var idWell = dtos.First().IdWell; @@ -148,7 +158,13 @@ public class WellOperationRepository : CrudRepositoryBase 0) + memoryCache.Remove(cacheKeyWellOperations); + + return result; + } public override Task UpdateRangeAsync(IEnumerable dtos, CancellationToken token) diff --git a/AsbCloudWebApi.IntegrationTests/Clients/IWellClient.cs b/AsbCloudWebApi.IntegrationTests/Clients/IWellClient.cs new file mode 100644 index 00000000..1e6961a5 --- /dev/null +++ b/AsbCloudWebApi.IntegrationTests/Clients/IWellClient.cs @@ -0,0 +1,12 @@ +using AsbCloudApp.Data; +using Refit; + +namespace AsbCloudWebApi.IntegrationTests.Clients; + +public interface IWellClient +{ + private const string BaseRoute = "/api/well"; + + [Get(BaseRoute)] + Task>> GetWellsAsync(); +} diff --git a/AsbCloudWebApi.IntegrationTests/Controllers/WellControllerTest.cs b/AsbCloudWebApi.IntegrationTests/Controllers/WellControllerTest.cs new file mode 100644 index 00000000..329240fe --- /dev/null +++ b/AsbCloudWebApi.IntegrationTests/Controllers/WellControllerTest.cs @@ -0,0 +1,67 @@ +using AsbCloudApp.Data; +using AsbCloudApp.Data.WellOperation; +using AsbCloudDb.Model; +using AsbCloudInfrastructure; +using AsbCloudWebApi.IntegrationTests.Clients; +using Mapster; +using Microsoft.EntityFrameworkCore; +using System.Net; +using Xunit; + +namespace AsbCloudWebApi.IntegrationTests.Controllers; + +public class WellControllerTest : BaseIntegrationTest +{ + + private static readonly WellOperationDto wellOperationDto = new() + { + DateStart = DateTimeOffset.UtcNow, + Day = 1, + DepthEnd = 1000, + DepthStart = 500, + DurationHours = 5, + Id = 1, + IdCategory = 5095, + IdPlan = null, + IdType = 1, + IdUser = 1, + IdWell = 1, + IdWellSectionType = 1, + NptHours = 5 + }; + + private readonly IWellClient wellClient; + private readonly IWellOperationClient wellOperationClient; + + public WellControllerTest(WebAppFactoryFixture factory) + : base(factory) + { + wellClient = factory.GetAuthorizedHttpClient(string.Empty); + wellOperationClient = factory.GetAuthorizedHttpClient(string.Empty); + } + + [Fact] + public async Task CheckDateStartForWell_returns_success() + { + //act + var wellOperationDto1 = wellOperationDto.Adapt(); + wellOperationDto1.DateStart = DateTimeOffset.UtcNow; + wellOperationDto1.Id = 2; + + var wellOperations = new List() { wellOperationDto, wellOperationDto1 }; + var insertedRedult = await wellOperationClient.InsertRangeAsync(1, false, wellOperations); + + var wellResponse = await wellClient.GetWellsAsync(); + + //assert + Assert.Equal(HttpStatusCode.OK, wellResponse.StatusCode); + Assert.NotNull(wellResponse.Content); + + var expectedCount = await dbContext.Wells.CountAsync(); + Assert.Equal(expectedCount, wellResponse.Content.Count()); + + var wellStartDate = wellResponse.Content.ElementAt(0).StartDate!.Value.ToUniversalTime(); + var expectedDate = wellOperations.MinByOrDefault(o => o.DateStart)!.DateStart.ToUniversalTime(); + Assert.Equal(expectedDate.ToString(), wellStartDate.ToString()); + } +} \ No newline at end of file From 0f8bc45e80d41af41ce42e1c59c20a943a077449 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Mon, 13 May 2024 11:18:24 +0500 Subject: [PATCH 2/2] =?UTF-8?q?=D0=BF=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/WellControllerTest.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AsbCloudWebApi.IntegrationTests/Controllers/WellControllerTest.cs b/AsbCloudWebApi.IntegrationTests/Controllers/WellControllerTest.cs index 329240fe..fe3fea64 100644 --- a/AsbCloudWebApi.IntegrationTests/Controllers/WellControllerTest.cs +++ b/AsbCloudWebApi.IntegrationTests/Controllers/WellControllerTest.cs @@ -60,8 +60,8 @@ public class WellControllerTest : BaseIntegrationTest var expectedCount = await dbContext.Wells.CountAsync(); Assert.Equal(expectedCount, wellResponse.Content.Count()); - var wellStartDate = wellResponse.Content.ElementAt(0).StartDate!.Value.ToUniversalTime(); - var expectedDate = wellOperations.MinByOrDefault(o => o.DateStart)!.DateStart.ToUniversalTime(); - Assert.Equal(expectedDate.ToString(), wellStartDate.ToString()); + var actualFirstStartDate = wellResponse.Content.ElementAt(0).StartDate!.Value.ToUniversalTime(); + var expectedFirstStartDate = wellOperations.MinByOrDefault(o => o.DateStart)!.DateStart.ToUniversalTime(); + Assert.Equal(expectedFirstStartDate.ToString(), actualFirstStartDate.ToString()); } } \ No newline at end of file