2024-11-14 15:17:43 +05:00
|
|
|
using System.Net;
|
2024-11-21 14:50:36 +05:00
|
|
|
using Mapster;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Persistence.Client;
|
|
|
|
using Persistence.Client.Clients;
|
2024-11-14 15:17:43 +05:00
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace Persistence.IntegrationTests.Controllers;
|
2024-11-18 14:22:09 +05:00
|
|
|
public abstract class TimeSeriesBaseControllerTest<TEntity, TDto> : BaseIntegrationTest
|
|
|
|
where TEntity : class
|
2024-11-14 15:17:43 +05:00
|
|
|
where TDto : class, new()
|
|
|
|
{
|
2024-11-21 14:50:36 +05:00
|
|
|
private ITimeSeriesClient<TDto> timeSeriesClient;
|
2024-11-14 15:17:43 +05:00
|
|
|
|
|
|
|
public TimeSeriesBaseControllerTest(WebAppFactoryFixture factory) : base(factory)
|
|
|
|
{
|
2024-11-18 14:22:09 +05:00
|
|
|
dbContext.CleanupDbSet<TEntity>();
|
2024-11-20 16:08:16 +05:00
|
|
|
|
2024-11-21 14:50:36 +05:00
|
|
|
var scope = factory.Services.CreateScope();
|
2024-11-25 10:09:38 +05:00
|
|
|
var persistenceClientFactory = scope.ServiceProvider
|
|
|
|
.GetRequiredService<PersistenceClientFactory>();
|
2024-11-21 14:50:36 +05:00
|
|
|
|
2024-11-25 10:09:38 +05:00
|
|
|
timeSeriesClient = persistenceClientFactory.GetClient<ITimeSeriesClient<TDto>>();
|
2024-11-14 15:17:43 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
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 });
|
2024-11-14 15:17:43 +05:00
|
|
|
|
|
|
|
//assert
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
Assert.Equal(1, response.Content);
|
2024-11-18 14:22:09 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
public async Task GetSuccess(DateTimeOffset beginDate, DateTimeOffset endDate, TEntity entity)
|
|
|
|
{
|
|
|
|
//arrange
|
|
|
|
var dbset = dbContext.Set<TEntity>();
|
2024-11-14 15:17:43 +05:00
|
|
|
|
2024-11-18 14:22:09 +05:00
|
|
|
dbset.Add(entity);
|
2024-11-14 15:17:43 +05:00
|
|
|
|
2024-11-18 14:22:09 +05:00
|
|
|
dbContext.SaveChanges();
|
2024-11-14 15:17:43 +05:00
|
|
|
|
2024-11-21 14:50:36 +05:00
|
|
|
var response = await timeSeriesClient.GetAsync(beginDate, endDate);
|
2024-11-14 15:17:43 +05:00
|
|
|
|
2024-11-18 14:22:09 +05:00
|
|
|
//assert
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
Assert.NotNull(response.Content);
|
|
|
|
Assert.Single(response.Content);
|
2024-11-14 15:17:43 +05:00
|
|
|
}
|
|
|
|
}
|