using System.Net; using Mapster; using Microsoft.Extensions.DependencyInjection; using Persistence.Client; using Persistence.Client.Clients; using Xunit; namespace Persistence.IntegrationTests.Controllers; public abstract class TimeSeriesBaseControllerTest : BaseIntegrationTest where TEntity : class where TDto : class, new() { private ITimeSeriesClient timeSeriesClient; public TimeSeriesBaseControllerTest(WebAppFactoryFixture factory) : base(factory) { dbContext.CleanupDbSet(); var scope = factory.Services.CreateScope(); var httpClient = scope.ServiceProvider .GetRequiredService() .CreateClient(); timeSeriesClient = PersistenceClientFactory.GetClient>(httpClient); } public async Task InsertRangeSuccess(TDto dto) { //arrange var expected = dto.Adapt(); //act 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(); dbset.Add(entity); dbContext.SaveChanges(); var response = await timeSeriesClient.GetAsync(beginDate, endDate); //assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(response.Content); Assert.Single(response.Content); } }