2024-11-14 15:17:43 +05:00
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-11-18 14:22:09 +05:00
|
|
|
|
using Microsoft.Extensions.Configuration.UserSecrets;
|
2024-11-14 15:17:43 +05:00
|
|
|
|
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;
|
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()
|
|
|
|
|
{
|
|
|
|
|
private ITimeSeriesClient<TDto> client;
|
|
|
|
|
|
|
|
|
|
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 11:41:53 +05:00
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
client = await factory.GetAuthorizedHttpClient<ITimeSeriesClient<TDto>>(string.Empty);
|
|
|
|
|
}).Wait();
|
2024-11-14 15:17:43 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
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-18 14:22:09 +05:00
|
|
|
|
var response = await client.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
|
|
|
|
}
|
|
|
|
|
}
|