Авторизация внутри интеграционного теста (начало)
This commit is contained in:
parent
e5ffd42fb3
commit
3a1ea55be2
@ -22,7 +22,8 @@ public abstract class TimeSeriesBaseControllerTest<TEntity, TDto> : BaseIntegrat
|
||||
public TimeSeriesBaseControllerTest(WebAppFactoryFixture factory) : base(factory)
|
||||
{
|
||||
dbContext.CleanupDbSet<TEntity>();
|
||||
client = factory.GetHttpClient<ITimeSeriesClient<TDto>>(string.Empty);
|
||||
|
||||
client = factory.GetAuthorizedHttpClient<ITimeSeriesClient<TDto>>(string.Empty);
|
||||
}
|
||||
|
||||
public async Task InsertRangeSuccess(TDto dto)
|
||||
|
@ -8,6 +8,7 @@ using Persistence.Database.Postgres;
|
||||
using Persistence.API;
|
||||
using Refit;
|
||||
using System.Text.Json;
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
namespace Persistence.IntegrationTests;
|
||||
public class WebAppFactoryFixture : WebApplicationFactory<Startup>
|
||||
@ -79,23 +80,23 @@ public class WebAppFactoryFixture : WebApplicationFactory<Startup>
|
||||
return RestService.For<T>(httpClient, RefitSettings);
|
||||
}
|
||||
|
||||
//public T GetAuthorizedHttpClient<T>(string uriSuffix)
|
||||
//{
|
||||
// var httpClient = GetAuthorizedHttpClient();
|
||||
// if (string.IsNullOrEmpty(uriSuffix))
|
||||
// return RestService.For<T>(httpClient, RefitSettings);
|
||||
public T GetAuthorizedHttpClient<T>(string uriSuffix)
|
||||
{
|
||||
var httpClient = GetAuthorizedHttpClient();
|
||||
if (string.IsNullOrEmpty(uriSuffix))
|
||||
return RestService.For<T>(httpClient, RefitSettings);
|
||||
|
||||
// if (httpClient.BaseAddress is not null)
|
||||
// httpClient.BaseAddress = new Uri(httpClient.BaseAddress, uriSuffix);
|
||||
if (httpClient.BaseAddress is not null)
|
||||
httpClient.BaseAddress = new Uri(httpClient.BaseAddress, uriSuffix);
|
||||
|
||||
// return RestService.For<T>(httpClient, RefitSettings);
|
||||
//}
|
||||
|
||||
//private HttpClient GetAuthorizedHttpClient()
|
||||
//{
|
||||
// var httpClient = CreateClient();
|
||||
// var jwtToken = ApiTokenHelper.GetAdminUserToken();
|
||||
// httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwtToken);
|
||||
// return httpClient;
|
||||
//}
|
||||
return RestService.For<T>(httpClient, RefitSettings);
|
||||
}
|
||||
|
||||
private HttpClient GetAuthorizedHttpClient()
|
||||
{
|
||||
var httpClient = CreateClient();
|
||||
////var jwtToken = ApiTokenHelper.GetAdminUserToken();
|
||||
//httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwtToken);
|
||||
return httpClient;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user