forked from ddrilling/AsbCloudServer
40 lines
1.2 KiB
C#
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);
|
||
|
}
|
||
|
}
|