Автотесты при хранении первой и последней даты операции в кеше

This commit is contained in:
Olga Nemt 2024-05-13 11:06:41 +05:00
parent 4d5ed1269e
commit c66d937e7a
3 changed files with 97 additions and 2 deletions

View File

@ -135,8 +135,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;
@ -148,7 +158,13 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
await DeleteRangeAsync(existingOperationIds, token);
return await InsertRangeAsync(dtos, token);
result = await InsertRangeAsync(dtos, token);
if (result > 0)
memoryCache.Remove(cacheKeyWellOperations);
return result;
}
public override Task<int> UpdateRangeAsync(IEnumerable<WellOperationDto> dtos, CancellationToken token)

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 wellStartDate = wellResponse.Content.ElementAt(0).StartDate!.Value.ToUniversalTime();
var expectedDate = wellOperations.MinByOrDefault(o => o.DateStart)!.DateStart.ToUniversalTime();
Assert.Equal(expectedDate.ToString(), wellStartDate.ToString());
}
}