62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
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<TEntity, TDto> : BaseIntegrationTest
|
|
where TEntity : class
|
|
where TDto : class, new()
|
|
{
|
|
private ITimeSeriesClient<TDto> client;
|
|
|
|
public TimeSeriesBaseControllerTest(WebAppFactoryFixture factory) : base(factory)
|
|
{
|
|
dbContext.CleanupDbSet<TEntity>();
|
|
|
|
Task.Run(async () =>
|
|
{
|
|
client = await factory.GetAuthorizedHttpClient<ITimeSeriesClient<TDto>>(string.Empty);
|
|
}).Wait();
|
|
}
|
|
|
|
public async Task InsertRangeSuccess(TDto dto)
|
|
{
|
|
//arrange
|
|
var expected = dto.Adapt<TDto>();
|
|
|
|
//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<TEntity>();
|
|
|
|
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);
|
|
}
|
|
}
|