diff --git a/commercetools.Sdk/Examples/commercetools.Api.CheckoutApp/Extensions/ClientInjectionSetup.cs b/commercetools.Sdk/Examples/commercetools.Api.CheckoutApp/Extensions/ClientInjectionSetup.cs index ed8ec765059..11d11bf05fc 100644 --- a/commercetools.Sdk/Examples/commercetools.Api.CheckoutApp/Extensions/ClientInjectionSetup.cs +++ b/commercetools.Sdk/Examples/commercetools.Api.CheckoutApp/Extensions/ClientInjectionSetup.cs @@ -36,8 +36,8 @@ public static IHttpClientBuilder UseCommercetoolsScopedClient(this IServiceColle ClientName = clientName, ClientConfiguration = clientConfiguration, TokenProvider = tokenProvider, - SerializerService =serviceProvider.GetService(), - HttpClient = serviceProvider.GetService().CreateClient(clientName) + SerializerService = serviceProvider.GetService(), + HttpClient = serviceProvider.GetService().CreateClient(clientName) }.Build(); return client; }); diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/LoggingTest.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/LoggingTest.cs index 8e45a0d76b3..201afed158d 100644 --- a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/LoggingTest.cs +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/LoggingTest.cs @@ -55,7 +55,7 @@ public async void DefaultLogger() Assert.StartsWith("GET https://api.europe-west1.gcp.commercetools.com/" + clientConfiguration.ProjectKey, messages.TrimEnd()); } - + [Fact] public async void CustomLogger() { @@ -94,7 +94,7 @@ public async void CustomLogger() var messages = logger.GetLogMessages(); Assert.Equal("GET https://api.europe-west1.gcp.commercetools.com/" + clientConfiguration.ProjectKey, messages.TrimEnd()); } - + public class CustomLoggerHandler : DelegatingHandler { private readonly ILogger logger; diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Me/MeIntegrationTests.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Me/MeIntegrationTests.cs index 48566f26b10..cd3d2ed07ac 100644 --- a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Me/MeIntegrationTests.cs +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Me/MeIntegrationTests.cs @@ -113,7 +113,8 @@ private void CreateMeClient() CustomerServices.CustomerPassword)); //Create MeClient - _meClient = new ClientBuilder { + _meClient = new ClientBuilder + { ClientName = "MeClient", ClientConfiguration = meClientConfig, TokenProvider = passwordTokenProvider, diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/MiddlewareTest.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/MiddlewareTest.cs index 7750b7ba25e..d4449af5a97 100644 --- a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/MiddlewareTest.cs +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/MiddlewareTest.cs @@ -22,7 +22,7 @@ public async void not_found_middleware_stream_client() Build(); var s = new ServiceCollection(); - s.UseCommercetoolsApi(configuration, "Client", options: new ClientOptions() { ReadResponseAsStream = true},middlewares: new List() + s.UseCommercetoolsApi(configuration, "Client", options: new ClientOptions() { ReadResponseAsStream = true }, middlewares: new List() { new NotFoundMiddleware() }); @@ -36,7 +36,7 @@ public async void not_found_middleware_stream_client() Assert.Null(category); } - + [Fact] public async void not_found_middleware_string_client() { @@ -48,7 +48,7 @@ public async void not_found_middleware_string_client() Build(); var s = new ServiceCollection(); - s.UseCommercetoolsApi(configuration, "Client", options: new ClientOptions() { ReadResponseAsStream = false},middlewares: new List() + s.UseCommercetoolsApi(configuration, "Client", options: new ClientOptions() { ReadResponseAsStream = false }, middlewares: new List() { new NotFoundMiddleware() }); diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/MultipleClientsTest.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/MultipleClientsTest.cs index 37caa426c07..c9a0d3a2b41 100644 --- a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/MultipleClientsTest.cs +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/MultipleClientsTest.cs @@ -1,8 +1,6 @@ -using System.Collections.Generic; using System.Linq; using commercetools.Api.IntegrationTests; using commercetools.Base.Client; -using commercetools.Base.Client.Middlewares; using commercetools.Sdk.Api; using commercetools.Sdk.Api.Extensions; using commercetools.Sdk.ImportApi.Extensions; diff --git a/commercetools.Sdk/Tests/commercetools.Sdk.Api.Tests/ClientsFactoryTests.cs b/commercetools.Sdk/Tests/commercetools.Sdk.Api.Tests/ClientsFactoryTests.cs index f69cd29ce24..74ffdfb06fe 100644 --- a/commercetools.Sdk/Tests/commercetools.Sdk.Api.Tests/ClientsFactoryTests.cs +++ b/commercetools.Sdk/Tests/commercetools.Sdk.Api.Tests/ClientsFactoryTests.cs @@ -86,12 +86,14 @@ public void TestClientConfigValidationBuilder() var tokenProvider = TokenProviderFactory .CreateClientCredentialsTokenProvider(clientConfig, null); - new ClientBuilder { + new ClientBuilder + { ClientName = "test", ClientConfiguration = clientConfig, HttpClient = null, SerializerService = serializerService, - TokenProvider = tokenProvider}.Build(); + TokenProvider = tokenProvider + }.Build(); } catch (Exception e) { @@ -102,7 +104,7 @@ public void TestClientConfigValidationBuilder() Assert.NotNull(validationEx); Assert.IsType(validationEx); } - + [Fact] public void TestClientConfigValidation() { diff --git a/commercetools.Sdk/commercetools.Base.Client/ApiMethod.cs b/commercetools.Sdk/commercetools.Base.Client/ApiMethod.cs index 8249767798b..459b4825ab3 100644 --- a/commercetools.Sdk/commercetools.Base.Client/ApiMethod.cs +++ b/commercetools.Sdk/commercetools.Base.Client/ApiMethod.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Net; using System.Net.Http; namespace commercetools.Base.Client diff --git a/commercetools.Sdk/commercetools.Base.Client/ClientBuilder.cs b/commercetools.Sdk/commercetools.Base.Client/ClientBuilder.cs index b358faa77b4..7022b940a26 100644 --- a/commercetools.Sdk/commercetools.Base.Client/ClientBuilder.cs +++ b/commercetools.Sdk/commercetools.Base.Client/ClientBuilder.cs @@ -16,7 +16,7 @@ public class ClientBuilder public ITokenProvider TokenProvider { get; set; } public bool ReadResponseAsStream { get; set; } = true; public ICorrelationIdProvider CorrelationIdProvider { get; set; } - + [Obsolete("Set default HttpVersion in HttpClient instead")] public Version HttpVersion { get; set; } public IEnumerable Middlewares { get; set; } = new List(); diff --git a/commercetools.Sdk/commercetools.Base.Client/ClientFactory.cs b/commercetools.Sdk/commercetools.Base.Client/ClientFactory.cs index 4f634a9c206..79934cb586b 100644 --- a/commercetools.Sdk/commercetools.Base.Client/ClientFactory.cs +++ b/commercetools.Sdk/commercetools.Base.Client/ClientFactory.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; using System.Net.Http; using commercetools.Base.Client.Middlewares; using commercetools.Base.Client.Tokens; @@ -23,16 +22,16 @@ public static IClient Create( Version httpVersion = null) { return new ClientBuilder() - { - ClientName = clientName, - ClientConfiguration = configuration, - HttpClient = factory.CreateClient(clientName), - SerializerService = serializerService, - TokenProvider = tokenProvider, - ReadResponseAsStream = readResponseAsStream, - CorrelationIdProvider = correlationIdProvider, - HttpVersion = httpVersion - }.Build(); + { + ClientName = clientName, + ClientConfiguration = configuration, + HttpClient = factory.CreateClient(clientName), + SerializerService = serializerService, + TokenProvider = tokenProvider, + ReadResponseAsStream = readResponseAsStream, + CorrelationIdProvider = correlationIdProvider, + HttpVersion = httpVersion + }.Build(); } [Obsolete("Use ClientBuilder.CreateMiddlewareStack instead")] diff --git a/commercetools.Sdk/commercetools.Base.Client/CtpClient.cs b/commercetools.Sdk/commercetools.Base.Client/CtpClient.cs index efced614b22..7676c2dbf55 100644 --- a/commercetools.Sdk/commercetools.Base.Client/CtpClient.cs +++ b/commercetools.Sdk/commercetools.Base.Client/CtpClient.cs @@ -48,7 +48,7 @@ public async Task> SendAsync(HttpRequestMessage requestMessag var result = await SendAsJsonAsync(requestMessage, cancellationToken); if (string.IsNullOrEmpty(result.Body)) { - return new ApiResponse(result.StatusCode, result.ReasonPhrase, result.HttpHeaders, default); + return new ApiResponse(result.StatusCode, result.ReasonPhrase, result.HttpHeaders, default); } var body = this.SerializerService.Deserialize(result.Body); return new ApiResponse(result.StatusCode, result.ReasonPhrase, result.HttpHeaders, body); diff --git a/commercetools.Sdk/commercetools.Base.Client/DefaultHttpLogger.cs b/commercetools.Sdk/commercetools.Base.Client/DefaultHttpLogger.cs index b0aa49e7b51..54cb9fa5c3c 100644 --- a/commercetools.Sdk/commercetools.Base.Client/DefaultHttpLogger.cs +++ b/commercetools.Sdk/commercetools.Base.Client/DefaultHttpLogger.cs @@ -1,4 +1,3 @@ -using System; using System.Linq; using System.Net.Http; using System.Net.Http.Headers; @@ -19,7 +18,7 @@ public async Task LogRequestBody(ILogger logger, LogLevel logLevel, HttpRequestM request.RequestUri.AbsoluteUri, RedactAuthorizationHeader(request.Headers), SecuredBody(body)); } } - + public async Task LogResponseBody(ILogger logger, LogLevel logLevel, HttpRequestMessage request, HttpResponseMessage response, long elapsed) { if (logger.IsEnabled(logLevel)) @@ -29,7 +28,7 @@ public async Task LogResponseBody(ILogger logger, LogLevel logLevel, HttpRequest request.RequestUri.AbsoluteUri, (int)response.StatusCode, elapsed, RedactAuthorizationHeader(request.Headers), SecuredBody(body)); } } - + public void Log(ILogger logger, LogLevel logLevel, HttpRequestMessage request) { if (logger.IsEnabled(logLevel)) @@ -38,7 +37,7 @@ public void Log(ILogger logger, LogLevel logLevel, HttpRequestMessage request) request.RequestUri.AbsoluteUri, RedactAuthorizationHeader(request.Headers)); } } - + public void Log(ILogger logger, LogLevel level, HttpRequestMessage request, HttpResponseMessage response, long elapsed) { if (logger.IsEnabled(level)) @@ -57,12 +56,12 @@ public void Log(ILogger logger, LogLevel logLevel, HttpRequestMessage request, A } } - + private static string RedactAuthorizationHeader(HttpRequestHeaders headers) { var headString = from header in headers - where header.Key.ToLower() != "authorization" - select header.Key + ": " + string.Join(", ", header.Value); + where header.Key.ToLower() != "authorization" + select header.Key + ": " + string.Join(", ", header.Value); return "[" + string.Join(", ", headString) + "]"; } @@ -79,12 +78,12 @@ private static string GetCorrelationId(ApiHttpHeaders headers) { return headers.GetFirst("X-Correlation-Id") ?? "-"; } - + private static string GetCorrelationId(HttpResponseHeaders headers) { return GetHeader(headers, "X-Correlation-ID"); } - + private static string GetHeader(HttpResponseHeaders headers, string headerName) { var headerValue = "-"; @@ -96,12 +95,12 @@ private static string GetHeader(HttpResponseHeaders headers, string headerName) return headerValue; } - + private static string GetServerTiming(HttpResponseHeaders headers) { return GetHeader(headers, "Server-Timing"); } - + private static string GetServerTiming(ApiHttpHeaders headers) { return headers.GetFirst("Server-Timing") ?? "-"; diff --git a/commercetools.Sdk/commercetools.Base.Client/DependencyInjectionSetup.cs b/commercetools.Sdk/commercetools.Base.Client/DependencyInjectionSetup.cs index 151eb445aa2..b5a9e1a8d37 100644 --- a/commercetools.Sdk/commercetools.Base.Client/DependencyInjectionSetup.cs +++ b/commercetools.Sdk/commercetools.Base.Client/DependencyInjectionSetup.cs @@ -57,8 +57,9 @@ private static IDictionary UseMultipleClients(this I builders.TryAdd(clientName, services.SetupClient(clientName, errorResponseTypeMapper, serializerFactory, options)); services.AddSingleton(serviceProvider => { - - var client = new ClientBuilder { + + var client = new ClientBuilder + { ClientName = clientName, ClientConfiguration = clientConfiguration, HttpClient = serviceProvider.GetService().CreateClient(clientName), @@ -88,7 +89,8 @@ private static IDictionary UseSingleClient(this ISer services.AddSingleton(serviceProvider => { - var client = new ClientBuilder { + var client = new ClientBuilder + { ClientName = clientName, ClientConfiguration = clientConfiguration, HttpClient = serviceProvider.GetService().CreateClient(clientName), diff --git a/commercetools.Sdk/commercetools.Base.Client/ErrorHandler.cs b/commercetools.Sdk/commercetools.Base.Client/ErrorHandler.cs index 04ab0e059b2..7157ad8662d 100644 --- a/commercetools.Sdk/commercetools.Base.Client/ErrorHandler.cs +++ b/commercetools.Sdk/commercetools.Base.Client/ErrorHandler.cs @@ -8,7 +8,7 @@ namespace commercetools.Base.Client public class ErrorHandler : DelegatingHandler { private readonly Func _errorResponseBodyMapper; - + public ErrorHandler(Func errorResponseBodyMapper) { this._errorResponseBodyMapper = errorResponseBodyMapper; diff --git a/commercetools.Sdk/commercetools.Base.Client/LoggerHandler.cs b/commercetools.Sdk/commercetools.Base.Client/LoggerHandler.cs index 3b3f0626fc1..990ba93610b 100644 --- a/commercetools.Sdk/commercetools.Base.Client/LoggerHandler.cs +++ b/commercetools.Sdk/commercetools.Base.Client/LoggerHandler.cs @@ -41,10 +41,10 @@ protected override async Task SendAsync( { var response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false); watch.Stop(); - + _httpLogger.Log(logger, (int)response.StatusCode < 400 ? _loggerHandlerOptions.ResponseLogEvent : _loggerHandlerOptions.DefaultExceptionLogEvent, request, response, watch.ElapsedMilliseconds); await _httpLogger.LogResponseBody(logger, LogLevel.Trace, request, response, watch.ElapsedMilliseconds); - + return response; } catch (ApiHttpException e) diff --git a/commercetools.Sdk/commercetools.Base.Client/Middlewares/NotFoundMiddleware.cs b/commercetools.Sdk/commercetools.Base.Client/Middlewares/NotFoundMiddleware.cs index d49b923ee96..dde421ae7ce 100644 --- a/commercetools.Sdk/commercetools.Base.Client/Middlewares/NotFoundMiddleware.cs +++ b/commercetools.Sdk/commercetools.Base.Client/Middlewares/NotFoundMiddleware.cs @@ -6,7 +6,7 @@ namespace commercetools.Base.Client.Middlewares; -public class NotFoundMiddleware: DelegatingMiddleware +public class NotFoundMiddleware : DelegatingMiddleware { protected internal override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { diff --git a/reference.txt b/reference.txt new file mode 100644 index 00000000000..3d8c1962584 --- /dev/null +++ b/reference.txt @@ -0,0 +1 @@ +505b3af56b4452b22dfb595f93e010b3e2fccc53 diff --git a/references.txt b/references.txt index d276643cb20..ae08ace70a6 100644 --- a/references.txt +++ b/references.txt @@ -298,3 +298,4 @@ f254d17f05343dcc4299fc53ff9b335b5ef63d69 6892be230f1ad73f1150dd544c9fa7fee0e6b123 6a8624fb41168a6a78ac836b7208c2790a686608 b747e1fa4f246b748a89bccbfd8a43f5b6f51175 +f4cb4be0d9a27d8799b209eeb70db38bd80d5f57