DD.WellWorkover.Cloud/AsbCloudWebApi.IntegrationTests/BaseIntegrationTest.cs
Степанов Дмитрий 88ce24b8bb Интеграционные тесты
1. Создание инфраструктуры для интегарционных тестов
2. Покрытие контроллера месторождений тестами
2023-12-29 11:46:17 +05:00

40 lines
1.2 KiB
C#

using System.Net.Http.Headers;
using System.Text.Json;
using AsbCloudDb.Model;
using AsbCloudWebApi.IntegrationTests.Clients;
using Microsoft.Extensions.DependencyInjection;
using Refit;
using Xunit;
namespace AsbCloudWebApi.IntegrationTests;
public abstract class BaseIntegrationTest : IClassFixture<WebAppFactoryFixture>
{
private readonly IServiceScope scope;
private readonly HttpClient httpClient;
protected readonly IAsbCloudDbContext dbContext;
protected IAdminDepositClient adminDepositClient;
protected BaseIntegrationTest(WebAppFactoryFixture factory)
{
scope = factory.Services.CreateScope();
httpClient = factory.CreateClient();
dbContext = scope.ServiceProvider.GetRequiredService<IAsbCloudDbContext>();
var jwtToken = ApiTokenHelper.GetAdminUserToken();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwtToken);
var jsonSerializerOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
PropertyNameCaseInsensitive = true
};
var refitSettings = new RefitSettings(new SystemTextJsonContentSerializer(jsonSerializerOptions));
adminDepositClient = RestService.For<IAdminDepositClient>(httpClient, refitSettings);
}
}