From 3a1ea55be27041b8cd7ada723829c14fe760a843 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Wed, 20 Nov 2024 16:08:16 +0500 Subject: [PATCH] =?UTF-8?q?=D0=90=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B2=D0=BD=D1=83=D1=82=D1=80=D0=B8?= =?UTF-8?q?=20=D0=B8=D0=BD=D1=82=D0=B5=D0=B3=D1=80=D0=B0=D1=86=D0=B8=D0=BE?= =?UTF-8?q?=D0=BD=D0=BD=D0=BE=D0=B3=D0=BE=20=D1=82=D0=B5=D1=81=D1=82=D0=B0?= =?UTF-8?q?=20(=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TimeSeriesBaseControllerTest.cs | 3 +- .../WebAppFactoryFixture.cs | 33 ++++++++++--------- 2 files changed, 19 insertions(+), 17 deletions(-) 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 d1cedf8..62489e3 100644 --- a/Persistence.IntegrationTests/WebAppFactoryFixture.cs +++ b/Persistence.IntegrationTests/WebAppFactoryFixture.cs @@ -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 @@ -79,23 +80,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; + } }