persistence/Persistence.IntegrationTests/Controllers/TimeSeriesBaseControllerTest.cs

57 lines
1.6 KiB
C#
Raw Normal View History

using System.Net;
2024-11-21 14:50:36 +05:00
using Mapster;
using Microsoft.Extensions.DependencyInjection;
using Persistence.Client;
using Persistence.Client.Clients;
using Xunit;
namespace Persistence.IntegrationTests.Controllers;
public abstract class TimeSeriesBaseControllerTest<TEntity, TDto> : BaseIntegrationTest
where TEntity : class
where TDto : class, new()
{
2024-11-21 14:50:36 +05:00
private ITimeSeriesClient<TDto> timeSeriesClient;
public TimeSeriesBaseControllerTest(WebAppFactoryFixture factory) : base(factory)
{
dbContext.CleanupDbSet<TEntity>();
2024-11-21 14:50:36 +05:00
var scope = factory.Services.CreateScope();
var httpClient = scope.ServiceProvider
.GetRequiredService<IHttpClientFactory>()
.CreateClient();
timeSeriesClient = PersistenceClientFactory.GetClient<ITimeSeriesClient<TDto>>(httpClient);
}
public async Task InsertRangeSuccess(TDto dto)
{
//arrange
var expected = dto.Adapt<TDto>();
//act
2024-11-21 14:50:36 +05:00
var response = await timeSeriesClient.InsertRangeAsync(new TDto[] { expected });
//assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(1, response.Content);
}
public async Task GetSuccess(DateTimeOffset beginDate, DateTimeOffset endDate, TEntity entity)
{
//arrange
var dbset = dbContext.Set<TEntity>();
dbset.Add(entity);
dbContext.SaveChanges();
2024-11-21 14:50:36 +05:00
var response = await timeSeriesClient.GetAsync(beginDate, endDate);
//assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(response.Content);
Assert.Single(response.Content);
}
}