Правки по ревью: авторизация не внутри RefitClientFactory, а снаружи, например, в IntegrationTests
Some checks failed
Unit tests / test (push) Failing after 1m3s
Some checks failed
Unit tests / test (push) Failing after 1m3s
This commit is contained in:
parent
4cae12ddac
commit
649c51a8ab
@ -1,9 +1,4 @@
|
||||
using DD.Persistence.Client.Clients.Interfaces.Refit;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DD.Persistence.Client;
|
||||
|
||||
|
@ -1,146 +0,0 @@
|
||||
//using Microsoft.Extensions.Configuration;
|
||||
//using DD.Persistence.Client.Clients.Interfaces;
|
||||
//using DD.Persistence.Client.Clients;
|
||||
//using DD.Persistence.Client.Helpers;
|
||||
//using Refit;
|
||||
//using DD.Persistence.Factories;
|
||||
//using DD.Persistence.Client.Clients.Interfaces.Refit;
|
||||
//using Microsoft.Extensions.Logging;
|
||||
//using Microsoft.Extensions.DependencyInjection;
|
||||
//using System.Text.Json;
|
||||
|
||||
//namespace DD.Persistence.Client
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// Фабрика клиентов для доступа к Persistence - сервису
|
||||
// /// </summary>
|
||||
// public class PersistenceClientFactory
|
||||
// {
|
||||
// private static readonly JsonSerializerOptions JsonSerializerOptions = new()
|
||||
// {
|
||||
// PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
// PropertyNameCaseInsensitive = true
|
||||
// };
|
||||
// private static readonly RefitSettings RefitSettings = new(new SystemTextJsonContentSerializer(JsonSerializerOptions));
|
||||
// private readonly IServiceProvider provider;
|
||||
// private HttpClient httpClient;
|
||||
// public PersistenceClientFactory(IHttpClientFactory httpClientFactory, IServiceProvider provider, IConfiguration configuration)
|
||||
// {
|
||||
// this.provider = provider;
|
||||
|
||||
// httpClient = httpClientFactory.CreateClient();
|
||||
|
||||
// httpClient.Authorize(configuration);
|
||||
// }
|
||||
|
||||
// public PersistenceClientFactory(IHttpClientFactory httpClientFactory, IAuthTokenFactory authTokenFactory, IServiceProvider provider, IConfiguration configuration)
|
||||
// {
|
||||
// this.provider = provider;
|
||||
|
||||
// httpClient = httpClientFactory.CreateClient();
|
||||
|
||||
// var token = authTokenFactory.GetToken();
|
||||
// httpClient.Authorize(token);
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Получить клиент для работы с уставками
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// //public ISetpointClient GetSetpointClient()
|
||||
// //{
|
||||
// // var logger = provider.GetRequiredService<ILogger<SetpointClient>>();
|
||||
|
||||
// // var restClient = RestService.For<IRefitSetpointClient>(httpClient, RefitSettings);
|
||||
// // var client = new SetpointClient(restClient, logger);
|
||||
|
||||
// // return client;
|
||||
// //}
|
||||
|
||||
// /// <summary>
|
||||
// /// Получить клиент для работы с технологическими сообщениями
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// //public ITechMessagesClient GetTechMessagesClient()
|
||||
// //{
|
||||
// // var logger = provider.GetRequiredService<ILogger<TechMessagesClient>>();
|
||||
|
||||
// // var restClient = RestService.For<IRefitTechMessagesClient>(httpClient, RefitSettings);
|
||||
// // var client = new TechMessagesClient(restClient, logger);
|
||||
|
||||
// // return client;
|
||||
// //}
|
||||
|
||||
// /// <summary>
|
||||
// /// Получить клиент для работы с временными данными
|
||||
// /// </summary>
|
||||
// /// <typeparam name="TDto"></typeparam>
|
||||
// /// <returns></returns>
|
||||
// //public ITimeSeriesClient<TDto> GetTimeSeriesClient<TDto>()
|
||||
// // where TDto : class, new()
|
||||
// //{
|
||||
// // var logger = provider.GetRequiredService<ILogger<TimeSeriesClient<TDto>>>();
|
||||
|
||||
// // var restClient = RestService.For<IRefitTimeSeriesClient<TDto>>(httpClient, RefitSettings);
|
||||
// // var client = new TimeSeriesClient<TDto>(restClient, logger);
|
||||
|
||||
// // return client;
|
||||
// //}
|
||||
|
||||
// /// <summary>
|
||||
// /// Получить клиент для работы с данными с отметкой времени
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// //public ITimestampedSetClient GetTimestampedSetClient()
|
||||
// //{
|
||||
// // var logger = provider.GetRequiredService<ILogger<TimestampedSetClient>>();
|
||||
|
||||
// // var restClient = RestService.For<IRefitTimestampedSetClient>(httpClient, RefitSettings);
|
||||
// // var client = new TimestampedSetClient(restClient, logger);
|
||||
|
||||
// // return client;
|
||||
// //}
|
||||
|
||||
// /// <summary>
|
||||
// /// Получить клиент для работы с записями ChangeLog
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// //public IChangeLogClient GetChangeLogClient()
|
||||
// //{
|
||||
// // var logger = provider.GetRequiredService<ILogger<ChangeLogClient>>();
|
||||
|
||||
// // var restClient = RestService.For<IRefitChangeLogClient>(httpClient, RefitSettings);
|
||||
// // var client = new ChangeLogClient(restClient, logger);
|
||||
|
||||
// // return client;
|
||||
// //}
|
||||
|
||||
// /// <summary>
|
||||
// /// Получить клиент для работы c параметрами Wits
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// //public IWitsDataClient GetWitsDataClient()
|
||||
// //{
|
||||
// // var logger = provider.GetRequiredService<ILogger<WitsDataClient>>();
|
||||
|
||||
// // var restClient = RestService.For<IRefitWitsDataClient>(httpClient, RefitSettings);
|
||||
// // var client = new WitsDataClient(restClient, logger);
|
||||
|
||||
// // return client;
|
||||
// //}
|
||||
|
||||
// /// <summary>
|
||||
// /// Получить клиент для работы c системами
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// //public IDataSourceSystemClient GetDataSourceSystemClient()
|
||||
// //{
|
||||
// // var logger = provider.GetRequiredService<ILogger<DataSourceSystemClient>>();
|
||||
|
||||
// // var restClient = RestService.For<IRefitDataSourceSystemClient>(httpClient, RefitSettings);
|
||||
// // var client = new DataSourceSystemClient(restClient, logger);
|
||||
|
||||
// // return client;
|
||||
// //}
|
||||
// }
|
||||
//}
|
@ -17,9 +17,7 @@ public class RefitClientFactory<T> : IRefitClientFactory<T> where T : IRefitClie
|
||||
private HttpClient client;
|
||||
private RefitSettings refitSettings;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
public RefitClientFactory(IConfiguration configuration, ILogger<IRefitClientFactory<T>> logger, HttpClient client)
|
||||
{
|
||||
//this.client = factory.CreateClient();
|
||||
@ -35,7 +33,6 @@ public class RefitClientFactory<T> : IRefitClientFactory<T> where T : IRefitClie
|
||||
throw exception;
|
||||
}
|
||||
client.BaseAddress = new Uri(baseUrl);
|
||||
client.Authorize(configuration);
|
||||
|
||||
JsonSerializerOptions JsonSerializerOptions = new()
|
||||
{
|
||||
|
@ -1,4 +1,7 @@
|
||||
namespace DD.Persistence.IntegrationTests
|
||||
using DD.Persistence.Client.Helpers;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace DD.Persistence.IntegrationTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Фабрика HTTP клиентов для интеграционных тестов
|
||||
@ -6,14 +9,19 @@
|
||||
public class TestHttpClientFactory : IHttpClientFactory
|
||||
{
|
||||
private readonly WebAppFactoryFixture factory;
|
||||
private readonly IConfiguration configuration;
|
||||
|
||||
public TestHttpClientFactory(WebAppFactoryFixture factory)
|
||||
public TestHttpClientFactory(WebAppFactoryFixture factory, IConfiguration configuration)
|
||||
{
|
||||
this.factory = factory;
|
||||
this.configuration = configuration;
|
||||
}
|
||||
public HttpClient CreateClient(string name)
|
||||
{
|
||||
return factory.CreateClient();
|
||||
var client = factory.CreateClient();
|
||||
client.Authorize(configuration);
|
||||
|
||||
return client;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,9 @@ using DD.Persistence.Database.Model;
|
||||
using DD.Persistence.Database.Postgres;
|
||||
using RestSharp;
|
||||
using DD.Persistence.App;
|
||||
using DD.Persistence.Client.Helpers;
|
||||
using DD.Persistence.Factories;
|
||||
using System.Net;
|
||||
|
||||
namespace DD.Persistence.IntegrationTests;
|
||||
public class WebAppFactoryFixture : WebApplicationFactory<Program>
|
||||
@ -40,13 +43,11 @@ public class WebAppFactoryFixture : WebApplicationFactory<Program>
|
||||
services.AddLogging(builder => builder.AddConsole());
|
||||
|
||||
services.RemoveAll<IHttpClientFactory>();
|
||||
services.AddSingleton<IHttpClientFactory>(provider =>
|
||||
services.AddSingleton<IHttpClientFactory>((provider) =>
|
||||
{
|
||||
return new TestHttpClientFactory(this);
|
||||
return new TestHttpClientFactory(this, provider.GetRequiredService<IConfiguration>());
|
||||
});
|
||||
|
||||
services.AddHttpClient();
|
||||
//services.AddSingleton<PersistenceClientFactory>();
|
||||
services.AddPersistenceClients();
|
||||
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
|
Loading…
Reference in New Issue
Block a user