Merge pull request 'Интеграционный тест на проверку дат первой и последней операции, хранящейся в кеше' (#275) from fix/first-and-last-date-operation-into-cashe-test into dev

Reviewed-on: http://test.digitaldrilling.ru:8080/DDrilling/AsbCloudServer/pulls/275
This commit is contained in:
Никита Фролов 2024-05-13 12:25:22 +05:00
commit c6a9797255
3 changed files with 91 additions and 2 deletions

View File

@ -136,8 +136,18 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
{
EnsureValidWellOperations(dtos);
var result = 0;
if (!deleteBeforeInsert)
return await InsertRangeAsync(dtos, token);
{
result = await InsertRangeAsync(dtos, token);
if (result > 0)
memoryCache.Remove(cacheKeyWellOperations);
return result;
}
var idType = dtos.First().IdType;
var idWell = dtos.First().IdWell;
@ -149,7 +159,7 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
await DeleteRangeAsync(existingOperationIds, token);
var result = await InsertRangeAsync(dtos, token);
result = await InsertRangeAsync(dtos, token);
if (result > 0)
memoryCache.Remove(cacheKeyWellOperations);

View File

@ -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<IApiResponse<IEnumerable<WellDto>>> GetWellsAsync();
}

View File

@ -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<IWellClient>(string.Empty);
wellOperationClient = factory.GetAuthorizedHttpClient<IWellOperationClient>(string.Empty);
}
[Fact]
public async Task CheckDateStartForWell_returns_success()
{
//act
var wellOperationDto1 = wellOperationDto.Adapt<WellOperationDto>();
wellOperationDto1.DateStart = DateTimeOffset.UtcNow;
wellOperationDto1.Id = 2;
var wellOperations = new List<WellOperationDto>() { 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 actualFirstStartDate = wellResponse.Content.ElementAt(0).StartDate!.Value.ToUniversalTime();
var expectedFirstStartDate = wellOperations.MinByOrDefault(o => o.DateStart)!.DateStart.ToUniversalTime();
Assert.Equal(expectedFirstStartDate.ToString(), actualFirstStartDate.ToString());
}
}