using Mapster; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration.UserSecrets; using Persistence.IntegrationTests.Clients; using Persistence.Models; using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; using Xunit; namespace Persistence.IntegrationTests.Controllers; public abstract class TimeSeriesBaseControllerTest : BaseIntegrationTest where TEntity : class where TDto : class, new() { private ITimeSeriesClient client; public TimeSeriesBaseControllerTest(WebAppFactoryFixture factory) : base(factory) { dbContext.CleanupDbSet(); Task.Run(async () => { client = await factory.GetAuthorizedHttpClient>(string.Empty); }).Wait(); } public async Task InsertRangeSuccess(TDto dto) { //arrange var expected = dto.Adapt(); //act var response = await client.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 client.GetAsync(beginDate, endDate); //assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(response.Content); Assert.Single(response.Content); } }