diff --git a/Persistence.IntegrationTests/Controllers/TimeSeriesBaseControllerTest.cs b/Persistence.IntegrationTests/Controllers/TimeSeriesBaseControllerTest.cs index 2119bf7..c63f094 100644 --- a/Persistence.IntegrationTests/Controllers/TimeSeriesBaseControllerTest.cs +++ b/Persistence.IntegrationTests/Controllers/TimeSeriesBaseControllerTest.cs @@ -22,7 +22,8 @@ public abstract class TimeSeriesBaseControllerTest : BaseIntegrat public TimeSeriesBaseControllerTest(WebAppFactoryFixture factory) : base(factory) { dbContext.CleanupDbSet(); - client = factory.GetHttpClient>(string.Empty); + + client = factory.GetAuthorizedHttpClient>(string.Empty); } public async Task InsertRangeSuccess(TDto dto) diff --git a/Persistence.IntegrationTests/WebAppFactoryFixture.cs b/Persistence.IntegrationTests/WebAppFactoryFixture.cs index 802c384..ac73013 100644 --- a/Persistence.IntegrationTests/WebAppFactoryFixture.cs +++ b/Persistence.IntegrationTests/WebAppFactoryFixture.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; @@ -9,6 +9,7 @@ using Persistence.API; using Refit; using System.Text.Json; using Persistence.Database.Postgres; +using System.Net.Http.Headers; namespace Persistence.IntegrationTests; public class WebAppFactoryFixture : WebApplicationFactory @@ -80,23 +81,23 @@ public class WebAppFactoryFixture : WebApplicationFactory return RestService.For(httpClient, RefitSettings); } - //public T GetAuthorizedHttpClient(string uriSuffix) - //{ - // var httpClient = GetAuthorizedHttpClient(); - // if (string.IsNullOrEmpty(uriSuffix)) - // return RestService.For(httpClient, RefitSettings); + public T GetAuthorizedHttpClient(string uriSuffix) + { + var httpClient = GetAuthorizedHttpClient(); + if (string.IsNullOrEmpty(uriSuffix)) + return RestService.For(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(httpClient, RefitSettings); - //} + return RestService.For(httpClient, RefitSettings); + } - //private HttpClient GetAuthorizedHttpClient() - //{ - // var httpClient = CreateClient(); - // var jwtToken = ApiTokenHelper.GetAdminUserToken(); - // httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwtToken); - // return httpClient; - //} + private HttpClient GetAuthorizedHttpClient() + { + var httpClient = CreateClient(); + ////var jwtToken = ApiTokenHelper.GetAdminUserToken(); + //httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwtToken); + return httpClient; + } }