diff --git a/src/Ocelot.Administration/IIdentityServerConfiguration.cs b/src/Ocelot.Administration/IIdentityServerConfiguration.cs index eb389cf9..cbfa289e 100644 --- a/src/Ocelot.Administration/IIdentityServerConfiguration.cs +++ b/src/Ocelot.Administration/IIdentityServerConfiguration.cs @@ -4,10 +4,10 @@ namespace Ocelot.Administration public interface IIdentityServerConfiguration { - string ApiName { get; } - string ApiSecret { get; } - bool RequireHttps { get; } - List AllowedScopes { get; } + string ApiName { get; } + string ApiSecret { get; } + bool RequireHttps { get; } + List AllowedScopes { get; } string CredentialsSigningCertificateLocation { get; } string CredentialsSigningCertificatePassword { get; } } diff --git a/src/Ocelot.Administration/IdentityServerMiddlewareConfigurationProvider.cs b/src/Ocelot.Administration/IdentityServerMiddlewareConfigurationProvider.cs index 3ad31b69..b4b8994a 100644 --- a/src/Ocelot.Administration/IdentityServerMiddlewareConfigurationProvider.cs +++ b/src/Ocelot.Administration/IdentityServerMiddlewareConfigurationProvider.cs @@ -1,11 +1,10 @@ namespace Ocelot.Administration { - using System.Threading.Tasks; - using Configuration; using Configuration.Repository; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Ocelot.Middleware; + using System.Threading.Tasks; public static class IdentityServerMiddlewareConfigurationProvider { diff --git a/src/Ocelot.Administration/OcelotBuilderExtensions.cs b/src/Ocelot.Administration/OcelotBuilderExtensions.cs index caafa4df..207b3bcf 100644 --- a/src/Ocelot.Administration/OcelotBuilderExtensions.cs +++ b/src/Ocelot.Administration/OcelotBuilderExtensions.cs @@ -1,14 +1,6 @@ namespace Ocelot.Administration { - using System; - using System.Collections.Generic; - using System.IdentityModel.Tokens.Jwt; - using System.Linq; - using System.Security.Cryptography.X509Certificates; - using Configuration; - using Configuration.Creator; using DependencyInjection; - using IdentityModel; using IdentityServer4.AccessTokenValidation; using IdentityServer4.Models; using Microsoft.AspNetCore.Builder; @@ -16,6 +8,10 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Ocelot.Middleware; + using System; + using System.Collections.Generic; + using System.IdentityModel.Tokens.Jwt; + using System.Security.Cryptography.X509Certificates; public static class OcelotBuilderExtensions { @@ -61,7 +57,8 @@ { builder.Services.TryAddSingleton(identityServerConfiguration); var identityServerBuilder = builder.Services - .AddIdentityServer(o => { + .AddIdentityServer(o => + { o.IssuerUri = "Ocelot"; }) .AddInMemoryApiResources(Resources(identityServerConfiguration)) diff --git a/src/Ocelot.Cache.CacheManager/OcelotBuilderExtensions.cs b/src/Ocelot.Cache.CacheManager/OcelotBuilderExtensions.cs index e9841890..7a2c2d86 100644 --- a/src/Ocelot.Cache.CacheManager/OcelotBuilderExtensions.cs +++ b/src/Ocelot.Cache.CacheManager/OcelotBuilderExtensions.cs @@ -1,12 +1,12 @@ namespace Ocelot.Cache.CacheManager { - using System; using Configuration; using Configuration.File; using DependencyInjection; using global::CacheManager.Core; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; + using System; public static class OcelotBuilderExtensions { diff --git a/src/Ocelot.Cache.CacheManager/OcelotCacheManagerCache.cs b/src/Ocelot.Cache.CacheManager/OcelotCacheManagerCache.cs index 7165edb5..a95df4c4 100644 --- a/src/Ocelot.Cache.CacheManager/OcelotCacheManagerCache.cs +++ b/src/Ocelot.Cache.CacheManager/OcelotCacheManagerCache.cs @@ -1,7 +1,7 @@ namespace Ocelot.Cache.CacheManager { - using System; using global::CacheManager.Core; + using System; public class OcelotCacheManagerCache : IOcelotCache { diff --git a/src/Ocelot.Provider.Consul/Consul.cs b/src/Ocelot.Provider.Consul/Consul.cs index 3aac63b6..2625d3f7 100644 --- a/src/Ocelot.Provider.Consul/Consul.cs +++ b/src/Ocelot.Provider.Consul/Consul.cs @@ -1,16 +1,15 @@ namespace Ocelot.Provider.Consul { - using System; - using System.Collections.Generic; - using System.Linq; - using System.Threading.Tasks; using global::Consul; using Infrastructure.Extensions; using Logging; using ServiceDiscovery.Providers; + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; using Values; - public class Consul : IServiceDiscoveryProvider { private readonly ConsulRegistryConfiguration _config; diff --git a/src/Ocelot.Provider.Consul/ConsulClientFactory.cs b/src/Ocelot.Provider.Consul/ConsulClientFactory.cs index de1f30aa..f3f0e54f 100644 --- a/src/Ocelot.Provider.Consul/ConsulClientFactory.cs +++ b/src/Ocelot.Provider.Consul/ConsulClientFactory.cs @@ -1,7 +1,7 @@ namespace Ocelot.Provider.Consul { - using System; using global::Consul; + using System; public class ConsulClientFactory : IConsulClientFactory { diff --git a/src/Ocelot.Provider.Consul/ConsulFileConfigurationRepository.cs b/src/Ocelot.Provider.Consul/ConsulFileConfigurationRepository.cs index 01273a35..7d7f4d44 100644 --- a/src/Ocelot.Provider.Consul/ConsulFileConfigurationRepository.cs +++ b/src/Ocelot.Provider.Consul/ConsulFileConfigurationRepository.cs @@ -1,14 +1,14 @@ namespace Ocelot.Provider.Consul { - using System; - using System.Text; - using System.Threading.Tasks; using Configuration.File; using Configuration.Repository; using global::Consul; using Logging; using Newtonsoft.Json; using Responses; + using System; + using System.Text; + using System.Threading.Tasks; public class ConsulFileConfigurationRepository : IFileConfigurationRepository { diff --git a/src/Ocelot.Provider.Consul/ConsulMiddlewareConfigurationProvider.cs b/src/Ocelot.Provider.Consul/ConsulMiddlewareConfigurationProvider.cs index a25d3752..1b89b4f3 100644 --- a/src/Ocelot.Provider.Consul/ConsulMiddlewareConfigurationProvider.cs +++ b/src/Ocelot.Provider.Consul/ConsulMiddlewareConfigurationProvider.cs @@ -1,8 +1,5 @@ namespace Ocelot.Provider.Consul { - using System; - using System.Linq; - using System.Threading.Tasks; using Configuration.Creator; using Configuration.File; using Configuration.Repository; @@ -11,6 +8,9 @@ using Microsoft.Extensions.Options; using Middleware; using Responses; + using System; + using System.Linq; + using System.Threading.Tasks; public static class ConsulMiddlewareConfigurationProvider { diff --git a/src/Ocelot.Provider.Consul/ConsulProviderFactory.cs b/src/Ocelot.Provider.Consul/ConsulProviderFactory.cs index 53095404..cdf422b8 100644 --- a/src/Ocelot.Provider.Consul/ConsulProviderFactory.cs +++ b/src/Ocelot.Provider.Consul/ConsulProviderFactory.cs @@ -1,8 +1,6 @@ namespace Ocelot.Provider.Consul { - using System.Threading.Tasks; using Logging; - using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using ServiceDiscovery; diff --git a/src/Ocelot.Provider.Consul/PollingConsulServiceDiscoveryProvider.cs b/src/Ocelot.Provider.Consul/PollingConsulServiceDiscoveryProvider.cs index 32470153..15abc777 100644 --- a/src/Ocelot.Provider.Consul/PollingConsulServiceDiscoveryProvider.cs +++ b/src/Ocelot.Provider.Consul/PollingConsulServiceDiscoveryProvider.cs @@ -1,10 +1,10 @@ namespace Ocelot.Provider.Consul { + using Logging; + using ServiceDiscovery.Providers; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; - using Logging; - using ServiceDiscovery.Providers; using Values; public class PollConsul : IServiceDiscoveryProvider diff --git a/src/Ocelot.Provider.Consul/UnableToSetConfigInConsulError.cs b/src/Ocelot.Provider.Consul/UnableToSetConfigInConsulError.cs index b0163916..bc3103ac 100644 --- a/src/Ocelot.Provider.Consul/UnableToSetConfigInConsulError.cs +++ b/src/Ocelot.Provider.Consul/UnableToSetConfigInConsulError.cs @@ -4,7 +4,7 @@ public class UnableToSetConfigInConsulError : Error { - public UnableToSetConfigInConsulError(string s) + public UnableToSetConfigInConsulError(string s) : base(s, OcelotErrorCode.UnknownError) { } diff --git a/src/Ocelot.Provider.Eureka/Eureka.cs b/src/Ocelot.Provider.Eureka/Eureka.cs index b4f5fd3b..8316beac 100644 --- a/src/Ocelot.Provider.Eureka/Eureka.cs +++ b/src/Ocelot.Provider.Eureka/Eureka.cs @@ -1,10 +1,10 @@ namespace Ocelot.Provider.Eureka { + using ServiceDiscovery.Providers; + using Steeltoe.Common.Discovery; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; - using ServiceDiscovery.Providers; - using Steeltoe.Common.Discovery; using Values; public class Eureka : IServiceDiscoveryProvider diff --git a/src/Ocelot.Provider.Eureka/EurekaMiddlewareConfigurationProvider.cs b/src/Ocelot.Provider.Eureka/EurekaMiddlewareConfigurationProvider.cs index ac6bba72..f893ed72 100644 --- a/src/Ocelot.Provider.Eureka/EurekaMiddlewareConfigurationProvider.cs +++ b/src/Ocelot.Provider.Eureka/EurekaMiddlewareConfigurationProvider.cs @@ -1,11 +1,11 @@ namespace Ocelot.Provider.Eureka { - using System.Threading.Tasks; using Configuration; using Configuration.Repository; using Microsoft.Extensions.DependencyInjection; using Middleware; using Steeltoe.Discovery.Client; + using System.Threading.Tasks; public class EurekaMiddlewareConfigurationProvider { diff --git a/src/Ocelot.Provider.Eureka/EurekaProviderFactory.cs b/src/Ocelot.Provider.Eureka/EurekaProviderFactory.cs index b35fe7c8..9fdea310 100644 --- a/src/Ocelot.Provider.Eureka/EurekaProviderFactory.cs +++ b/src/Ocelot.Provider.Eureka/EurekaProviderFactory.cs @@ -2,7 +2,6 @@ { using Microsoft.Extensions.DependencyInjection; using ServiceDiscovery; - using ServiceDiscovery.Providers; using Steeltoe.Common.Discovery; public static class EurekaProviderFactory diff --git a/src/Ocelot.Provider.Eureka/OcelotBuilderExtensions.cs b/src/Ocelot.Provider.Eureka/OcelotBuilderExtensions.cs index 0e69d433..4a246e4f 100644 --- a/src/Ocelot.Provider.Eureka/OcelotBuilderExtensions.cs +++ b/src/Ocelot.Provider.Eureka/OcelotBuilderExtensions.cs @@ -1,12 +1,12 @@ namespace Ocelot.Provider.Eureka { - using System.Linq; using DependencyInjection; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Middleware; - using Steeltoe.Discovery.Client; using ServiceDiscovery; + using Steeltoe.Discovery.Client; + using System.Linq; public static class OcelotBuilderExtensions { diff --git a/src/Ocelot.Provider.Kubernetes/KubeProvider.cs b/src/Ocelot.Provider.Kubernetes/KubeProvider.cs index 5baa7e31..b790c147 100644 --- a/src/Ocelot.Provider.Kubernetes/KubeProvider.cs +++ b/src/Ocelot.Provider.Kubernetes/KubeProvider.cs @@ -22,7 +22,6 @@ namespace Ocelot.Provider.Kubernetes this.kubeApi = kubeApi; } - public async Task> Get() { var service = await kubeApi.ServicesV1() diff --git a/src/Ocelot.Provider.Kubernetes/KubeRegistryConfiguration.cs b/src/Ocelot.Provider.Kubernetes/KubeRegistryConfiguration.cs index 5c35bbeb..3aea206e 100644 --- a/src/Ocelot.Provider.Kubernetes/KubeRegistryConfiguration.cs +++ b/src/Ocelot.Provider.Kubernetes/KubeRegistryConfiguration.cs @@ -1,7 +1,4 @@ -using KubeClient; -using System; - -namespace Ocelot.Provider.Kubernetes +namespace Ocelot.Provider.Kubernetes { public class KubeRegistryConfiguration { diff --git a/src/Ocelot.Provider.Polly/CircuitBreaker.cs b/src/Ocelot.Provider.Polly/CircuitBreaker.cs index 762749d6..8d4c6d4c 100644 --- a/src/Ocelot.Provider.Polly/CircuitBreaker.cs +++ b/src/Ocelot.Provider.Polly/CircuitBreaker.cs @@ -1,15 +1,13 @@ +using Polly; using System.Collections.Generic; using System.Linq; -using Polly; -using Polly.CircuitBreaker; -using Polly.Timeout; namespace Ocelot.Provider.Polly { public class CircuitBreaker { private readonly List _policies = new List(); - + public CircuitBreaker(params IAsyncPolicy[] policies) { foreach (var policy in policies.Where(p => p != null)) @@ -17,7 +15,7 @@ namespace Ocelot.Provider.Polly this._policies.Add(policy); } } - + public IAsyncPolicy[] Policies => this._policies.ToArray(); } } diff --git a/src/Ocelot.Provider.Polly/OcelotBuilderExtensions.cs b/src/Ocelot.Provider.Polly/OcelotBuilderExtensions.cs index ae7e881c..f753d9d3 100644 --- a/src/Ocelot.Provider.Polly/OcelotBuilderExtensions.cs +++ b/src/Ocelot.Provider.Polly/OcelotBuilderExtensions.cs @@ -1,9 +1,5 @@ namespace Ocelot.Provider.Polly { - using System; - using System.Collections.Generic; - using System.Net.Http; - using System.Threading.Tasks; using Configuration; using DependencyInjection; using Errors; @@ -12,6 +8,10 @@ using Logging; using Microsoft.Extensions.DependencyInjection; using Requester; + using System; + using System.Collections.Generic; + using System.Net.Http; + using System.Threading.Tasks; public static class OcelotBuilderExtensions { @@ -31,7 +31,7 @@ return new PollyCircuitBreakingDelegatingHandler(new PollyQoSProvider(reRoute, logger), logger); } - builder.Services.AddSingleton((QosDelegatingHandlerDelegate) QosDelegatingHandlerDelegate); + builder.Services.AddSingleton((QosDelegatingHandlerDelegate)QosDelegatingHandlerDelegate); return builder; } } diff --git a/src/Ocelot.Provider.Polly/PollyCircuitBreakingDelegatingHandler.cs b/src/Ocelot.Provider.Polly/PollyCircuitBreakingDelegatingHandler.cs index 2e5bb5a9..8bdcaa4a 100644 --- a/src/Ocelot.Provider.Polly/PollyCircuitBreakingDelegatingHandler.cs +++ b/src/Ocelot.Provider.Polly/PollyCircuitBreakingDelegatingHandler.cs @@ -1,9 +1,9 @@ -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; using Ocelot.Logging; using Polly; using Polly.CircuitBreaker; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; namespace Ocelot.Provider.Polly { @@ -26,11 +26,11 @@ namespace Ocelot.Provider.Polly { return await Policy .WrapAsync(_qoSProvider.CircuitBreaker.Policies) - .ExecuteAsync(() => base.SendAsync(request,cancellationToken)); + .ExecuteAsync(() => base.SendAsync(request, cancellationToken)); } catch (BrokenCircuitException ex) { - _logger.LogError($"Reached to allowed number of exceptions. Circuit is open",ex); + _logger.LogError($"Reached to allowed number of exceptions. Circuit is open", ex); throw; } catch (HttpRequestException ex) diff --git a/src/Ocelot.Provider.Polly/PollyQoSProvider.cs b/src/Ocelot.Provider.Polly/PollyQoSProvider.cs index 4344f1b9..3f2c6720 100644 --- a/src/Ocelot.Provider.Polly/PollyQoSProvider.cs +++ b/src/Ocelot.Provider.Polly/PollyQoSProvider.cs @@ -1,12 +1,12 @@ namespace Ocelot.Provider.Polly { - using System; - using System.Net.Http; using global::Polly; using global::Polly.CircuitBreaker; using global::Polly.Timeout; using Ocelot.Configuration; using Ocelot.Logging; + using System; + using System.Net.Http; public class PollyQoSProvider { diff --git a/src/Ocelot.Provider.Polly/RequestTimedOutError.cs b/src/Ocelot.Provider.Polly/RequestTimedOutError.cs index 4e910b12..63ad74ae 100644 --- a/src/Ocelot.Provider.Polly/RequestTimedOutError.cs +++ b/src/Ocelot.Provider.Polly/RequestTimedOutError.cs @@ -1,7 +1,7 @@ namespace Ocelot.Provider.Polly { - using System; using Errors; + using System; public class RequestTimedOutError : Error { diff --git a/src/Ocelot.Provider.Rafty/FilePeersProvider.cs b/src/Ocelot.Provider.Rafty/FilePeersProvider.cs index 1f9300bc..ddca1ac2 100644 --- a/src/Ocelot.Provider.Rafty/FilePeersProvider.cs +++ b/src/Ocelot.Provider.Rafty/FilePeersProvider.cs @@ -1,14 +1,13 @@ namespace Ocelot.Provider.Rafty { - using System.Net.Http; - using Configuration; + using Administration; using Configuration.Repository; using global::Rafty.Concensus.Peers; using global::Rafty.Infrastructure; using Microsoft.Extensions.Options; using Middleware; using System.Collections.Generic; - using Administration; + using System.Net.Http; public class FilePeersProvider : IPeersProvider { diff --git a/src/Ocelot.Provider.Rafty/HttpPeer.cs b/src/Ocelot.Provider.Rafty/HttpPeer.cs index 11397293..c3ed9e65 100644 --- a/src/Ocelot.Provider.Rafty/HttpPeer.cs +++ b/src/Ocelot.Provider.Rafty/HttpPeer.cs @@ -1,7 +1,6 @@ namespace Ocelot.Provider.Rafty { - using System.Net.Http; - using System.Threading.Tasks; + using Administration; using Configuration; using global::Rafty.Concensus.Messages; using global::Rafty.Concensus.Peers; @@ -11,7 +10,8 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; - using Administration; + using System.Net.Http; + using System.Threading.Tasks; public class HttpPeer : IPeer { diff --git a/src/Ocelot.Provider.Rafty/OcelotFiniteStateMachine.cs b/src/Ocelot.Provider.Rafty/OcelotFiniteStateMachine.cs index c7dd3ef6..b054852e 100644 --- a/src/Ocelot.Provider.Rafty/OcelotFiniteStateMachine.cs +++ b/src/Ocelot.Provider.Rafty/OcelotFiniteStateMachine.cs @@ -1,9 +1,9 @@ namespace Ocelot.Provider.Rafty { - using System.Threading.Tasks; using Configuration.Setter; using global::Rafty.FiniteStateMachine; using global::Rafty.Log; + using System.Threading.Tasks; public class OcelotFiniteStateMachine : IFiniteStateMachine { diff --git a/src/Ocelot.Provider.Rafty/RaftController.cs b/src/Ocelot.Provider.Rafty/RaftController.cs index 9cf51dd6..a8006cdc 100644 --- a/src/Ocelot.Provider.Rafty/RaftController.cs +++ b/src/Ocelot.Provider.Rafty/RaftController.cs @@ -1,8 +1,5 @@ namespace Ocelot.Provider.Rafty { - using System; - using System.IO; - using System.Threading.Tasks; using global::Rafty.Concensus.Messages; using global::Rafty.Concensus.Node; using global::Rafty.FiniteStateMachine; @@ -11,6 +8,9 @@ using Microsoft.AspNetCore.Mvc; using Middleware; using Newtonsoft.Json; + using System; + using System.IO; + using System.Threading.Tasks; [Authorize] [Route("raft")] diff --git a/src/Ocelot.Provider.Rafty/RaftyFileConfigurationSetter.cs b/src/Ocelot.Provider.Rafty/RaftyFileConfigurationSetter.cs index bf26ab07..21fc97a8 100644 --- a/src/Ocelot.Provider.Rafty/RaftyFileConfigurationSetter.cs +++ b/src/Ocelot.Provider.Rafty/RaftyFileConfigurationSetter.cs @@ -1,10 +1,10 @@ namespace Ocelot.Provider.Rafty { - using System.Threading.Tasks; using Configuration.File; using Configuration.Setter; using global::Rafty.Concensus.Node; using global::Rafty.Infrastructure; + using System.Threading.Tasks; public class RaftyFileConfigurationSetter : IFileConfigurationSetter { diff --git a/src/Ocelot.Provider.Rafty/RaftyMiddlewareConfigurationProvider.cs b/src/Ocelot.Provider.Rafty/RaftyMiddlewareConfigurationProvider.cs index e8c3ad5c..62e9711d 100644 --- a/src/Ocelot.Provider.Rafty/RaftyMiddlewareConfigurationProvider.cs +++ b/src/Ocelot.Provider.Rafty/RaftyMiddlewareConfigurationProvider.cs @@ -1,12 +1,12 @@ namespace Ocelot.Provider.Rafty { - using System.Threading.Tasks; using global::Rafty.Concensus.Node; using global::Rafty.Infrastructure; using Microsoft.AspNetCore.Builder; + using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Middleware; - using Microsoft.AspNetCore.Hosting; + using System.Threading.Tasks; public static class RaftyMiddlewareConfigurationProvider { diff --git a/src/Ocelot.Provider.Rafty/SqlLiteLog.cs b/src/Ocelot.Provider.Rafty/SqlLiteLog.cs index 618b4851..1be1645e 100644 --- a/src/Ocelot.Provider.Rafty/SqlLiteLog.cs +++ b/src/Ocelot.Provider.Rafty/SqlLiteLog.cs @@ -1,15 +1,15 @@ namespace Ocelot.Provider.Rafty { - using System; - using System.Collections.Generic; - using System.IO; - using System.Threading; - using System.Threading.Tasks; using global::Rafty.Infrastructure; using global::Rafty.Log; using Microsoft.Data.Sqlite; using Microsoft.Extensions.Logging; using Newtonsoft.Json; + using System; + using System.Collections.Generic; + using System.IO; + using System.Threading; + using System.Threading.Tasks; public class SqlLiteLog : ILog { diff --git a/src/Ocelot.Provider.Rafty/UnableToSaveAcceptCommand.cs b/src/Ocelot.Provider.Rafty/UnableToSaveAcceptCommand.cs index 888987ba..1a9f12e2 100644 --- a/src/Ocelot.Provider.Rafty/UnableToSaveAcceptCommand.cs +++ b/src/Ocelot.Provider.Rafty/UnableToSaveAcceptCommand.cs @@ -1,9 +1,10 @@ namespace Ocelot.Provider.Rafty { using Errors; + public class UnableToSaveAcceptCommand : Error { - public UnableToSaveAcceptCommand(string message) + public UnableToSaveAcceptCommand(string message) : base(message, OcelotErrorCode.UnknownError) { } diff --git a/src/Ocelot.Tracing.Butterfly/ButterflyTracer.cs b/src/Ocelot.Tracing.Butterfly/ButterflyTracer.cs index d8d1dd84..3cd63eb0 100644 --- a/src/Ocelot.Tracing.Butterfly/ButterflyTracer.cs +++ b/src/Ocelot.Tracing.Butterfly/ButterflyTracer.cs @@ -1,17 +1,17 @@ namespace Ocelot.Tracing.Butterfly { - using System; - using System.Collections.Generic; - using System.Linq; - using System.Net.Http; - using System.Threading; - using System.Threading.Tasks; using global::Butterfly.Client.AspNetCore; using global::Butterfly.Client.Tracing; using global::Butterfly.OpenTracing; using Infrastructure.Extensions; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; + using System; + using System.Collections.Generic; + using System.Linq; + using System.Net.Http; + using System.Threading; + using System.Threading.Tasks; public class ButterflyTracer : DelegatingHandler, Logging.ITracer { @@ -25,7 +25,7 @@ public void Event(HttpContext httpContext, string @event) { - // todo - if the user isnt using tracing the code gets here and will blow up on + // todo - if the user isnt using tracing the code gets here and will blow up on // _tracer.Tracer.TryExtract.. if (_tracer == null) { @@ -52,8 +52,8 @@ public Task SendAsync( HttpRequestMessage request, - CancellationToken cancellationToken, - Action addTraceIdToRepo, + CancellationToken cancellationToken, + Action addTraceIdToRepo, Func> baseSendAsync) { return _tracer.ChildTraceAsync($"httpclient {request.Method}", DateTimeOffset.UtcNow, span => TracingSendAsync(span, request, cancellationToken, addTraceIdToRepo, baseSendAsync)); @@ -62,8 +62,8 @@ protected virtual async Task TracingSendAsync( ISpan span, HttpRequestMessage request, - CancellationToken cancellationToken, - Action addTraceIdToRepo, + CancellationToken cancellationToken, + Action addTraceIdToRepo, Func> baseSendAsync) { if (request.Headers.Contains(PrefixSpanId)) diff --git a/src/Ocelot.Tracing.Butterfly/OcelotBuilderExtensions.cs b/src/Ocelot.Tracing.Butterfly/OcelotBuilderExtensions.cs index 4a543a2e..8c67f0df 100644 --- a/src/Ocelot.Tracing.Butterfly/OcelotBuilderExtensions.cs +++ b/src/Ocelot.Tracing.Butterfly/OcelotBuilderExtensions.cs @@ -1,10 +1,10 @@ namespace Ocelot.Tracing.Butterfly { - using System; using DependencyInjection; using global::Butterfly.Client.AspNetCore; using Logging; using Microsoft.Extensions.DependencyInjection; + using System; public static class OcelotBuilderExtensions { diff --git a/src/Ocelot/Authentication/Middleware/AuthenticationMiddleware.cs b/src/Ocelot/Authentication/Middleware/AuthenticationMiddleware.cs index af7f5791..942e8cac 100644 --- a/src/Ocelot/Authentication/Middleware/AuthenticationMiddleware.cs +++ b/src/Ocelot/Authentication/Middleware/AuthenticationMiddleware.cs @@ -1,11 +1,8 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authentication; using Ocelot.Configuration; -using Ocelot.Errors; -using Ocelot.Infrastructure.Extensions; using Ocelot.Logging; using Ocelot.Middleware; +using System.Threading.Tasks; namespace Ocelot.Authentication.Middleware { diff --git a/src/Ocelot/Authentication/Middleware/AuthenticationMiddlewareMiddlewareExtensions.cs b/src/Ocelot/Authentication/Middleware/AuthenticationMiddlewareMiddlewareExtensions.cs index 27b0f197..edd49f32 100644 --- a/src/Ocelot/Authentication/Middleware/AuthenticationMiddlewareMiddlewareExtensions.cs +++ b/src/Ocelot/Authentication/Middleware/AuthenticationMiddlewareMiddlewareExtensions.cs @@ -9,4 +9,4 @@ namespace Ocelot.Authentication.Middleware return builder.UseMiddleware(); } } -} +} diff --git a/src/Ocelot/Authorisation/ClaimValueNotAuthorisedError.cs b/src/Ocelot/Authorisation/ClaimValueNotAuthorisedError.cs index 9d552205..d0535624 100644 --- a/src/Ocelot/Authorisation/ClaimValueNotAuthorisedError.cs +++ b/src/Ocelot/Authorisation/ClaimValueNotAuthorisedError.cs @@ -4,9 +4,9 @@ namespace Ocelot.Authorisation { public class ClaimValueNotAuthorisedError : Error { - public ClaimValueNotAuthorisedError(string message) + public ClaimValueNotAuthorisedError(string message) : base(message, OcelotErrorCode.ClaimValueNotAuthorisedError) { } } -} +} diff --git a/src/Ocelot/Authorisation/ClaimsAuthoriser.cs b/src/Ocelot/Authorisation/ClaimsAuthoriser.cs index 75a166f2..5ae95e91 100644 --- a/src/Ocelot/Authorisation/ClaimsAuthoriser.cs +++ b/src/Ocelot/Authorisation/ClaimsAuthoriser.cs @@ -1,14 +1,10 @@ -using System; +using Ocelot.DownstreamRouteFinder.UrlMatcher; +using Ocelot.Responses; using System.Collections.Generic; using System.Linq; using System.Security.Claims; using System.Text.RegularExpressions; -using Ocelot.DownstreamRouteFinder.UrlMatcher; -using Ocelot.Middleware; -using Ocelot.Responses; -using Ocelot.Values; - namespace Ocelot.Authorisation { using Infrastructure.Claims.Parser; @@ -26,7 +22,8 @@ namespace Ocelot.Authorisation ClaimsPrincipal claimsPrincipal, Dictionary routeClaimsRequirement, List urlPathPlaceholderNameAndValues - ){ + ) + { foreach (var required in routeClaimsRequirement) { var values = _claimsParser.GetValuesByClaimType(claimsPrincipal.Claims, required.Key); @@ -62,15 +59,14 @@ namespace Ocelot.Authorisation if (matchingPlaceholders.Length == 0) { return new ErrorResponse(new ClaimValueNotAuthorisedError( - $"config error: requires variable claim value: {variableName} placeholders does not contain that variable: {string.Join(", ", urlPathPlaceholderNameAndValues.Select(p=>p.Name))}")); + $"config error: requires variable claim value: {variableName} placeholders does not contain that variable: {string.Join(", ", urlPathPlaceholderNameAndValues.Select(p => p.Name))}")); } else { return new ErrorResponse(new ClaimValueNotAuthorisedError( - $"config error: requires variable claim value: {required.Value} but placeholders are ambiguous: {string.Join(", ", urlPathPlaceholderNameAndValues.Where(p=>p.Name.Equals(variableName)).Select(p => p.Value))}")); + $"config error: requires variable claim value: {required.Value} but placeholders are ambiguous: {string.Join(", ", urlPathPlaceholderNameAndValues.Where(p => p.Name.Equals(variableName)).Select(p => p.Value))}")); } } - } else { @@ -92,4 +88,4 @@ namespace Ocelot.Authorisation return new OkResponse(true); } } -} +} diff --git a/src/Ocelot/Authorisation/IClaimsAuthoriser.cs b/src/Ocelot/Authorisation/IClaimsAuthoriser.cs index 9f9ce3f8..5e4b9c59 100644 --- a/src/Ocelot/Authorisation/IClaimsAuthoriser.cs +++ b/src/Ocelot/Authorisation/IClaimsAuthoriser.cs @@ -1,9 +1,6 @@ -using System.Security.Claims; - -using Ocelot.Configuration; -using Ocelot.DownstreamRouteFinder.UrlMatcher; +using Ocelot.DownstreamRouteFinder.UrlMatcher; using Ocelot.Responses; -using Ocelot.Values; +using System.Security.Claims; namespace Ocelot.Authorisation { @@ -17,4 +14,4 @@ namespace Ocelot.Authorisation List urlPathPlaceholderNameAndValues ); } -} +} diff --git a/src/Ocelot/Authorisation/IScopesAuthoriser.cs b/src/Ocelot/Authorisation/IScopesAuthoriser.cs index a6a1396c..57047ce7 100644 --- a/src/Ocelot/Authorisation/IScopesAuthoriser.cs +++ b/src/Ocelot/Authorisation/IScopesAuthoriser.cs @@ -1,5 +1,5 @@ -using System.Security.Claims; -using Ocelot.Responses; +using Ocelot.Responses; +using System.Security.Claims; namespace Ocelot.Authorisation { @@ -9,4 +9,4 @@ namespace Ocelot.Authorisation { Response Authorise(ClaimsPrincipal claimsPrincipal, List routeAllowedScopes); } -} +} diff --git a/src/Ocelot/Authorisation/Middleware/AuthorisationMiddleware.cs b/src/Ocelot/Authorisation/Middleware/AuthorisationMiddleware.cs index 8e906d5c..cc5cfda8 100644 --- a/src/Ocelot/Authorisation/Middleware/AuthorisationMiddleware.cs +++ b/src/Ocelot/Authorisation/Middleware/AuthorisationMiddleware.cs @@ -1,12 +1,10 @@ namespace Ocelot.Authorisation.Middleware { - using System.Collections.Generic; - using System.Threading.Tasks; - using Errors; - using Ocelot.Middleware; - using Logging; - using Responses; using Configuration; + using Logging; + using Ocelot.Middleware; + using Responses; + using System.Threading.Tasks; public class AuthorisationMiddleware : OcelotMiddleware { @@ -18,7 +16,7 @@ IClaimsAuthoriser claimsAuthoriser, IScopesAuthoriser scopesAuthoriser, IOcelotLoggerFactory loggerFactory) - :base(loggerFactory.CreateLogger()) + : base(loggerFactory.CreateLogger()) { _next = next; _claimsAuthoriser = claimsAuthoriser; @@ -102,4 +100,4 @@ return reRoute.IsAuthorised; } } -} +} diff --git a/src/Ocelot/Authorisation/Middleware/AuthorisationMiddlewareMiddlewareExtensions.cs b/src/Ocelot/Authorisation/Middleware/AuthorisationMiddlewareMiddlewareExtensions.cs index df00eb6b..a4999381 100644 --- a/src/Ocelot/Authorisation/Middleware/AuthorisationMiddlewareMiddlewareExtensions.cs +++ b/src/Ocelot/Authorisation/Middleware/AuthorisationMiddlewareMiddlewareExtensions.cs @@ -9,4 +9,4 @@ namespace Ocelot.Authorisation.Middleware return builder.UseMiddleware(); } } -} +} diff --git a/src/Ocelot/Authorisation/ScopeNotAuthorisedError.cs b/src/Ocelot/Authorisation/ScopeNotAuthorisedError.cs index d99e1abd..1abf5715 100644 --- a/src/Ocelot/Authorisation/ScopeNotAuthorisedError.cs +++ b/src/Ocelot/Authorisation/ScopeNotAuthorisedError.cs @@ -4,9 +4,9 @@ namespace Ocelot.Authorisation { public class ScopeNotAuthorisedError : Error { - public ScopeNotAuthorisedError(string message) + public ScopeNotAuthorisedError(string message) : base(message, OcelotErrorCode.ScopeNotAuthorisedError) { } } -} +} diff --git a/src/Ocelot/Authorisation/ScopesAuthoriser.cs b/src/Ocelot/Authorisation/ScopesAuthoriser.cs index 6d7a8d57..8344d80b 100644 --- a/src/Ocelot/Authorisation/ScopesAuthoriser.cs +++ b/src/Ocelot/Authorisation/ScopesAuthoriser.cs @@ -1,7 +1,7 @@ using Ocelot.Responses; using System.Collections.Generic; -using System.Security.Claims; using System.Linq; +using System.Security.Claims; namespace Ocelot.Authorisation { diff --git a/src/Ocelot/Authorisation/UnauthorisedError.cs b/src/Ocelot/Authorisation/UnauthorisedError.cs index 2a594d72..5e8f054c 100644 --- a/src/Ocelot/Authorisation/UnauthorisedError.cs +++ b/src/Ocelot/Authorisation/UnauthorisedError.cs @@ -4,9 +4,9 @@ namespace Ocelot.Authorisation { public class UnauthorisedError : Error { - public UnauthorisedError(string message) + public UnauthorisedError(string message) : base(message, OcelotErrorCode.UnauthorizedError) { } } -} +} diff --git a/src/Ocelot/Authorisation/UserDoesNotHaveClaimError.cs b/src/Ocelot/Authorisation/UserDoesNotHaveClaimError.cs index 4752fdef..2cf8211d 100644 --- a/src/Ocelot/Authorisation/UserDoesNotHaveClaimError.cs +++ b/src/Ocelot/Authorisation/UserDoesNotHaveClaimError.cs @@ -4,9 +4,9 @@ namespace Ocelot.Authorisation { public class UserDoesNotHaveClaimError : Error { - public UserDoesNotHaveClaimError(string message) + public UserDoesNotHaveClaimError(string message) : base(message, OcelotErrorCode.UserDoesNotHaveClaimError) { } } -} +} diff --git a/src/Ocelot/Cache/CacheKeyGenerator.cs b/src/Ocelot/Cache/CacheKeyGenerator.cs index c33c6104..29b2174b 100644 --- a/src/Ocelot/Cache/CacheKeyGenerator.cs +++ b/src/Ocelot/Cache/CacheKeyGenerator.cs @@ -1,13 +1,17 @@ -using System.Text; +using Ocelot.Middleware; +using System.Text; using System.Threading.Tasks; -using Ocelot.Middleware; -namespace Ocelot.Cache { - public class CacheKeyGenerator : ICacheKeyGenerator { - public string GenerateRequestCacheKey(DownstreamContext context) { +namespace Ocelot.Cache +{ + public class CacheKeyGenerator : ICacheKeyGenerator + { + public string GenerateRequestCacheKey(DownstreamContext context) + { string hashedContent = null; StringBuilder downStreamUrlKeyBuilder = new StringBuilder($"{context.DownstreamRequest.Method}-{context.DownstreamRequest.OriginalString}"); - if (context.DownstreamRequest.Content != null) { + if (context.DownstreamRequest.Content != null) + { string requestContentString = Task.Run(async () => await context.DownstreamRequest.Content.ReadAsStringAsync()).Result; downStreamUrlKeyBuilder.Append(requestContentString); } diff --git a/src/Ocelot/Cache/CacheObject.cs b/src/Ocelot/Cache/CacheObject.cs index adee3ed8..ef310a06 100644 --- a/src/Ocelot/Cache/CacheObject.cs +++ b/src/Ocelot/Cache/CacheObject.cs @@ -2,7 +2,7 @@ { using System; - class CacheObject + internal class CacheObject { public CacheObject(T value, DateTime expires) { diff --git a/src/Ocelot/Cache/CachedResponse.cs b/src/Ocelot/Cache/CachedResponse.cs index 538a4c35..aa2fafcc 100644 --- a/src/Ocelot/Cache/CachedResponse.cs +++ b/src/Ocelot/Cache/CachedResponse.cs @@ -27,7 +27,7 @@ namespace Ocelot.Cache public Dictionary> ContentHeaders { get; private set; } public string Body { get; private set; } - + public string ReasonPhrase { get; private set; } } } diff --git a/src/Ocelot/Cache/ICacheKeyGenerator.cs b/src/Ocelot/Cache/ICacheKeyGenerator.cs index 5a65eb8a..fc6ad52b 100644 --- a/src/Ocelot/Cache/ICacheKeyGenerator.cs +++ b/src/Ocelot/Cache/ICacheKeyGenerator.cs @@ -1,7 +1,9 @@ using Ocelot.Middleware; -namespace Ocelot.Cache { - public interface ICacheKeyGenerator { +namespace Ocelot.Cache +{ + public interface ICacheKeyGenerator + { string GenerateRequestCacheKey(DownstreamContext context); } } diff --git a/src/Ocelot/Cache/IOcelotCache.cs b/src/Ocelot/Cache/IOcelotCache.cs index 04ac2b51..8d507489 100644 --- a/src/Ocelot/Cache/IOcelotCache.cs +++ b/src/Ocelot/Cache/IOcelotCache.cs @@ -5,8 +5,11 @@ namespace Ocelot.Cache public interface IOcelotCache { void Add(string key, T value, TimeSpan ttl, string region); + T Get(string key, string region); + void ClearRegion(string region); + void AddAndDelete(string key, T value, TimeSpan ttl, string region); } } diff --git a/src/Ocelot/Cache/InMemoryCache.cs b/src/Ocelot/Cache/InMemoryCache.cs index 64c1dbc5..c0c892ad 100644 --- a/src/Ocelot/Cache/InMemoryCache.cs +++ b/src/Ocelot/Cache/InMemoryCache.cs @@ -35,7 +35,7 @@ } else { - _regions.Add(region, new List{ key }); + _regions.Add(region, new List { key }); } } diff --git a/src/Ocelot/Cache/MD5Helper.cs b/src/Ocelot/Cache/MD5Helper.cs index d98bb8c5..ff8eaa30 100644 --- a/src/Ocelot/Cache/MD5Helper.cs +++ b/src/Ocelot/Cache/MD5Helper.cs @@ -1,20 +1,25 @@ using System.Security.Cryptography; using System.Text; -namespace Ocelot.Cache { - public static class MD5Helper { - public static string GenerateMd5(byte[] contentBytes) { +namespace Ocelot.Cache +{ + public static class MD5Helper + { + public static string GenerateMd5(byte[] contentBytes) + { MD5 md5 = MD5.Create(); byte[] hash = md5.ComputeHash(contentBytes); StringBuilder sb = new StringBuilder(); - for (int i = 0; i < hash.Length; i++) { + for (int i = 0; i < hash.Length; i++) + { sb.Append(hash[i].ToString("X2")); } return sb.ToString(); } - public static string GenerateMd5(string contentString) { + public static string GenerateMd5(string contentString) + { byte[] contentBytes = Encoding.Unicode.GetBytes(contentString); return GenerateMd5(contentBytes); } diff --git a/src/Ocelot/Cache/Middleware/OutputCacheMiddleware.cs b/src/Ocelot/Cache/Middleware/OutputCacheMiddleware.cs index ae99c52e..3d37febc 100644 --- a/src/Ocelot/Cache/Middleware/OutputCacheMiddleware.cs +++ b/src/Ocelot/Cache/Middleware/OutputCacheMiddleware.cs @@ -1,13 +1,13 @@ namespace Ocelot.Cache.Middleware { - using System; - using System.Linq; - using System.Net.Http; - using System.Threading.Tasks; using Ocelot.Logging; using Ocelot.Middleware; + using System; using System.IO; + using System.Linq; + using System.Net.Http; using System.Text; + using System.Threading.Tasks; public class OutputCacheMiddleware : OcelotMiddleware { @@ -19,7 +19,7 @@ IOcelotLoggerFactory loggerFactory, IOcelotCache outputCache, ICacheKeyGenerator cacheGeneratot) - :base(loggerFactory.CreateLogger()) + : base(loggerFactory.CreateLogger()) { _next = next; _outputCache = outputCache; @@ -71,16 +71,18 @@ Logger.LogDebug($"finished response added to cache for {downstreamUrlKey}"); } - private void SetHttpResponseMessageThisRequest(DownstreamContext context, + private void SetHttpResponseMessageThisRequest(DownstreamContext context, DownstreamResponse response) { context.DownstreamResponse = response; } - private string GenerateRequestCacheKey(DownstreamContext context) { + private string GenerateRequestCacheKey(DownstreamContext context) + { string hashedContent = null; StringBuilder downStreamUrlKeyBuilder = new StringBuilder($"{context.DownstreamRequest.Method}-{context.DownstreamRequest.OriginalString}"); - if(context.DownstreamRequest.Content != null) { + if (context.DownstreamRequest.Content != null) + { string requestContentString = Task.Run(async () => await context.DownstreamRequest.Content?.ReadAsStringAsync()).Result; downStreamUrlKeyBuilder.Append(requestContentString); } diff --git a/src/Ocelot/Cache/Middleware/OutputCacheMiddlewareExtensions.cs b/src/Ocelot/Cache/Middleware/OutputCacheMiddlewareExtensions.cs index e28df6f0..fa80a237 100644 --- a/src/Ocelot/Cache/Middleware/OutputCacheMiddlewareExtensions.cs +++ b/src/Ocelot/Cache/Middleware/OutputCacheMiddlewareExtensions.cs @@ -10,4 +10,4 @@ namespace Ocelot.Cache.Middleware return builder.UseMiddleware(); } } -} +} diff --git a/src/Ocelot/Cache/OutputCacheController.cs b/src/Ocelot/Cache/OutputCacheController.cs index cc33e8aa..3564e393 100644 --- a/src/Ocelot/Cache/OutputCacheController.cs +++ b/src/Ocelot/Cache/OutputCacheController.cs @@ -22,4 +22,4 @@ namespace Ocelot.Cache return new NoContentResult(); } } -} +} diff --git a/src/Ocelot/Cache/RegionCreator.cs b/src/Ocelot/Cache/RegionCreator.cs index f5a94c21..cc1a9359 100644 --- a/src/Ocelot/Cache/RegionCreator.cs +++ b/src/Ocelot/Cache/RegionCreator.cs @@ -1,6 +1,5 @@ -using System.Linq; -using Ocelot.Configuration; using Ocelot.Configuration.File; +using System.Linq; namespace Ocelot.Cache { @@ -8,16 +7,16 @@ namespace Ocelot.Cache { public string Create(FileReRoute reRoute) { - if(!string.IsNullOrEmpty(reRoute?.FileCacheOptions?.Region)) + if (!string.IsNullOrEmpty(reRoute?.FileCacheOptions?.Region)) { return reRoute?.FileCacheOptions?.Region; } var methods = string.Join("", reRoute.UpstreamHttpMethod.Select(m => m)); - var region = $"{methods}{reRoute.UpstreamPathTemplate.Replace("/", "")}"; - + var region = $"{methods}{reRoute.UpstreamPathTemplate.Replace("/", "")}"; + return region; } } -} +} diff --git a/src/Ocelot/Cache/Regions.cs b/src/Ocelot/Cache/Regions.cs index 2ef0f6a8..05f254cb 100644 --- a/src/Ocelot/Cache/Regions.cs +++ b/src/Ocelot/Cache/Regions.cs @@ -11,4 +11,4 @@ namespace Ocelot.Cache public List Value { get; } } -} +} diff --git a/src/Ocelot/Claims/AddClaimsToRequest.cs b/src/Ocelot/Claims/AddClaimsToRequest.cs index 9ff0254f..ab197c2b 100644 --- a/src/Ocelot/Claims/AddClaimsToRequest.cs +++ b/src/Ocelot/Claims/AddClaimsToRequest.cs @@ -1,10 +1,10 @@ -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; using Ocelot.Configuration; using Ocelot.Infrastructure.Claims.Parser; using Ocelot.Responses; +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; namespace Ocelot.Claims { diff --git a/src/Ocelot/Claims/IAddClaimsToRequest.cs b/src/Ocelot/Claims/IAddClaimsToRequest.cs index 9adbcab4..b9db39f5 100644 --- a/src/Ocelot/Claims/IAddClaimsToRequest.cs +++ b/src/Ocelot/Claims/IAddClaimsToRequest.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; using Ocelot.Configuration; using Ocelot.Responses; +using System.Collections.Generic; namespace Ocelot.Claims { @@ -10,4 +10,4 @@ namespace Ocelot.Claims Response SetClaimsOnContext(List claimsToThings, HttpContext context); } -} +} diff --git a/src/Ocelot/Claims/Middleware/ClaimsToClaimsMiddleware.cs b/src/Ocelot/Claims/Middleware/ClaimsToClaimsMiddleware.cs index 7e1a301e..58838a97 100644 --- a/src/Ocelot/Claims/Middleware/ClaimsToClaimsMiddleware.cs +++ b/src/Ocelot/Claims/Middleware/ClaimsToClaimsMiddleware.cs @@ -1,10 +1,7 @@ -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Ocelot.DownstreamRouteFinder.Middleware; -using Ocelot.Infrastructure.RequestData; -using Ocelot.Logging; +using Ocelot.Logging; using Ocelot.Middleware; +using System.Linq; +using System.Threading.Tasks; namespace Ocelot.Claims.Middleware { @@ -13,10 +10,10 @@ namespace Ocelot.Claims.Middleware private readonly OcelotRequestDelegate _next; private readonly IAddClaimsToRequest _addClaimsToRequest; - public ClaimsToClaimsMiddleware(OcelotRequestDelegate next, + public ClaimsToClaimsMiddleware(OcelotRequestDelegate next, IOcelotLoggerFactory loggerFactory, - IAddClaimsToRequest addClaimsToRequest) - :base(loggerFactory.CreateLogger()) + IAddClaimsToRequest addClaimsToRequest) + : base(loggerFactory.CreateLogger()) { _next = next; _addClaimsToRequest = addClaimsToRequest; diff --git a/src/Ocelot/Configuration/AuthenticationOptions.cs b/src/Ocelot/Configuration/AuthenticationOptions.cs index 2b911b58..9cede795 100644 --- a/src/Ocelot/Configuration/AuthenticationOptions.cs +++ b/src/Ocelot/Configuration/AuthenticationOptions.cs @@ -13,4 +13,4 @@ namespace Ocelot.Configuration public List AllowedScopes { get; private set; } public string AuthenticationProviderKey { get; private set; } } -} +} diff --git a/src/Ocelot/Configuration/Builder/DownstreamReRouteBuilder.cs b/src/Ocelot/Configuration/Builder/DownstreamReRouteBuilder.cs index 8e2583d2..42ad17db 100644 --- a/src/Ocelot/Configuration/Builder/DownstreamReRouteBuilder.cs +++ b/src/Ocelot/Configuration/Builder/DownstreamReRouteBuilder.cs @@ -1,8 +1,8 @@ -using System.Collections.Generic; -using System.Net.Http; -using Ocelot.Values; -using System.Linq; using Ocelot.Configuration.Creator; +using Ocelot.Values; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; namespace Ocelot.Configuration.Builder { @@ -39,6 +39,7 @@ namespace Ocelot.Configuration.Builder private List _addHeadersToUpstream; private bool _dangerousAcceptAnyServerCertificateValidator; private SecurityOptions _securityOptions; + public DownstreamReRouteBuilder() { _downstreamAddresses = new List(); @@ -55,7 +56,7 @@ namespace Ocelot.Configuration.Builder public DownstreamReRouteBuilder WithLoadBalancerOptions(LoadBalancerOptions loadBalancerOptions) { - _loadBalancerOptions = loadBalancerOptions; + _loadBalancerOptions = loadBalancerOptions; return this; } @@ -142,7 +143,7 @@ namespace Ocelot.Configuration.Builder _qosOptions = input; return this; } - + public DownstreamReRouteBuilder WithLoadBalancerKey(string loadBalancerKey) { _loadBalancerKey = loadBalancerKey; @@ -239,26 +240,26 @@ namespace Ocelot.Configuration.Builder _key, _upstreamTemplatePattern, _upstreamHeaderFindAndReplace, - _downstreamHeaderFindAndReplace, + _downstreamHeaderFindAndReplace, _downstreamAddresses, - _serviceName, - _httpHandlerOptions, - _useServiceDiscovery, - _enableRateLimiting, + _serviceName, + _httpHandlerOptions, + _useServiceDiscovery, + _enableRateLimiting, _qosOptions, - _downstreamScheme, - _requestIdHeaderKey, - _isCached, - _fileCacheOptions, - _loadBalancerOptions, + _downstreamScheme, + _requestIdHeaderKey, + _isCached, + _fileCacheOptions, + _loadBalancerOptions, _rateLimitOptions, - _routeClaimRequirement, - _claimToQueries, - _claimsToHeaders, + _routeClaimRequirement, + _claimToQueries, + _claimsToHeaders, _claimToClaims, - _isAuthenticated, - _isAuthorised, - _authenticationOptions, + _isAuthenticated, + _isAuthorised, + _authenticationOptions, new DownstreamPathTemplate(_downstreamPathTemplate), _loadBalancerKey, _delegatingHandlers, diff --git a/src/Ocelot/Configuration/Builder/QoSOptionsBuilder.cs b/src/Ocelot/Configuration/Builder/QoSOptionsBuilder.cs index e1b86d1a..413163db 100644 --- a/src/Ocelot/Configuration/Builder/QoSOptionsBuilder.cs +++ b/src/Ocelot/Configuration/Builder/QoSOptionsBuilder.cs @@ -39,4 +39,4 @@ return new QoSOptions(_exceptionsAllowedBeforeBreaking, _durationOfBreak, _timeoutValue, _key); } } -} +} diff --git a/src/Ocelot/Configuration/Builder/RateLimitOptionsBuilder.cs b/src/Ocelot/Configuration/Builder/RateLimitOptionsBuilder.cs index 69ad913c..eba79769 100644 --- a/src/Ocelot/Configuration/Builder/RateLimitOptionsBuilder.cs +++ b/src/Ocelot/Configuration/Builder/RateLimitOptionsBuilder.cs @@ -63,9 +63,9 @@ namespace Ocelot.Configuration.Builder public RateLimitOptions Build() { - return new RateLimitOptions(_enableRateLimiting, _clientIdHeader, _clientWhitelist, - _disableRateLimitHeaders, _quotaExceededMessage, _rateLimitCounterPrefix, + return new RateLimitOptions(_enableRateLimiting, _clientIdHeader, _clientWhitelist, + _disableRateLimitHeaders, _quotaExceededMessage, _rateLimitCounterPrefix, _rateLimitRule, _httpStatusCode); } } -} +} diff --git a/src/Ocelot/Configuration/Builder/ReRouteBuilder.cs b/src/Ocelot/Configuration/Builder/ReRouteBuilder.cs index dae8c11e..4716c03a 100644 --- a/src/Ocelot/Configuration/Builder/ReRouteBuilder.cs +++ b/src/Ocelot/Configuration/Builder/ReRouteBuilder.cs @@ -1,10 +1,10 @@ namespace Ocelot.Configuration.Builder { - using System.Collections.Generic; - using System.Net.Http; - using Ocelot.Values; - using System.Linq; using Ocelot.Configuration.File; + using Ocelot.Values; + using System.Collections.Generic; + using System.Linq; + using System.Net.Http; public class ReRouteBuilder { @@ -68,11 +68,11 @@ return new ReRoute( _downstreamReRoutes, _downstreamReRoutesConfig, - _upstreamHttpMethod, - _upstreamTemplatePattern, + _upstreamHttpMethod, + _upstreamTemplatePattern, _upstreamHost, _aggregator ); } } -} +} diff --git a/src/Ocelot/Configuration/CacheOptions.cs b/src/Ocelot/Configuration/CacheOptions.cs index 46c49280..e5738a46 100644 --- a/src/Ocelot/Configuration/CacheOptions.cs +++ b/src/Ocelot/Configuration/CacheOptions.cs @@ -12,4 +12,4 @@ public string Region { get; private set; } } -} +} diff --git a/src/Ocelot/Configuration/ClaimToThing.cs b/src/Ocelot/Configuration/ClaimToThing.cs index 0d13f5d0..9264de5f 100644 --- a/src/Ocelot/Configuration/ClaimToThing.cs +++ b/src/Ocelot/Configuration/ClaimToThing.cs @@ -15,4 +15,4 @@ public string Delimiter { get; private set; } public int Index { get; private set; } } -} +} diff --git a/src/Ocelot/Configuration/Creator/AggregatesCreator.cs b/src/Ocelot/Configuration/Creator/AggregatesCreator.cs index 9acef561..1dd8fea5 100644 --- a/src/Ocelot/Configuration/Creator/AggregatesCreator.cs +++ b/src/Ocelot/Configuration/Creator/AggregatesCreator.cs @@ -1,9 +1,9 @@ namespace Ocelot.Configuration.Creator { - using System.Collections.Generic; - using System.Linq; using Builder; using File; + using System.Collections.Generic; + using System.Linq; public class AggregatesCreator : IAggregatesCreator { diff --git a/src/Ocelot/Configuration/Creator/AuthenticationOptionsCreator.cs b/src/Ocelot/Configuration/Creator/AuthenticationOptionsCreator.cs index ce5e0e1e..69f4f49d 100644 --- a/src/Ocelot/Configuration/Creator/AuthenticationOptionsCreator.cs +++ b/src/Ocelot/Configuration/Creator/AuthenticationOptionsCreator.cs @@ -7,6 +7,6 @@ namespace Ocelot.Configuration.Creator public AuthenticationOptions Create(FileReRoute reRoute) { return new AuthenticationOptions(reRoute.AuthenticationOptions.AllowedScopes, reRoute.AuthenticationOptions.AuthenticationProviderKey); - } + } } -} \ No newline at end of file +} diff --git a/src/Ocelot/Configuration/Creator/ClaimsToThingCreator.cs b/src/Ocelot/Configuration/Creator/ClaimsToThingCreator.cs index 0be61658..1500f5d3 100644 --- a/src/Ocelot/Configuration/Creator/ClaimsToThingCreator.cs +++ b/src/Ocelot/Configuration/Creator/ClaimsToThingCreator.cs @@ -1,6 +1,6 @@ -using System.Collections.Generic; using Ocelot.Configuration.Parser; using Ocelot.Logging; +using System.Collections.Generic; namespace Ocelot.Configuration.Creator { @@ -14,9 +14,9 @@ namespace Ocelot.Configuration.Creator { _logger = loggerFactory.CreateLogger(); _claimToThingConfigParser = claimToThingConfigurationParser; - } - - public List Create(Dictionary inputToBeParsed) + } + + public List Create(Dictionary inputToBeParsed) { var claimsToThings = new List(); @@ -37,4 +37,4 @@ namespace Ocelot.Configuration.Creator return claimsToThings; } } -} \ No newline at end of file +} diff --git a/src/Ocelot/Configuration/Creator/ConfigurationCreator.cs b/src/Ocelot/Configuration/Creator/ConfigurationCreator.cs index e6fe13ac..1d5abc32 100644 --- a/src/Ocelot/Configuration/Creator/ConfigurationCreator.cs +++ b/src/Ocelot/Configuration/Creator/ConfigurationCreator.cs @@ -1,10 +1,10 @@ namespace Ocelot.Configuration.Creator { + using DependencyInjection; + using File; + using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; - using File; - using DependencyInjection; - using Microsoft.Extensions.DependencyInjection; public class ConfigurationCreator : IConfigurationCreator { diff --git a/src/Ocelot/Configuration/Creator/DownstreamAddressesCreator.cs b/src/Ocelot/Configuration/Creator/DownstreamAddressesCreator.cs index 777f9dce..78718c84 100644 --- a/src/Ocelot/Configuration/Creator/DownstreamAddressesCreator.cs +++ b/src/Ocelot/Configuration/Creator/DownstreamAddressesCreator.cs @@ -1,6 +1,6 @@ +using Ocelot.Configuration.File; using System.Collections.Generic; using System.Linq; -using Ocelot.Configuration.File; namespace Ocelot.Configuration.Creator { @@ -11,4 +11,4 @@ namespace Ocelot.Configuration.Creator return reRoute.DownstreamHostAndPorts.Select(hostAndPort => new DownstreamHostAndPort(hostAndPort.Host, hostAndPort.Port)).ToList(); } } -} +} diff --git a/src/Ocelot/Configuration/Creator/DynamicsCreator.cs b/src/Ocelot/Configuration/Creator/DynamicsCreator.cs index 96d56287..2b5193c0 100644 --- a/src/Ocelot/Configuration/Creator/DynamicsCreator.cs +++ b/src/Ocelot/Configuration/Creator/DynamicsCreator.cs @@ -1,9 +1,9 @@ namespace Ocelot.Configuration.Creator { - using System.Collections.Generic; - using System.Linq; using Builder; using File; + using System.Collections.Generic; + using System.Linq; public class DynamicsCreator : IDynamicsCreator { diff --git a/src/Ocelot/Configuration/Creator/FileInternalConfigurationCreator.cs b/src/Ocelot/Configuration/Creator/FileInternalConfigurationCreator.cs index f59f8a80..1a12cab5 100644 --- a/src/Ocelot/Configuration/Creator/FileInternalConfigurationCreator.cs +++ b/src/Ocelot/Configuration/Creator/FileInternalConfigurationCreator.cs @@ -1,10 +1,10 @@ namespace Ocelot.Configuration.Creator { + using File; + using Responses; using System.Linq; using System.Threading.Tasks; - using File; using Validator; - using Responses; public class FileInternalConfigurationCreator : IInternalConfigurationCreator { diff --git a/src/Ocelot/Configuration/Creator/HeaderFindAndReplaceCreator.cs b/src/Ocelot/Configuration/Creator/HeaderFindAndReplaceCreator.cs index 53f629af..fdf05450 100644 --- a/src/Ocelot/Configuration/Creator/HeaderFindAndReplaceCreator.cs +++ b/src/Ocelot/Configuration/Creator/HeaderFindAndReplaceCreator.cs @@ -1,11 +1,9 @@ -using System; -using System.Collections.Generic; using Ocelot.Configuration.File; using Ocelot.Infrastructure; using Ocelot.Infrastructure.Extensions; using Ocelot.Logging; -using Ocelot.Middleware; using Ocelot.Responses; +using System.Collections.Generic; namespace Ocelot.Configuration.Creator { @@ -25,7 +23,7 @@ namespace Ocelot.Configuration.Creator var upstream = new List(); var addHeadersToUpstream = new List(); - foreach(var input in fileReRoute.UpstreamHeaderTransform) + foreach (var input in fileReRoute.UpstreamHeaderTransform) { if (input.Value.Contains(",")) { @@ -46,14 +44,14 @@ namespace Ocelot.Configuration.Creator } var downstream = new List(); - var addHeadersToDownstream = new List(); - - foreach(var input in fileReRoute.DownstreamHeaderTransform) + var addHeadersToDownstream = new List(); + + foreach (var input in fileReRoute.DownstreamHeaderTransform) { - if(input.Value.Contains(",")) + if (input.Value.Contains(",")) { var hAndr = Map(input); - if(!hAndr.IsError) + if (!hAndr.IsError) { downstream.Add(hAndr.Data); } @@ -66,27 +64,27 @@ namespace Ocelot.Configuration.Creator { addHeadersToDownstream.Add(new AddHeader(input.Key, input.Value)); } - } - + } + return new HeaderTransformations(upstream, downstream, addHeadersToDownstream, addHeadersToUpstream); } - private Response Map(KeyValuePair input) + private Response Map(KeyValuePair input) { var findAndReplace = input.Value.Split(","); var replace = findAndReplace[1].TrimStart(); var startOfPlaceholder = replace.IndexOf("{"); - if(startOfPlaceholder > -1) + if (startOfPlaceholder > -1) { - var endOfPlaceholder = replace.IndexOf("}", startOfPlaceholder); - + var endOfPlaceholder = replace.IndexOf("}", startOfPlaceholder); + var placeholder = replace.Substring(startOfPlaceholder, startOfPlaceholder + (endOfPlaceholder + 1)); var value = _placeholders.Get(placeholder); - if(value.IsError) + if (value.IsError) { return new ErrorResponse(value.Errors); } @@ -94,9 +92,9 @@ namespace Ocelot.Configuration.Creator replace = replace.Replace(placeholder, value.Data); } - var hAndr = new HeaderFindAndReplace(input.Key, findAndReplace[0], replace, 0); - + var hAndr = new HeaderFindAndReplace(input.Key, findAndReplace[0], replace, 0); + return new OkResponse(hAndr); } } -} +} diff --git a/src/Ocelot/Configuration/Creator/HeaderTransformations.cs b/src/Ocelot/Configuration/Creator/HeaderTransformations.cs index 72b6e1f6..29e9c40d 100644 --- a/src/Ocelot/Configuration/Creator/HeaderTransformations.cs +++ b/src/Ocelot/Configuration/Creator/HeaderTransformations.cs @@ -5,7 +5,7 @@ namespace Ocelot.Configuration.Creator public class HeaderTransformations { public HeaderTransformations( - List upstream, + List upstream, List downstream, List addHeaderToDownstream, List addHeaderToUpstream) @@ -23,4 +23,4 @@ namespace Ocelot.Configuration.Creator public List AddHeadersToDownstream { get; } public List AddHeadersToUpstream { get; } } -} +} diff --git a/src/Ocelot/Configuration/Creator/HttpHandlerOptionsCreator.cs b/src/Ocelot/Configuration/Creator/HttpHandlerOptionsCreator.cs index f55e35ca..08e79ad1 100644 --- a/src/Ocelot/Configuration/Creator/HttpHandlerOptionsCreator.cs +++ b/src/Ocelot/Configuration/Creator/HttpHandlerOptionsCreator.cs @@ -1,9 +1,9 @@ namespace Ocelot.Configuration.Creator { - using System; using Logging; using Microsoft.Extensions.DependencyInjection; using Ocelot.Configuration.File; + using System; public class HttpHandlerOptionsCreator : IHttpHandlerOptionsCreator { @@ -16,7 +16,7 @@ public HttpHandlerOptions Create(FileHttpHandlerOptions options) { - var useTracing = _tracer!= null && options.UseTracing; + var useTracing = _tracer != null && options.UseTracing; return new HttpHandlerOptions(options.AllowAutoRedirect, options.UseCookieContainer, useTracing, options.UseProxy); diff --git a/src/Ocelot/Configuration/Creator/IAggregatesCreator.cs b/src/Ocelot/Configuration/Creator/IAggregatesCreator.cs index 1586a2be..05fe2177 100644 --- a/src/Ocelot/Configuration/Creator/IAggregatesCreator.cs +++ b/src/Ocelot/Configuration/Creator/IAggregatesCreator.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; using Ocelot.Configuration.File; +using System.Collections.Generic; namespace Ocelot.Configuration.Creator { diff --git a/src/Ocelot/Configuration/Creator/IAuthenticationOptionsCreator.cs b/src/Ocelot/Configuration/Creator/IAuthenticationOptionsCreator.cs index a987f69a..95636af5 100644 --- a/src/Ocelot/Configuration/Creator/IAuthenticationOptionsCreator.cs +++ b/src/Ocelot/Configuration/Creator/IAuthenticationOptionsCreator.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using Ocelot.Configuration.File; namespace Ocelot.Configuration.Creator @@ -7,4 +6,4 @@ namespace Ocelot.Configuration.Creator { AuthenticationOptions Create(FileReRoute reRoute); } -} \ No newline at end of file +} diff --git a/src/Ocelot/Configuration/Creator/IClaimsToThingCreator.cs b/src/Ocelot/Configuration/Creator/IClaimsToThingCreator.cs index ead3d537..3f424790 100644 --- a/src/Ocelot/Configuration/Creator/IClaimsToThingCreator.cs +++ b/src/Ocelot/Configuration/Creator/IClaimsToThingCreator.cs @@ -4,6 +4,6 @@ namespace Ocelot.Configuration.Creator { public interface IClaimsToThingCreator { - List Create(Dictionary thingsBeingAdded); + List Create(Dictionary thingsBeingAdded); } -} \ No newline at end of file +} diff --git a/src/Ocelot/Configuration/Creator/IConfigurationCreator.cs b/src/Ocelot/Configuration/Creator/IConfigurationCreator.cs index aed2db54..8aa42d0e 100644 --- a/src/Ocelot/Configuration/Creator/IConfigurationCreator.cs +++ b/src/Ocelot/Configuration/Creator/IConfigurationCreator.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; using Ocelot.Configuration.File; +using System.Collections.Generic; namespace Ocelot.Configuration.Creator { diff --git a/src/Ocelot/Configuration/Creator/IDownstreamAddressesCreator.cs b/src/Ocelot/Configuration/Creator/IDownstreamAddressesCreator.cs index 6db1c1bf..e6081290 100644 --- a/src/Ocelot/Configuration/Creator/IDownstreamAddressesCreator.cs +++ b/src/Ocelot/Configuration/Creator/IDownstreamAddressesCreator.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; using Ocelot.Configuration.File; +using System.Collections.Generic; namespace Ocelot.Configuration.Creator { @@ -7,4 +7,4 @@ namespace Ocelot.Configuration.Creator { List Create(FileReRoute reRoute); } -} +} diff --git a/src/Ocelot/Configuration/Creator/IDynamicsCreator.cs b/src/Ocelot/Configuration/Creator/IDynamicsCreator.cs index f6c7e16c..715db098 100644 --- a/src/Ocelot/Configuration/Creator/IDynamicsCreator.cs +++ b/src/Ocelot/Configuration/Creator/IDynamicsCreator.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; using Ocelot.Configuration.File; +using System.Collections.Generic; namespace Ocelot.Configuration.Creator { diff --git a/src/Ocelot/Configuration/Creator/IHeaderFindAndReplaceCreator.cs b/src/Ocelot/Configuration/Creator/IHeaderFindAndReplaceCreator.cs index 9a983a8a..496e17bf 100644 --- a/src/Ocelot/Configuration/Creator/IHeaderFindAndReplaceCreator.cs +++ b/src/Ocelot/Configuration/Creator/IHeaderFindAndReplaceCreator.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using Ocelot.Configuration.File; namespace Ocelot.Configuration.Creator @@ -7,4 +6,4 @@ namespace Ocelot.Configuration.Creator { HeaderTransformations Create(FileReRoute fileReRoute); } -} +} diff --git a/src/Ocelot/Configuration/Creator/IHttpHandlerOptionsCreator.cs b/src/Ocelot/Configuration/Creator/IHttpHandlerOptionsCreator.cs index 80137651..76a9bc94 100644 --- a/src/Ocelot/Configuration/Creator/IHttpHandlerOptionsCreator.cs +++ b/src/Ocelot/Configuration/Creator/IHttpHandlerOptionsCreator.cs @@ -9,4 +9,4 @@ namespace Ocelot.Configuration.Creator { HttpHandlerOptions Create(FileHttpHandlerOptions fileReRoute); } -} +} diff --git a/src/Ocelot/Configuration/Creator/IInternalConfigurationCreator.cs b/src/Ocelot/Configuration/Creator/IInternalConfigurationCreator.cs index a0f3cb42..f8e39d7b 100644 --- a/src/Ocelot/Configuration/Creator/IInternalConfigurationCreator.cs +++ b/src/Ocelot/Configuration/Creator/IInternalConfigurationCreator.cs @@ -1,6 +1,6 @@ -using System.Threading.Tasks; using Ocelot.Configuration.File; using Ocelot.Responses; +using System.Threading.Tasks; namespace Ocelot.Configuration.Creator { diff --git a/src/Ocelot/Configuration/Creator/IQoSOptionsCreator.cs b/src/Ocelot/Configuration/Creator/IQoSOptionsCreator.cs index 77ada9c6..128058a9 100644 --- a/src/Ocelot/Configuration/Creator/IQoSOptionsCreator.cs +++ b/src/Ocelot/Configuration/Creator/IQoSOptionsCreator.cs @@ -1,12 +1,14 @@ -using System.Collections.Generic; using Ocelot.Configuration.File; +using System.Collections.Generic; namespace Ocelot.Configuration.Creator { public interface IQoSOptionsCreator { QoSOptions Create(FileQoSOptions options); + QoSOptions Create(FileQoSOptions options, string pathTemplate, List httpMethods); + QoSOptions Create(QoSOptions options, string pathTemplate, List httpMethods); } } diff --git a/src/Ocelot/Configuration/Creator/IReRouteOptionsCreator.cs b/src/Ocelot/Configuration/Creator/IReRouteOptionsCreator.cs index 1f7983d6..1d5761d5 100644 --- a/src/Ocelot/Configuration/Creator/IReRouteOptionsCreator.cs +++ b/src/Ocelot/Configuration/Creator/IReRouteOptionsCreator.cs @@ -6,4 +6,4 @@ namespace Ocelot.Configuration.Creator { ReRouteOptions Create(FileReRoute fileReRoute); } -} +} diff --git a/src/Ocelot/Configuration/Creator/IReRoutesCreator.cs b/src/Ocelot/Configuration/Creator/IReRoutesCreator.cs index 608e2af5..18b26528 100644 --- a/src/Ocelot/Configuration/Creator/IReRoutesCreator.cs +++ b/src/Ocelot/Configuration/Creator/IReRoutesCreator.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; using Ocelot.Configuration.File; +using System.Collections.Generic; namespace Ocelot.Configuration.Creator { diff --git a/src/Ocelot/Configuration/Creator/ISecurityOptionsCreator.cs b/src/Ocelot/Configuration/Creator/ISecurityOptionsCreator.cs index 792c8530..5f5f727f 100644 --- a/src/Ocelot/Configuration/Creator/ISecurityOptionsCreator.cs +++ b/src/Ocelot/Configuration/Creator/ISecurityOptionsCreator.cs @@ -1,7 +1,4 @@ using Ocelot.Configuration.File; -using System; -using System.Collections.Generic; -using System.Text; namespace Ocelot.Configuration.Creator { diff --git a/src/Ocelot/Configuration/Creator/IUpstreamTemplatePatternCreator.cs b/src/Ocelot/Configuration/Creator/IUpstreamTemplatePatternCreator.cs index b8303189..aaec7634 100644 --- a/src/Ocelot/Configuration/Creator/IUpstreamTemplatePatternCreator.cs +++ b/src/Ocelot/Configuration/Creator/IUpstreamTemplatePatternCreator.cs @@ -7,4 +7,4 @@ namespace Ocelot.Configuration.Creator { UpstreamPathTemplate Create(IReRoute reRoute); } -} +} diff --git a/src/Ocelot/Configuration/Creator/ReRouteKeyCreator.cs b/src/Ocelot/Configuration/Creator/ReRouteKeyCreator.cs index 4c7d276d..44be1afa 100644 --- a/src/Ocelot/Configuration/Creator/ReRouteKeyCreator.cs +++ b/src/Ocelot/Configuration/Creator/ReRouteKeyCreator.cs @@ -1,6 +1,6 @@ -using System.Linq; using Ocelot.Configuration.File; using Ocelot.LoadBalancer.LoadBalancers; +using System.Linq; namespace Ocelot.Configuration.Creator { @@ -12,14 +12,14 @@ namespace Ocelot.Configuration.Creator { return $"{nameof(CookieStickySessions)}:{fileReRoute.LoadBalancerOptions.Key}"; } - + return $"{fileReRoute.UpstreamPathTemplate}|{string.Join(",", fileReRoute.UpstreamHttpMethod)}|{string.Join(",", fileReRoute.DownstreamHostAndPorts.Select(x => $"{x.Host}:{x.Port}"))}"; } private bool IsStickySession(FileReRoute fileReRoute) { - if (!string.IsNullOrEmpty(fileReRoute.LoadBalancerOptions.Type) - && !string.IsNullOrEmpty(fileReRoute.LoadBalancerOptions.Key) + if (!string.IsNullOrEmpty(fileReRoute.LoadBalancerOptions.Type) + && !string.IsNullOrEmpty(fileReRoute.LoadBalancerOptions.Key) && fileReRoute.LoadBalancerOptions.Type == nameof(CookieStickySessions)) { return true; diff --git a/src/Ocelot/Configuration/Creator/ReRouteOptionsCreator.cs b/src/Ocelot/Configuration/Creator/ReRouteOptionsCreator.cs index 1eb4e372..ce710c8e 100644 --- a/src/Ocelot/Configuration/Creator/ReRouteOptionsCreator.cs +++ b/src/Ocelot/Configuration/Creator/ReRouteOptionsCreator.cs @@ -20,7 +20,7 @@ namespace Ocelot.Configuration.Creator .WithRateLimiting(enableRateLimiting) .WithUseServiceDiscovery(useServiceDiscovery) .Build(); - + return options; } diff --git a/src/Ocelot/Configuration/Creator/ReRoutesCreator.cs b/src/Ocelot/Configuration/Creator/ReRoutesCreator.cs index d2ec6619..c6171521 100644 --- a/src/Ocelot/Configuration/Creator/ReRoutesCreator.cs +++ b/src/Ocelot/Configuration/Creator/ReRoutesCreator.cs @@ -1,10 +1,10 @@ namespace Ocelot.Configuration.Creator { + using Builder; + using Cache; + using File; using System.Collections.Generic; using System.Linq; - using Cache; - using Builder; - using File; public class ReRoutesCreator : IReRoutesCreator { diff --git a/src/Ocelot/Configuration/Creator/RequestIdKeyCreator.cs b/src/Ocelot/Configuration/Creator/RequestIdKeyCreator.cs index 6fad9b28..8d4a81fe 100644 --- a/src/Ocelot/Configuration/Creator/RequestIdKeyCreator.cs +++ b/src/Ocelot/Configuration/Creator/RequestIdKeyCreator.cs @@ -6,13 +6,13 @@ namespace Ocelot.Configuration.Creator { public string Create(FileReRoute fileReRoute, FileGlobalConfiguration globalConfiguration) { - var reRouteId = !string.IsNullOrEmpty(fileReRoute.RequestIdKey); - - var requestIdKey = reRouteId - ? fileReRoute.RequestIdKey - : globalConfiguration.RequestIdKey; - - return requestIdKey; + var reRouteId = !string.IsNullOrEmpty(fileReRoute.RequestIdKey); + + var requestIdKey = reRouteId + ? fileReRoute.RequestIdKey + : globalConfiguration.RequestIdKey; + + return requestIdKey; } } -} \ No newline at end of file +} diff --git a/src/Ocelot/Configuration/Creator/SecurityOptionsCreator.cs b/src/Ocelot/Configuration/Creator/SecurityOptionsCreator.cs index d1ee3508..cc538510 100644 --- a/src/Ocelot/Configuration/Creator/SecurityOptionsCreator.cs +++ b/src/Ocelot/Configuration/Creator/SecurityOptionsCreator.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Ocelot.Configuration.File; +using Ocelot.Configuration.File; namespace Ocelot.Configuration.Creator { diff --git a/src/Ocelot/Configuration/Creator/ServiceProviderConfigurationCreator.cs b/src/Ocelot/Configuration/Creator/ServiceProviderConfigurationCreator.cs index 3b0ee225..aa631f87 100644 --- a/src/Ocelot/Configuration/Creator/ServiceProviderConfigurationCreator.cs +++ b/src/Ocelot/Configuration/Creator/ServiceProviderConfigurationCreator.cs @@ -9,8 +9,8 @@ namespace Ocelot.Configuration.Creator { var port = globalConfiguration?.ServiceDiscoveryProvider?.Port ?? 0; var host = globalConfiguration?.ServiceDiscoveryProvider?.Host ?? "localhost"; - var type = !string.IsNullOrEmpty(globalConfiguration?.ServiceDiscoveryProvider?.Type) - ? globalConfiguration?.ServiceDiscoveryProvider?.Type + var type = !string.IsNullOrEmpty(globalConfiguration?.ServiceDiscoveryProvider?.Type) + ? globalConfiguration?.ServiceDiscoveryProvider?.Type : "consul"; var pollingInterval = globalConfiguration?.ServiceDiscoveryProvider?.PollingInterval ?? 0; var k8snamespace = globalConfiguration?.ServiceDiscoveryProvider?.Namespace ?? string.Empty; diff --git a/src/Ocelot/Configuration/Creator/UpstreamTemplatePatternCreator.cs b/src/Ocelot/Configuration/Creator/UpstreamTemplatePatternCreator.cs index b5acc10f..7de660b7 100644 --- a/src/Ocelot/Configuration/Creator/UpstreamTemplatePatternCreator.cs +++ b/src/Ocelot/Configuration/Creator/UpstreamTemplatePatternCreator.cs @@ -1,6 +1,6 @@ -using System.Collections.Generic; using Ocelot.Configuration.File; using Ocelot.Values; +using System.Collections.Generic; namespace Ocelot.Configuration.Creator { @@ -29,7 +29,7 @@ namespace Ocelot.Configuration.Creator placeholders.Add(placeHolderName); //hack to handle /{url} case - if(ForwardSlashAndOnePlaceHolder(upstreamTemplate, placeholders, postitionOfPlaceHolderClosingBracket)) + if (ForwardSlashAndOnePlaceHolder(upstreamTemplate, placeholders, postitionOfPlaceHolderClosingBracket)) { return new UpstreamPathTemplate(RegExForwardSlashAndOnePlaceHolder, 0, false, reRoute.UpstreamPathTemplate); } @@ -48,11 +48,11 @@ namespace Ocelot.Configuration.Creator { var indexOfPlaceholder = upstreamTemplate.IndexOf(placeholders[i]); var indexOfNextForwardSlash = upstreamTemplate.IndexOf("/", indexOfPlaceholder); - if(indexOfNextForwardSlash < indexOfPlaceholder || (containsQueryString && upstreamTemplate.IndexOf("?") < upstreamTemplate.IndexOf(placeholders[i]))) + if (indexOfNextForwardSlash < indexOfPlaceholder || (containsQueryString && upstreamTemplate.IndexOf("?") < upstreamTemplate.IndexOf(placeholders[i]))) { upstreamTemplate = upstreamTemplate.Replace(placeholders[i], RegExMatchOneOrMoreOfEverything); - } - else + } + else { upstreamTemplate = upstreamTemplate.Replace(placeholders[i], RegExMatchOneOrMoreOfEverythingUntilNextForwardSlash); } @@ -63,13 +63,13 @@ namespace Ocelot.Configuration.Creator return new UpstreamPathTemplate(RegExForwardSlashOnly, reRoute.Priority, containsQueryString, reRoute.UpstreamPathTemplate); } - if(upstreamTemplate.EndsWith("/")) + if (upstreamTemplate.EndsWith("/")) { - upstreamTemplate = upstreamTemplate.Remove(upstreamTemplate.Length -1, 1) + "(/|)"; + upstreamTemplate = upstreamTemplate.Remove(upstreamTemplate.Length - 1, 1) + "(/|)"; } - var route = reRoute.ReRouteIsCaseSensitive - ? $"^{upstreamTemplate}{RegExMatchEndString}" + var route = reRoute.ReRouteIsCaseSensitive + ? $"^{upstreamTemplate}{RegExMatchEndString}" : $"^{RegExIgnoreCase}{upstreamTemplate}{RegExMatchEndString}"; return new UpstreamPathTemplate(route, reRoute.Priority, containsQueryString, reRoute.UpstreamPathTemplate); @@ -77,8 +77,8 @@ namespace Ocelot.Configuration.Creator private bool ForwardSlashAndOnePlaceHolder(string upstreamTemplate, List placeholders, int postitionOfPlaceHolderClosingBracket) { - if(upstreamTemplate.Substring(0, 2) == "/{" && placeholders.Count == 1 && upstreamTemplate.Length == postitionOfPlaceHolderClosingBracket + 1) - { + if (upstreamTemplate.Substring(0, 2) == "/{" && placeholders.Count == 1 && upstreamTemplate.Length == postitionOfPlaceHolderClosingBracket + 1) + { return true; } diff --git a/src/Ocelot/Configuration/DownstreamHostAndPort.cs b/src/Ocelot/Configuration/DownstreamHostAndPort.cs index 186cce2f..672a8b9c 100644 --- a/src/Ocelot/Configuration/DownstreamHostAndPort.cs +++ b/src/Ocelot/Configuration/DownstreamHostAndPort.cs @@ -11,4 +11,4 @@ public string Host { get; private set; } public int Port { get; private set; } } -} +} diff --git a/src/Ocelot/Configuration/DownstreamReRoute.cs b/src/Ocelot/Configuration/DownstreamReRoute.cs index b8ec926c..b332b622 100644 --- a/src/Ocelot/Configuration/DownstreamReRoute.cs +++ b/src/Ocelot/Configuration/DownstreamReRoute.cs @@ -1,7 +1,7 @@ namespace Ocelot.Configuration { - using System.Collections.Generic; using Creator; + using System.Collections.Generic; using Values; public class DownstreamReRoute diff --git a/src/Ocelot/Configuration/File/AggregateReRouteConfig.cs b/src/Ocelot/Configuration/File/AggregateReRouteConfig.cs index 8a155c1b..6519d6b5 100644 --- a/src/Ocelot/Configuration/File/AggregateReRouteConfig.cs +++ b/src/Ocelot/Configuration/File/AggregateReRouteConfig.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Ocelot.Configuration.File +namespace Ocelot.Configuration.File { public class AggregateReRouteConfig { diff --git a/src/Ocelot/Configuration/File/FileAggregateReRoute.cs b/src/Ocelot/Configuration/File/FileAggregateReRoute.cs index 5c3b551c..2f1b4676 100644 --- a/src/Ocelot/Configuration/File/FileAggregateReRoute.cs +++ b/src/Ocelot/Configuration/File/FileAggregateReRoute.cs @@ -4,19 +4,19 @@ namespace Ocelot.Configuration.File { public class FileAggregateReRoute : IReRoute { - public List ReRouteKeys { get;set; } - public List ReRouteKeysConfig { get;set; } - public string UpstreamPathTemplate { get;set; } + public List ReRouteKeys { get; set; } + public List ReRouteKeysConfig { get; set; } + public string UpstreamPathTemplate { get; set; } public string UpstreamHost { get; set; } public bool ReRouteIsCaseSensitive { get; set; } public string Aggregator { get; set; } // Only supports GET..are you crazy!! POST, PUT WOULD BE CRAZY!! :) - public List UpstreamHttpMethod - { - get { return new List {"Get"}; } + public List UpstreamHttpMethod + { + get { return new List { "Get" }; } } - public int Priority {get;set;} = 1; - } + public int Priority { get; set; } = 1; + } } diff --git a/src/Ocelot/Configuration/File/FileAuthenticationOptions.cs b/src/Ocelot/Configuration/File/FileAuthenticationOptions.cs index 873d1b5b..81805df1 100644 --- a/src/Ocelot/Configuration/File/FileAuthenticationOptions.cs +++ b/src/Ocelot/Configuration/File/FileAuthenticationOptions.cs @@ -1,6 +1,6 @@ -using System.Collections.Generic; +using Ocelot.Infrastructure.Extensions; +using System.Collections.Generic; using System.Text; -using Ocelot.Infrastructure.Extensions; namespace Ocelot.Configuration.File { @@ -11,7 +11,7 @@ namespace Ocelot.Configuration.File AllowedScopes = new List(); } - public string AuthenticationProviderKey {get; set;} + public string AuthenticationProviderKey { get; set; } public List AllowedScopes { get; set; } public override string ToString() @@ -23,4 +23,4 @@ namespace Ocelot.Configuration.File return sb.ToString(); } } -} +} diff --git a/src/Ocelot/Configuration/File/FileCacheOptions.cs b/src/Ocelot/Configuration/File/FileCacheOptions.cs index 9bca1f5b..b5168b3c 100644 --- a/src/Ocelot/Configuration/File/FileCacheOptions.cs +++ b/src/Ocelot/Configuration/File/FileCacheOptions.cs @@ -3,6 +3,6 @@ public class FileCacheOptions { public int TtlSeconds { get; set; } - public string Region {get; set;} + public string Region { get; set; } } -} +} diff --git a/src/Ocelot/Configuration/File/FileConfiguration.cs b/src/Ocelot/Configuration/File/FileConfiguration.cs index 49eb0c9e..ecd41a35 100644 --- a/src/Ocelot/Configuration/File/FileConfiguration.cs +++ b/src/Ocelot/Configuration/File/FileConfiguration.cs @@ -14,9 +14,10 @@ namespace Ocelot.Configuration.File public List ReRoutes { get; set; } public List DynamicReRoutes { get; set; } - + // Seperate field for aggregates because this let's you re-use ReRoutes in multiple Aggregates - public List Aggregates { get;set; } + public List Aggregates { get; set; } + public FileGlobalConfiguration GlobalConfiguration { get; set; } } } diff --git a/src/Ocelot/Configuration/File/FileGlobalConfiguration.cs b/src/Ocelot/Configuration/File/FileGlobalConfiguration.cs index a13284ad..9844c15d 100644 --- a/src/Ocelot/Configuration/File/FileGlobalConfiguration.cs +++ b/src/Ocelot/Configuration/File/FileGlobalConfiguration.cs @@ -13,13 +13,13 @@ public string RequestIdKey { get; set; } - public FileServiceDiscoveryProvider ServiceDiscoveryProvider { get;set; } + public FileServiceDiscoveryProvider ServiceDiscoveryProvider { get; set; } public FileRateLimitOptions RateLimitOptions { get; set; } public FileQoSOptions QoSOptions { get; set; } - public string BaseUrl { get ;set; } + public string BaseUrl { get; set; } public FileLoadBalancerOptions LoadBalancerOptions { get; set; } diff --git a/src/Ocelot/Configuration/File/FileHostAndPort.cs b/src/Ocelot/Configuration/File/FileHostAndPort.cs index 67191873..23c745e0 100644 --- a/src/Ocelot/Configuration/File/FileHostAndPort.cs +++ b/src/Ocelot/Configuration/File/FileHostAndPort.cs @@ -2,7 +2,7 @@ namespace Ocelot.Configuration.File { public class FileHostAndPort { - public string Host {get;set;} + public string Host { get; set; } public int Port { get; set; } } -} +} diff --git a/src/Ocelot/Configuration/File/FileHttpHandlerOptions.cs b/src/Ocelot/Configuration/File/FileHttpHandlerOptions.cs index e10e7345..d765af58 100644 --- a/src/Ocelot/Configuration/File/FileHttpHandlerOptions.cs +++ b/src/Ocelot/Configuration/File/FileHttpHandlerOptions.cs @@ -17,4 +17,4 @@ public bool UseProxy { get; set; } } -} +} diff --git a/src/Ocelot/Configuration/File/FileLoadBalancerOptions.cs b/src/Ocelot/Configuration/File/FileLoadBalancerOptions.cs index 29acb5f6..105ccc7a 100644 --- a/src/Ocelot/Configuration/File/FileLoadBalancerOptions.cs +++ b/src/Ocelot/Configuration/File/FileLoadBalancerOptions.cs @@ -4,6 +4,6 @@ namespace Ocelot.Configuration.File { public string Type { get; set; } public string Key { get; set; } - public int Expiry { get; set; } + public int Expiry { get; set; } } } diff --git a/src/Ocelot/Configuration/File/FileQoSOptions.cs b/src/Ocelot/Configuration/File/FileQoSOptions.cs index aa842ced..4e12b4a3 100644 --- a/src/Ocelot/Configuration/File/FileQoSOptions.cs +++ b/src/Ocelot/Configuration/File/FileQoSOptions.cs @@ -8,4 +8,4 @@ public int TimeoutValue { get; set; } } -} +} diff --git a/src/Ocelot/Configuration/File/FileRateLimitOptions.cs b/src/Ocelot/Configuration/File/FileRateLimitOptions.cs index 05c6fac4..51be9ed0 100644 --- a/src/Ocelot/Configuration/File/FileRateLimitOptions.cs +++ b/src/Ocelot/Configuration/File/FileRateLimitOptions.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Ocelot.Configuration.File +namespace Ocelot.Configuration.File { public class FileRateLimitOptions { @@ -14,7 +9,7 @@ namespace Ocelot.Configuration.File /// /// Gets or sets a value that will be used as a formatter for the QuotaExceeded response message. - /// If none specified the default will be: + /// If none specified the default will be: /// API calls quota exceeded! maximum admitted {0} per {1} /// public string QuotaExceededMessage { get; set; } @@ -32,6 +27,6 @@ namespace Ocelot.Configuration.File /// /// Gets or sets the HTTP Status code returned when rate limiting occurs, by default value is set to 429 (Too Many Requests) /// - public int HttpStatusCode { get; set; } = 429; + public int HttpStatusCode { get; set; } = 429; } } diff --git a/src/Ocelot/Configuration/File/FileRateLimitRule.cs b/src/Ocelot/Configuration/File/FileRateLimitRule.cs index 2714be4d..575ad190 100644 --- a/src/Ocelot/Configuration/File/FileRateLimitRule.cs +++ b/src/Ocelot/Configuration/File/FileRateLimitRule.cs @@ -1,9 +1,6 @@ -using System; +using Ocelot.Infrastructure.Extensions; using System.Collections.Generic; -using System.Linq; using System.Text; -using System.Threading.Tasks; -using Ocelot.Infrastructure.Extensions; namespace Ocelot.Configuration.File { diff --git a/src/Ocelot/Configuration/File/FileReRoute.cs b/src/Ocelot/Configuration/File/FileReRoute.cs index 1a8f2a1a..c87bf435 100644 --- a/src/Ocelot/Configuration/File/FileReRoute.cs +++ b/src/Ocelot/Configuration/File/FileReRoute.cs @@ -38,17 +38,17 @@ namespace Ocelot.Configuration.File public FileCacheOptions FileCacheOptions { get; set; } public bool ReRouteIsCaseSensitive { get; set; } public string ServiceName { get; set; } - public string DownstreamScheme {get;set;} + public string DownstreamScheme { get; set; } public FileQoSOptions QoSOptions { get; set; } public FileLoadBalancerOptions LoadBalancerOptions { get; set; } public FileRateLimitRule RateLimitOptions { get; set; } public FileAuthenticationOptions AuthenticationOptions { get; set; } public FileHttpHandlerOptions HttpHandlerOptions { get; set; } - public List DownstreamHostAndPorts {get;set;} + public List DownstreamHostAndPorts { get; set; } public string UpstreamHost { get; set; } - public string Key { get;set; } - public List DelegatingHandlers {get;set;} - public int Priority { get;set; } + public string Key { get; set; } + public List DelegatingHandlers { get; set; } + public int Priority { get; set; } public int Timeout { get; set; } public bool DangerousAcceptAnyServerCertificateValidator { get; set; } public FileSecurityOptions SecurityOptions { get; set; } diff --git a/src/Ocelot/Configuration/File/FileSecurityOptions.cs b/src/Ocelot/Configuration/File/FileSecurityOptions.cs index 1f383a5b..c3687d48 100644 --- a/src/Ocelot/Configuration/File/FileSecurityOptions.cs +++ b/src/Ocelot/Configuration/File/FileSecurityOptions.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Generic; namespace Ocelot.Configuration.File { @@ -12,7 +10,7 @@ namespace Ocelot.Configuration.File IPBlockedList = new List(); } - public List IPAllowedList { get; set; } + public List IPAllowedList { get; set; } public List IPBlockedList { get; set; } } diff --git a/src/Ocelot/Configuration/File/FileServiceDiscoveryProvider.cs b/src/Ocelot/Configuration/File/FileServiceDiscoveryProvider.cs index 153145bd..c41f1e24 100644 --- a/src/Ocelot/Configuration/File/FileServiceDiscoveryProvider.cs +++ b/src/Ocelot/Configuration/File/FileServiceDiscoveryProvider.cs @@ -2,7 +2,7 @@ namespace Ocelot.Configuration.File { public class FileServiceDiscoveryProvider { - public string Host {get;set;} + public string Host { get; set; } public int Port { get; set; } public string Type { get; set; } public string Token { get; set; } diff --git a/src/Ocelot/Configuration/File/IReRoute.cs b/src/Ocelot/Configuration/File/IReRoute.cs index fb7e9313..b5191428 100644 --- a/src/Ocelot/Configuration/File/IReRoute.cs +++ b/src/Ocelot/Configuration/File/IReRoute.cs @@ -4,6 +4,6 @@ { string UpstreamPathTemplate { get; set; } bool ReRouteIsCaseSensitive { get; set; } - int Priority {get;set;} + int Priority { get; set; } } } diff --git a/src/Ocelot/Configuration/FileConfigurationController.cs b/src/Ocelot/Configuration/FileConfigurationController.cs index 91777ef3..2f6a51af 100644 --- a/src/Ocelot/Configuration/FileConfigurationController.cs +++ b/src/Ocelot/Configuration/FileConfigurationController.cs @@ -1,9 +1,9 @@ -using System; -using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Ocelot.Configuration.File; using Ocelot.Configuration.Setter; +using System; +using System.Threading.Tasks; namespace Ocelot.Configuration { @@ -29,7 +29,7 @@ namespace Ocelot.Configuration { var response = await _repo.Get(); - if(response.IsError) + if (response.IsError) { return new BadRequestObjectResult(response.Errors); } @@ -51,7 +51,7 @@ namespace Ocelot.Configuration return new OkObjectResult(fileConfiguration); } - catch(Exception e) + catch (Exception e) { return new BadRequestObjectResult($"{e.Message}:{e.StackTrace}"); } diff --git a/src/Ocelot/Configuration/HeaderFindAndReplace.cs b/src/Ocelot/Configuration/HeaderFindAndReplace.cs index 6b1636c2..73966cf1 100644 --- a/src/Ocelot/Configuration/HeaderFindAndReplace.cs +++ b/src/Ocelot/Configuration/HeaderFindAndReplace.cs @@ -10,11 +10,11 @@ namespace Ocelot.Configuration Index = index; } - public string Key {get;} - public string Find {get;} - public string Replace {get;} - - // only index 0 for now.. - public int Index {get;} + public string Key { get; } + public string Find { get; } + public string Replace { get; } + + // only index 0 for now.. + public int Index { get; } } -} \ No newline at end of file +} diff --git a/src/Ocelot/Configuration/HttpHandlerOptions.cs b/src/Ocelot/Configuration/HttpHandlerOptions.cs index c8f88aa5..b551287f 100644 --- a/src/Ocelot/Configuration/HttpHandlerOptions.cs +++ b/src/Ocelot/Configuration/HttpHandlerOptions.cs @@ -1,7 +1,7 @@ namespace Ocelot.Configuration { /// - /// Describes configuration parameters for http handler, + /// Describes configuration parameters for http handler, /// that is created to handle a request to service /// public class HttpHandlerOptions @@ -34,4 +34,4 @@ /// public bool UseProxy { get; private set; } } -} +} diff --git a/src/Ocelot/Configuration/IInternalConfiguration.cs b/src/Ocelot/Configuration/IInternalConfiguration.cs index 253f7ffc..1780da33 100644 --- a/src/Ocelot/Configuration/IInternalConfiguration.cs +++ b/src/Ocelot/Configuration/IInternalConfiguration.cs @@ -6,11 +6,11 @@ namespace Ocelot.Configuration { List ReRoutes { get; } - string AdministrationPath {get;} + string AdministrationPath { get; } - ServiceProviderConfiguration ServiceProviderConfiguration {get;} + ServiceProviderConfiguration ServiceProviderConfiguration { get; } - string RequestId {get;} + string RequestId { get; } LoadBalancerOptions LoadBalancerOptions { get; } diff --git a/src/Ocelot/Configuration/InternalConfiguration.cs b/src/Ocelot/Configuration/InternalConfiguration.cs index cd939a86..7b7649e4 100644 --- a/src/Ocelot/Configuration/InternalConfiguration.cs +++ b/src/Ocelot/Configuration/InternalConfiguration.cs @@ -5,13 +5,13 @@ namespace Ocelot.Configuration public class InternalConfiguration : IInternalConfiguration { public InternalConfiguration( - List reRoutes, - string administrationPath, - ServiceProviderConfiguration serviceProviderConfiguration, - string requestId, - LoadBalancerOptions loadBalancerOptions, - string downstreamScheme, - QoSOptions qoSOptions, + List reRoutes, + string administrationPath, + ServiceProviderConfiguration serviceProviderConfiguration, + string requestId, + LoadBalancerOptions loadBalancerOptions, + string downstreamScheme, + QoSOptions qoSOptions, HttpHandlerOptions httpHandlerOptions) { ReRoutes = reRoutes; @@ -25,9 +25,9 @@ namespace Ocelot.Configuration } public List ReRoutes { get; } - public string AdministrationPath {get;} - public ServiceProviderConfiguration ServiceProviderConfiguration {get;} - public string RequestId {get;} + public string AdministrationPath { get; } + public ServiceProviderConfiguration ServiceProviderConfiguration { get; } + public string RequestId { get; } public LoadBalancerOptions LoadBalancerOptions { get; } public string DownstreamScheme { get; } public QoSOptions QoSOptions { get; } diff --git a/src/Ocelot/Configuration/Parser/ClaimToThingConfigurationParser.cs b/src/Ocelot/Configuration/Parser/ClaimToThingConfigurationParser.cs index 94df168f..76614f96 100644 --- a/src/Ocelot/Configuration/Parser/ClaimToThingConfigurationParser.cs +++ b/src/Ocelot/Configuration/Parser/ClaimToThingConfigurationParser.cs @@ -1,8 +1,6 @@ -using System; -using System.Collections.Generic; +using Ocelot.Responses; +using System; using System.Text.RegularExpressions; -using Ocelot.Errors; -using Ocelot.Responses; namespace Ocelot.Configuration.Parser { @@ -58,4 +56,4 @@ namespace Ocelot.Configuration.Parser return claimKey; } } -} +} diff --git a/src/Ocelot/Configuration/Parser/InstructionNotForClaimsError.cs b/src/Ocelot/Configuration/Parser/InstructionNotForClaimsError.cs index 50dd8820..24535653 100644 --- a/src/Ocelot/Configuration/Parser/InstructionNotForClaimsError.cs +++ b/src/Ocelot/Configuration/Parser/InstructionNotForClaimsError.cs @@ -4,9 +4,9 @@ namespace Ocelot.Configuration.Parser { public class InstructionNotForClaimsError : Error { - public InstructionNotForClaimsError() + public InstructionNotForClaimsError() : base("instructions did not contain claims, at the moment we only support claims extraction", OcelotErrorCode.InstructionNotForClaimsError) { } } -} +} diff --git a/src/Ocelot/Configuration/Parser/NoInstructionsError.cs b/src/Ocelot/Configuration/Parser/NoInstructionsError.cs index 8c7eafc7..67bcd3e1 100644 --- a/src/Ocelot/Configuration/Parser/NoInstructionsError.cs +++ b/src/Ocelot/Configuration/Parser/NoInstructionsError.cs @@ -4,9 +4,9 @@ namespace Ocelot.Configuration.Parser { public class NoInstructionsError : Error { - public NoInstructionsError(string splitToken) + public NoInstructionsError(string splitToken) : base($"There we no instructions splitting on {splitToken}", OcelotErrorCode.NoInstructionsError) { } } -} +} diff --git a/src/Ocelot/Configuration/Parser/ParsingConfigurationHeaderError.cs b/src/Ocelot/Configuration/Parser/ParsingConfigurationHeaderError.cs index 1f3eb627..fba6a6db 100644 --- a/src/Ocelot/Configuration/Parser/ParsingConfigurationHeaderError.cs +++ b/src/Ocelot/Configuration/Parser/ParsingConfigurationHeaderError.cs @@ -1,13 +1,13 @@ -using System; -using Ocelot.Errors; +using Ocelot.Errors; +using System; namespace Ocelot.Configuration.Parser { public class ParsingConfigurationHeaderError : Error { - public ParsingConfigurationHeaderError(Exception exception) + public ParsingConfigurationHeaderError(Exception exception) : base($"error parsing configuration eception is {exception.Message}", OcelotErrorCode.ParsingConfigurationHeaderError) { } } -} +} diff --git a/src/Ocelot/Configuration/QoSOptions.cs b/src/Ocelot/Configuration/QoSOptions.cs index 83309c27..461ff292 100644 --- a/src/Ocelot/Configuration/QoSOptions.cs +++ b/src/Ocelot/Configuration/QoSOptions.cs @@ -3,9 +3,9 @@ public class QoSOptions { public QoSOptions( - int exceptionsAllowedBeforeBreaking, - int durationofBreak, - int timeoutValue, + int exceptionsAllowedBeforeBreaking, + int durationofBreak, + int timeoutValue, string key, string timeoutStrategy = "Pessimistic") { @@ -14,7 +14,7 @@ TimeoutValue = timeoutValue; TimeoutStrategy = timeoutStrategy; Key = key; - } + } public int ExceptionsAllowedBeforeBreaking { get; } diff --git a/src/Ocelot/Configuration/RateLimitOptions.cs b/src/Ocelot/Configuration/RateLimitOptions.cs index 722af4cd..db1da8eb 100644 --- a/src/Ocelot/Configuration/RateLimitOptions.cs +++ b/src/Ocelot/Configuration/RateLimitOptions.cs @@ -1,6 +1,4 @@ using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace Ocelot.Configuration { @@ -9,12 +7,12 @@ namespace Ocelot.Configuration /// public class RateLimitOptions { - public RateLimitOptions(bool enbleRateLimiting, string clientIdHeader, List clientWhitelist,bool disableRateLimitHeaders, + public RateLimitOptions(bool enbleRateLimiting, string clientIdHeader, List clientWhitelist, bool disableRateLimitHeaders, string quotaExceededMessage, string rateLimitCounterPrefix, RateLimitRule rateLimitRule, int httpStatusCode) { EnableRateLimiting = enbleRateLimiting; ClientIdHeader = clientIdHeader; - ClientWhitelist = clientWhitelist?? new List(); + ClientWhitelist = clientWhitelist ?? new List(); DisableRateLimitHeaders = disableRateLimitHeaders; QuotaExceededMessage = quotaExceededMessage; RateLimitCounterPrefix = rateLimitCounterPrefix; @@ -22,23 +20,23 @@ namespace Ocelot.Configuration HttpStatusCode = httpStatusCode; } - public RateLimitRule RateLimitRule { get; private set; } + public RateLimitRule RateLimitRule { get; private set; } public List ClientWhitelist { get; private set; } /// /// Gets or sets the HTTP header that holds the client identifier, by default is X-ClientId /// - public string ClientIdHeader { get; private set; } - + public string ClientIdHeader { get; private set; } + /// /// Gets or sets the HTTP Status code returned when rate limiting occurs, by default value is set to 429 (Too Many Requests) /// - public int HttpStatusCode { get; private set; } - + public int HttpStatusCode { get; private set; } + /// /// Gets or sets a value that will be used as a formatter for the QuotaExceeded response message. - /// If none specified the default will be: + /// If none specified the default will be: /// API calls quota exceeded! maximum admitted {0} per {1} /// public string QuotaExceededMessage { get; private set; } @@ -46,8 +44,8 @@ namespace Ocelot.Configuration /// /// Gets or sets the counter prefix, used to compose the rate limit counter cache key /// - public string RateLimitCounterPrefix { get; private set; } - + public string RateLimitCounterPrefix { get; private set; } + /// /// Enables endpoint rate limiting based URL path and HTTP verb /// @@ -58,4 +56,4 @@ namespace Ocelot.Configuration /// public bool DisableRateLimitHeaders { get; private set; } } -} +} diff --git a/src/Ocelot/Configuration/RateLimitRule.cs b/src/Ocelot/Configuration/RateLimitRule.cs index 9240087c..b3393ae5 100644 --- a/src/Ocelot/Configuration/RateLimitRule.cs +++ b/src/Ocelot/Configuration/RateLimitRule.cs @@ -1,6 +1,4 @@ -using System; - -namespace Ocelot.Configuration +namespace Ocelot.Configuration { public class RateLimitRule { @@ -16,11 +14,11 @@ namespace Ocelot.Configuration /// public string Period { get; private set; } - public double PeriodTimespan { get; private set; } - + public double PeriodTimespan { get; private set; } + /// /// Maximum number of requests that a client can make in a defined period /// public long Limit { get; private set; } } -} +} diff --git a/src/Ocelot/Configuration/ReRoute.cs b/src/Ocelot/Configuration/ReRoute.cs index 31392770..e7efe12b 100644 --- a/src/Ocelot/Configuration/ReRoute.cs +++ b/src/Ocelot/Configuration/ReRoute.cs @@ -1,16 +1,16 @@ namespace Ocelot.Configuration { - using System.Collections.Generic; - using System.Net.Http; using Ocelot.Configuration.File; using Ocelot.Values; + using System.Collections.Generic; + using System.Net.Http; public class ReRoute { public ReRoute(List downstreamReRoute, List downstreamReRouteConfig, - List upstreamHttpMethod, - UpstreamPathTemplate upstreamTemplatePattern, + List upstreamHttpMethod, + UpstreamPathTemplate upstreamTemplatePattern, string upstreamHost, string aggregator) { @@ -27,6 +27,6 @@ public string UpstreamHost { get; private set; } public List DownstreamReRoute { get; private set; } public List DownstreamReRouteConfig { get; private set; } - public string Aggregator {get; private set;} + public string Aggregator { get; private set; } } -} +} diff --git a/src/Ocelot/Configuration/Repository/ConsulFileConfigurationPollerOption.cs b/src/Ocelot/Configuration/Repository/ConsulFileConfigurationPollerOption.cs index 8ea624f6..a324a3fb 100644 --- a/src/Ocelot/Configuration/Repository/ConsulFileConfigurationPollerOption.cs +++ b/src/Ocelot/Configuration/Repository/ConsulFileConfigurationPollerOption.cs @@ -1,33 +1,40 @@ -using System.Threading.Tasks; -using Ocelot.Responses; +using Ocelot.Responses; +using System.Threading.Tasks; -namespace Ocelot.Configuration.Repository { - public class ConsulFileConfigurationPollerOption : IFileConfigurationPollerOptions { +namespace Ocelot.Configuration.Repository +{ + public class ConsulFileConfigurationPollerOption : IFileConfigurationPollerOptions + { private readonly IInternalConfigurationRepository _internalConfigRepo; private readonly IFileConfigurationRepository _fileConfigurationRepository; public ConsulFileConfigurationPollerOption(IInternalConfigurationRepository internalConfigurationRepository, - IFileConfigurationRepository fileConfigurationRepository) { + IFileConfigurationRepository fileConfigurationRepository) + { _internalConfigRepo = internalConfigurationRepository; _fileConfigurationRepository = fileConfigurationRepository; } public int Delay => GetDelay(); - private int GetDelay() { + private int GetDelay() + { int delay = 1000; Response fileConfig = Task.Run(async () => await _fileConfigurationRepository.Get()).Result; if (fileConfig?.Data?.GlobalConfiguration?.ServiceDiscoveryProvider != null && !fileConfig.IsError && - fileConfig.Data.GlobalConfiguration.ServiceDiscoveryProvider.PollingInterval > 0) { + fileConfig.Data.GlobalConfiguration.ServiceDiscoveryProvider.PollingInterval > 0) + { delay = fileConfig.Data.GlobalConfiguration.ServiceDiscoveryProvider.PollingInterval; } - else { + else + { Response internalConfig = _internalConfigRepo.Get(); if (internalConfig?.Data?.ServiceProviderConfiguration != null && !internalConfig.IsError && - internalConfig.Data.ServiceProviderConfiguration.PollingInterval > 0) { + internalConfig.Data.ServiceProviderConfiguration.PollingInterval > 0) + { delay = internalConfig.Data.ServiceProviderConfiguration.PollingInterval; } } diff --git a/src/Ocelot/Configuration/Repository/DiskFileConfigurationRepository.cs b/src/Ocelot/Configuration/Repository/DiskFileConfigurationRepository.cs index 0141abd7..8df82935 100644 --- a/src/Ocelot/Configuration/Repository/DiskFileConfigurationRepository.cs +++ b/src/Ocelot/Configuration/Repository/DiskFileConfigurationRepository.cs @@ -1,9 +1,9 @@ -using System; -using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; using Newtonsoft.Json; using Ocelot.Configuration.File; using Ocelot.Responses; +using System; +using System.Threading.Tasks; namespace Ocelot.Configuration.Repository { @@ -25,7 +25,7 @@ namespace Ocelot.Configuration.Repository { string jsonConfiguration; - lock(_lock) + lock (_lock) { jsonConfiguration = System.IO.File.ReadAllText(_environmentFilePath); } @@ -39,7 +39,7 @@ namespace Ocelot.Configuration.Repository { string jsonConfiguration = JsonConvert.SerializeObject(fileConfiguration, Formatting.Indented); - lock(_lock) + lock (_lock) { if (System.IO.File.Exists(_environmentFilePath)) { diff --git a/src/Ocelot/Configuration/Repository/FileConfigurationPoller.cs b/src/Ocelot/Configuration/Repository/FileConfigurationPoller.cs index 84fc7918..cca50d0b 100644 --- a/src/Ocelot/Configuration/Repository/FileConfigurationPoller.cs +++ b/src/Ocelot/Configuration/Repository/FileConfigurationPoller.cs @@ -1,19 +1,18 @@ -using System; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; using Microsoft.Extensions.Hosting; using Newtonsoft.Json; using Ocelot.Configuration.Creator; using Ocelot.Configuration.File; -using Ocelot.Configuration.Setter; using Ocelot.Logging; +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; namespace Ocelot.Configuration.Repository { public class FileConfigurationPoller : IHostedService, IDisposable { - private readonly IOcelotLogger _logger; + private readonly IOcelotLogger _logger; private readonly IFileConfigurationRepository _repo; private string _previousAsJson; private Timer _timer; @@ -23,8 +22,8 @@ namespace Ocelot.Configuration.Repository private readonly IInternalConfigurationCreator _internalConfigCreator; public FileConfigurationPoller( - IOcelotLoggerFactory factory, - IFileConfigurationRepository repo, + IOcelotLoggerFactory factory, + IFileConfigurationRepository repo, IFileConfigurationPollerOptions options, IInternalConfigurationRepository internalConfigRepo, IInternalConfigurationCreator internalConfigCreator) @@ -36,18 +35,18 @@ namespace Ocelot.Configuration.Repository _repo = repo; _previousAsJson = ""; } - + public Task StartAsync(CancellationToken cancellationToken) { _logger.LogInformation($"{nameof(FileConfigurationPoller)} is starting."); _timer = new Timer(async x => { - if(_polling) + if (_polling) { return; } - + _polling = true; await Poll(); _polling = false; @@ -62,7 +61,7 @@ namespace Ocelot.Configuration.Repository _timer?.Change(Timeout.Infinite, 0); - return Task.CompletedTask; + return Task.CompletedTask; } private async Task Poll() @@ -71,7 +70,7 @@ namespace Ocelot.Configuration.Repository var fileConfig = await _repo.Get(); - if(fileConfig.IsError) + if (fileConfig.IsError) { _logger.LogWarning($"error geting file config, errors are {string.Join(",", fileConfig.Errors.Select(x => x.Message))}"); return; @@ -79,11 +78,11 @@ namespace Ocelot.Configuration.Repository var asJson = ToJson(fileConfig.Data); - if(!fileConfig.IsError && asJson != _previousAsJson) + if (!fileConfig.IsError && asJson != _previousAsJson) { var config = await _internalConfigCreator.Create(fileConfig.Data); - if(!config.IsError) + if (!config.IsError) { _internalConfigRepo.AddOrReplace(config.Data); } diff --git a/src/Ocelot/Configuration/Repository/IFileConfigurationRepository.cs b/src/Ocelot/Configuration/Repository/IFileConfigurationRepository.cs index 2fe8140a..55ad6ce7 100644 --- a/src/Ocelot/Configuration/Repository/IFileConfigurationRepository.cs +++ b/src/Ocelot/Configuration/Repository/IFileConfigurationRepository.cs @@ -1,12 +1,13 @@ -using System.Threading.Tasks; using Ocelot.Configuration.File; using Ocelot.Responses; +using System.Threading.Tasks; namespace Ocelot.Configuration.Repository { public interface IFileConfigurationRepository { Task> Get(); + Task Set(FileConfiguration fileConfiguration); } -} \ No newline at end of file +} diff --git a/src/Ocelot/Configuration/Repository/IInternalConfigurationRepository.cs b/src/Ocelot/Configuration/Repository/IInternalConfigurationRepository.cs index 5db4adb5..136bf321 100644 --- a/src/Ocelot/Configuration/Repository/IInternalConfigurationRepository.cs +++ b/src/Ocelot/Configuration/Repository/IInternalConfigurationRepository.cs @@ -5,6 +5,7 @@ namespace Ocelot.Configuration.Repository public interface IInternalConfigurationRepository { Response Get(); + Response AddOrReplace(IInternalConfiguration internalConfiguration); } } diff --git a/src/Ocelot/Configuration/SecurityOptions.cs b/src/Ocelot/Configuration/SecurityOptions.cs index 88d4d08a..e4cf4205 100644 --- a/src/Ocelot/Configuration/SecurityOptions.cs +++ b/src/Ocelot/Configuration/SecurityOptions.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Generic; namespace Ocelot.Configuration { diff --git a/src/Ocelot/Configuration/Setter/FileAndInternalConfigurationSetter.cs b/src/Ocelot/Configuration/Setter/FileAndInternalConfigurationSetter.cs index a5549b29..127e20be 100644 --- a/src/Ocelot/Configuration/Setter/FileAndInternalConfigurationSetter.cs +++ b/src/Ocelot/Configuration/Setter/FileAndInternalConfigurationSetter.cs @@ -1,8 +1,8 @@ -using System.Threading.Tasks; using Ocelot.Configuration.Creator; using Ocelot.Configuration.File; using Ocelot.Configuration.Repository; using Ocelot.Responses; +using System.Threading.Tasks; namespace Ocelot.Configuration.Setter { @@ -13,8 +13,8 @@ namespace Ocelot.Configuration.Setter private readonly IFileConfigurationRepository _repo; public FileAndInternalConfigurationSetter( - IInternalConfigurationRepository configRepo, - IInternalConfigurationCreator configCreator, + IInternalConfigurationRepository configRepo, + IInternalConfigurationCreator configCreator, IFileConfigurationRepository repo) { internalConfigRepo = configRepo; @@ -26,14 +26,14 @@ namespace Ocelot.Configuration.Setter { var response = await _repo.Set(fileConfig); - if(response.IsError) + if (response.IsError) { return new ErrorResponse(response.Errors); } var config = await _configCreator.Create(fileConfig); - if(!config.IsError) + if (!config.IsError) { internalConfigRepo.AddOrReplace(config.Data); } diff --git a/src/Ocelot/Configuration/Setter/IFileConfigurationSetter.cs b/src/Ocelot/Configuration/Setter/IFileConfigurationSetter.cs index 28fec505..9e8b4cc7 100644 --- a/src/Ocelot/Configuration/Setter/IFileConfigurationSetter.cs +++ b/src/Ocelot/Configuration/Setter/IFileConfigurationSetter.cs @@ -1,6 +1,6 @@ -using System.Threading.Tasks; using Ocelot.Configuration.File; using Ocelot.Responses; +using System.Threading.Tasks; namespace Ocelot.Configuration.Setter { diff --git a/src/Ocelot/Configuration/Validator/ConfigurationValidationResult.cs b/src/Ocelot/Configuration/Validator/ConfigurationValidationResult.cs index d8add08a..d1c87530 100644 --- a/src/Ocelot/Configuration/Validator/ConfigurationValidationResult.cs +++ b/src/Ocelot/Configuration/Validator/ConfigurationValidationResult.cs @@ -1,7 +1,7 @@ namespace Ocelot.Configuration.Validator { - using System.Collections.Generic; using Ocelot.Errors; + using System.Collections.Generic; public class ConfigurationValidationResult { @@ -19,6 +19,6 @@ public bool IsError { get; } - public List Errors { get; } + public List Errors { get; } } } diff --git a/src/Ocelot/Configuration/Validator/FileConfigurationFluentValidator.cs b/src/Ocelot/Configuration/Validator/FileConfigurationFluentValidator.cs index 728c218f..49e92355 100644 --- a/src/Ocelot/Configuration/Validator/FileConfigurationFluentValidator.cs +++ b/src/Ocelot/Configuration/Validator/FileConfigurationFluentValidator.cs @@ -1,15 +1,15 @@ namespace Ocelot.Configuration.Validator { - using FluentValidation; - using File; using Errors; + using File; + using FluentValidation; + using Microsoft.Extensions.DependencyInjection; using Responses; + using ServiceDiscovery; + using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; - using System; - using Microsoft.Extensions.DependencyInjection; - using ServiceDiscovery; public class FileConfigurationFluentValidator : AbstractValidator, IConfigurationValidator { @@ -73,11 +73,11 @@ private bool HaveServiceDiscoveryProviderRegistered(FileServiceDiscoveryProvider serviceDiscoveryProvider) { - if(serviceDiscoveryProvider == null) + if (serviceDiscoveryProvider == null) { return true; } - + if (serviceDiscoveryProvider?.Type?.ToLower() == "servicefabric") { return true; diff --git a/src/Ocelot/Configuration/Validator/FileGlobalConfigurationFluentValidator.cs b/src/Ocelot/Configuration/Validator/FileGlobalConfigurationFluentValidator.cs index fbad7645..22e1690f 100644 --- a/src/Ocelot/Configuration/Validator/FileGlobalConfigurationFluentValidator.cs +++ b/src/Ocelot/Configuration/Validator/FileGlobalConfigurationFluentValidator.cs @@ -1,7 +1,7 @@ namespace Ocelot.Configuration.Validator { - using FluentValidation; using File; + using FluentValidation; public class FileGlobalConfigurationFluentValidator : AbstractValidator { diff --git a/src/Ocelot/Configuration/Validator/FileQoSOptionsFluentValidator.cs b/src/Ocelot/Configuration/Validator/FileQoSOptionsFluentValidator.cs index 3c0d532b..4a6c8496 100644 --- a/src/Ocelot/Configuration/Validator/FileQoSOptionsFluentValidator.cs +++ b/src/Ocelot/Configuration/Validator/FileQoSOptionsFluentValidator.cs @@ -1,10 +1,10 @@ namespace Ocelot.Configuration.Validator { - using System; - using FluentValidation; using File; + using FluentValidation; using Microsoft.Extensions.DependencyInjection; using Requester; + using System; public class FileQoSOptionsFluentValidator : AbstractValidator { @@ -14,10 +14,11 @@ namespace Ocelot.Configuration.Validator { _qosDelegatingHandlerDelegate = provider.GetService(); - When(qosOptions => qosOptions.TimeoutValue > 0 && qosOptions.ExceptionsAllowedBeforeBreaking > 0, () => { + When(qosOptions => qosOptions.TimeoutValue > 0 && qosOptions.ExceptionsAllowedBeforeBreaking > 0, () => + { RuleFor(qosOptions => qosOptions) .Must(HaveQosHandlerRegistered) - .WithMessage("Unable to start Ocelot because either a ReRoute or GlobalConfiguration are using QoSOptions but no QosDelegatingHandlerDelegate has been registered in dependency injection container. Are you missing a package like Ocelot.Provider.Polly and services.AddPolly()?"); + .WithMessage("Unable to start Ocelot because either a ReRoute or GlobalConfiguration are using QoSOptions but no QosDelegatingHandlerDelegate has been registered in dependency injection container. Are you missing a package like Ocelot.Provider.Polly and services.AddPolly()?"); }); } diff --git a/src/Ocelot/Configuration/Validator/FileValidationFailedError.cs b/src/Ocelot/Configuration/Validator/FileValidationFailedError.cs index 937b896b..a1918341 100644 --- a/src/Ocelot/Configuration/Validator/FileValidationFailedError.cs +++ b/src/Ocelot/Configuration/Validator/FileValidationFailedError.cs @@ -4,9 +4,9 @@ public class FileValidationFailedError : Error { - public FileValidationFailedError(string message) + public FileValidationFailedError(string message) : base(message, OcelotErrorCode.FileValidationFailedError) { } } -} +} diff --git a/src/Ocelot/Configuration/Validator/IConfigurationValidator.cs b/src/Ocelot/Configuration/Validator/IConfigurationValidator.cs index 39f90c81..f9b7eef9 100644 --- a/src/Ocelot/Configuration/Validator/IConfigurationValidator.cs +++ b/src/Ocelot/Configuration/Validator/IConfigurationValidator.cs @@ -1,11 +1,11 @@ namespace Ocelot.Configuration.Validator { - using System.Threading.Tasks; using Ocelot.Configuration.File; using Ocelot.Responses; + using System.Threading.Tasks; public interface IConfigurationValidator { Task> IsValid(FileConfiguration configuration); } -} +} diff --git a/src/Ocelot/Configuration/Validator/ReRouteFluentValidator.cs b/src/Ocelot/Configuration/Validator/ReRouteFluentValidator.cs index e91c2f00..724d92bb 100644 --- a/src/Ocelot/Configuration/Validator/ReRouteFluentValidator.cs +++ b/src/Ocelot/Configuration/Validator/ReRouteFluentValidator.cs @@ -1,9 +1,8 @@ namespace Ocelot.Configuration.Validator { - using System; + using File; using FluentValidation; using Microsoft.AspNetCore.Authentication; - using File; using System.Linq; using System.Text.RegularExpressions; using System.Threading; @@ -73,12 +72,14 @@ .MustAsync(IsSupportedAuthenticationProviders) .WithMessage("{PropertyName} {PropertyValue} is unsupported authentication provider"); - When(reRoute => string.IsNullOrEmpty(reRoute.ServiceName), () => { + When(reRoute => string.IsNullOrEmpty(reRoute.ServiceName), () => + { RuleFor(r => r.DownstreamHostAndPorts).NotEmpty() .WithMessage("When not using service discovery DownstreamHostAndPorts must be set and not empty or Ocelot cannot find your service!"); }); - When(reRoute => string.IsNullOrEmpty(reRoute.ServiceName), () => { + When(reRoute => string.IsNullOrEmpty(reRoute.ServiceName), () => + { RuleFor(reRoute => reRoute.DownstreamHostAndPorts) .SetCollectionValidator(hostAndPortValidator); }); diff --git a/src/Ocelot/DependencyInjection/AdministrationPath.cs b/src/Ocelot/DependencyInjection/AdministrationPath.cs index b76fdbb2..13f4c0d1 100644 --- a/src/Ocelot/DependencyInjection/AdministrationPath.cs +++ b/src/Ocelot/DependencyInjection/AdministrationPath.cs @@ -7,6 +7,6 @@ namespace Ocelot.DependencyInjection Path = path; } - public string Path {get;private set;} + public string Path { get; private set; } } } diff --git a/src/Ocelot/DependencyInjection/ConfigurationBuilderExtensions.cs b/src/Ocelot/DependencyInjection/ConfigurationBuilderExtensions.cs index 02b5a17b..8d75bd97 100644 --- a/src/Ocelot/DependencyInjection/ConfigurationBuilderExtensions.cs +++ b/src/Ocelot/DependencyInjection/ConfigurationBuilderExtensions.cs @@ -1,15 +1,15 @@ namespace Ocelot.DependencyInjection { - using System; - using System.Collections.Generic; + using Configuration.File; + using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration.Memory; + using Newtonsoft.Json; + using System; + using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; - using Configuration.File; - using Newtonsoft.Json; - using Microsoft.AspNetCore.Hosting; public static class ConfigurationBuilderExtensions { @@ -55,13 +55,13 @@ namespace Ocelot.DependencyInjection foreach (var file in files) { - if(files.Count > 1 && file.Name.Equals(primaryConfigFile, StringComparison.OrdinalIgnoreCase)) + if (files.Count > 1 && file.Name.Equals(primaryConfigFile, StringComparison.OrdinalIgnoreCase)) { continue; } var lines = File.ReadAllText(file.FullName); - + var config = JsonConvert.DeserializeObject(lines); if (file.Name.Equals(globalConfigFile, StringComparison.OrdinalIgnoreCase)) diff --git a/src/Ocelot/DependencyInjection/IAdministrationPath.cs b/src/Ocelot/DependencyInjection/IAdministrationPath.cs index a206652f..856e0fa3 100644 --- a/src/Ocelot/DependencyInjection/IAdministrationPath.cs +++ b/src/Ocelot/DependencyInjection/IAdministrationPath.cs @@ -2,6 +2,6 @@ namespace Ocelot.DependencyInjection { public interface IAdministrationPath { - string Path {get;} + string Path { get; } } -} \ No newline at end of file +} diff --git a/src/Ocelot/DependencyInjection/IOcelotBuilder.cs b/src/Ocelot/DependencyInjection/IOcelotBuilder.cs index 34841c80..5e4421be 100644 --- a/src/Ocelot/DependencyInjection/IOcelotBuilder.cs +++ b/src/Ocelot/DependencyInjection/IOcelotBuilder.cs @@ -1,8 +1,7 @@ -using System; -using System.Net.Http; -using Ocelot.Middleware.Multiplexer; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Ocelot.Middleware.Multiplexer; +using System.Net.Http; namespace Ocelot.DependencyInjection { @@ -17,10 +16,10 @@ namespace Ocelot.DependencyInjection IOcelotBuilder AddDelegatingHandler(bool global = false) where T : DelegatingHandler; - IOcelotBuilder AddSingletonDefinedAggregator() + IOcelotBuilder AddSingletonDefinedAggregator() where T : class, IDefinedAggregator; - IOcelotBuilder AddTransientDefinedAggregator() + IOcelotBuilder AddTransientDefinedAggregator() where T : class, IDefinedAggregator; } } diff --git a/src/Ocelot/DependencyInjection/OcelotAdministrationBuilder.cs b/src/Ocelot/DependencyInjection/OcelotAdministrationBuilder.cs index 6e59284f..1ef75d06 100644 --- a/src/Ocelot/DependencyInjection/OcelotAdministrationBuilder.cs +++ b/src/Ocelot/DependencyInjection/OcelotAdministrationBuilder.cs @@ -11,7 +11,7 @@ namespace Ocelot.DependencyInjection public OcelotAdministrationBuilder(IServiceCollection services, IConfiguration configurationRoot) { ConfigurationRoot = configurationRoot; - Services = services; + Services = services; } } } diff --git a/src/Ocelot/DependencyInjection/OcelotBuilder.cs b/src/Ocelot/DependencyInjection/OcelotBuilder.cs index 3fee15e7..958f6841 100644 --- a/src/Ocelot/DependencyInjection/OcelotBuilder.cs +++ b/src/Ocelot/DependencyInjection/OcelotBuilder.cs @@ -3,9 +3,11 @@ namespace Ocelot.DependencyInjection using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.DependencyInjection.Extensions; using Ocelot.Authorisation; using Ocelot.Cache; using Ocelot.Claims; + using Ocelot.Configuration; using Ocelot.Configuration.Creator; using Ocelot.Configuration.File; using Ocelot.Configuration.Parser; @@ -16,27 +18,25 @@ namespace Ocelot.DependencyInjection using Ocelot.DownstreamRouteFinder.UrlMatcher; using Ocelot.DownstreamUrlCreator.UrlTemplateReplacer; using Ocelot.Headers; + using Ocelot.Infrastructure; using Ocelot.Infrastructure.Claims.Parser; using Ocelot.Infrastructure.RequestData; using Ocelot.LoadBalancer.LoadBalancers; using Ocelot.Logging; using Ocelot.Middleware; + using Ocelot.Middleware.Multiplexer; using Ocelot.QueryStrings; using Ocelot.RateLimit; + using Ocelot.Request.Creator; using Ocelot.Request.Mapper; using Ocelot.Requester; using Ocelot.Requester.QoS; using Ocelot.Responder; - using Ocelot.ServiceDiscovery; - using System.Reflection; - using Ocelot.Configuration; - using Microsoft.Extensions.DependencyInjection.Extensions; - using System.Net.Http; - using Ocelot.Infrastructure; - using Ocelot.Middleware.Multiplexer; - using Ocelot.Request.Creator; - using Ocelot.Security.IPSecurity; using Ocelot.Security; + using Ocelot.Security.IPSecurity; + using Ocelot.ServiceDiscovery; + using System.Net.Http; + using System.Reflection; public class OcelotBuilder : IOcelotBuilder { diff --git a/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs b/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs index e3f90665..030e9957 100644 --- a/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs +++ b/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs @@ -1,5 +1,4 @@ -using System; -using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System.Linq; @@ -19,4 +18,4 @@ namespace Ocelot.DependencyInjection return new OcelotBuilder(services, configuration); } } -} +} diff --git a/src/Ocelot/DownstreamRouteFinder/DownstreamRoute.cs b/src/Ocelot/DownstreamRouteFinder/DownstreamRoute.cs index c7696ecf..a691e11e 100644 --- a/src/Ocelot/DownstreamRouteFinder/DownstreamRoute.cs +++ b/src/Ocelot/DownstreamRouteFinder/DownstreamRoute.cs @@ -1,6 +1,6 @@ -using System.Collections.Generic; -using Ocelot.Configuration; +using Ocelot.Configuration; using Ocelot.DownstreamRouteFinder.UrlMatcher; +using System.Collections.Generic; namespace Ocelot.DownstreamRouteFinder { @@ -15,4 +15,4 @@ namespace Ocelot.DownstreamRouteFinder public List TemplatePlaceholderNameAndValues { get; private set; } public ReRoute ReRoute { get; private set; } } -} +} diff --git a/src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteCreator.cs b/src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteCreator.cs index b032555d..ec6821ad 100644 --- a/src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteCreator.cs +++ b/src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteCreator.cs @@ -1,14 +1,13 @@ namespace Ocelot.DownstreamRouteFinder.Finder { - using System.Collections.Concurrent; - using System.Collections.Generic; - using System.Linq; using Configuration; using Configuration.Builder; using Configuration.Creator; - using Configuration.File; using LoadBalancer.LoadBalancers; using Responses; + using System.Collections.Concurrent; + using System.Collections.Generic; + using System.Linq; using UrlMatcher; public class DownstreamRouteCreator : IDownstreamRouteProvider @@ -23,12 +22,12 @@ } public Response Get(string upstreamUrlPath, string upstreamQueryString, string upstreamHttpMethod, IInternalConfiguration configuration, string upstreamHost) - { + { var serviceName = GetServiceName(upstreamUrlPath); var downstreamPath = GetDownstreamPath(upstreamUrlPath); - if(HasQueryString(downstreamPath)) + if (HasQueryString(downstreamPath)) { downstreamPath = RemoveQueryString(downstreamPath); } @@ -37,7 +36,7 @@ var loadBalancerKey = CreateLoadBalancerKey(downstreamPathForKeys, upstreamHttpMethod, configuration.LoadBalancerOptions); - if(_cache.TryGetValue(loadBalancerKey, out var downstreamRoute)) + if (_cache.TryGetValue(loadBalancerKey, out var downstreamRoute)) { return downstreamRoute; } @@ -57,31 +56,31 @@ .WithLoadBalancerOptions(configuration.LoadBalancerOptions) .WithUpstreamPathTemplate(upstreamPathTemplate); - var rateLimitOptions = configuration.ReRoutes != null - ? configuration.ReRoutes - .SelectMany(x => x.DownstreamReRoute) - .FirstOrDefault(x => x.ServiceName == serviceName) - : null; + var rateLimitOptions = configuration.ReRoutes != null + ? configuration.ReRoutes + .SelectMany(x => x.DownstreamReRoute) + .FirstOrDefault(x => x.ServiceName == serviceName) + : null; - if(rateLimitOptions != null) - { - downstreamReRouteBuilder - .WithRateLimitOptions(rateLimitOptions.RateLimitOptions) - .WithEnableRateLimiting(true); - } - - var downstreamReRoute = downstreamReRouteBuilder.Build(); + if (rateLimitOptions != null) + { + downstreamReRouteBuilder + .WithRateLimitOptions(rateLimitOptions.RateLimitOptions) + .WithEnableRateLimiting(true); + } + + var downstreamReRoute = downstreamReRouteBuilder.Build(); var reRoute = new ReRouteBuilder() .WithDownstreamReRoute(downstreamReRoute) - .WithUpstreamHttpMethod(new List(){ upstreamHttpMethod }) + .WithUpstreamHttpMethod(new List() { upstreamHttpMethod }) .WithUpstreamPathTemplate(upstreamPathTemplate) .Build(); downstreamRoute = new OkResponse(new DownstreamRoute(new List(), reRoute)); _cache.AddOrUpdate(loadBalancerKey, downstreamRoute, (x, y) => downstreamRoute); - + return downstreamRoute; } @@ -98,7 +97,7 @@ private static string GetDownstreamPath(string upstreamUrlPath) { - if(upstreamUrlPath.IndexOf('/', 1) == -1) + if (upstreamUrlPath.IndexOf('/', 1) == -1) { return "/"; } @@ -109,7 +108,7 @@ private static string GetServiceName(string upstreamUrlPath) { - if(upstreamUrlPath.IndexOf('/', 1) == -1) + if (upstreamUrlPath.IndexOf('/', 1) == -1) { return upstreamUrlPath .Substring(1); diff --git a/src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteFinder.cs b/src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteFinder.cs index a66d2a04..115fbd42 100644 --- a/src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteFinder.cs +++ b/src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteFinder.cs @@ -1,9 +1,8 @@ -using System.Collections.Generic; -using System.Linq; -using Ocelot.Configuration; +using Ocelot.Configuration; using Ocelot.DownstreamRouteFinder.UrlMatcher; -using Ocelot.Errors; using Ocelot.Responses; +using System.Collections.Generic; +using System.Linq; namespace Ocelot.DownstreamRouteFinder.Finder { diff --git a/src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteProviderFactory.cs b/src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteProviderFactory.cs index 319e9191..32f68936 100644 --- a/src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteProviderFactory.cs +++ b/src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteProviderFactory.cs @@ -1,17 +1,17 @@ namespace Ocelot.DownstreamRouteFinder.Finder { - using System; - using System.Collections.Generic; - using System.Linq; using Configuration; using Microsoft.Extensions.DependencyInjection; using Ocelot.Logging; + using System; + using System.Collections.Generic; + using System.Linq; public class DownstreamRouteProviderFactory : IDownstreamRouteProviderFactory { private readonly Dictionary _providers; private readonly IOcelotLogger _logger; - + public DownstreamRouteProviderFactory(IServiceProvider provider, IOcelotLoggerFactory factory) { _logger = factory.CreateLogger(); @@ -22,18 +22,18 @@ { //todo - this is a bit hacky we are saying there are no reRoutes or there are reRoutes but none of them have //an upstream path template which means they are dyanmic and service discovery is on... - if((!config.ReRoutes.Any() || config.ReRoutes.All(x => string.IsNullOrEmpty(x.UpstreamTemplatePattern?.OriginalValue))) && IsServiceDiscovery(config.ServiceProviderConfiguration)) + if ((!config.ReRoutes.Any() || config.ReRoutes.All(x => string.IsNullOrEmpty(x.UpstreamTemplatePattern?.OriginalValue))) && IsServiceDiscovery(config.ServiceProviderConfiguration)) { _logger.LogInformation($"Selected {nameof(DownstreamRouteCreator)} as DownstreamRouteProvider for this request"); return _providers[nameof(DownstreamRouteCreator)]; } - + return _providers[nameof(DownstreamRouteFinder)]; } private bool IsServiceDiscovery(ServiceProviderConfiguration config) { - if(!string.IsNullOrEmpty(config?.Host) && config?.Port > 0 && !string.IsNullOrEmpty(config.Type)) + if (!string.IsNullOrEmpty(config?.Host) && config?.Port > 0 && !string.IsNullOrEmpty(config.Type)) { return true; } diff --git a/src/Ocelot/DownstreamRouteFinder/Finder/IDownstreamRouteProvider.cs b/src/Ocelot/DownstreamRouteFinder/Finder/IDownstreamRouteProvider.cs index 0a84f8f4..b2809ac9 100644 --- a/src/Ocelot/DownstreamRouteFinder/Finder/IDownstreamRouteProvider.cs +++ b/src/Ocelot/DownstreamRouteFinder/Finder/IDownstreamRouteProvider.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using Ocelot.Configuration; +using Ocelot.Configuration; using Ocelot.Responses; namespace Ocelot.DownstreamRouteFinder.Finder diff --git a/src/Ocelot/DownstreamRouteFinder/Finder/UnableToFindDownstreamRouteError.cs b/src/Ocelot/DownstreamRouteFinder/Finder/UnableToFindDownstreamRouteError.cs index cd7141a8..5a0a358c 100644 --- a/src/Ocelot/DownstreamRouteFinder/Finder/UnableToFindDownstreamRouteError.cs +++ b/src/Ocelot/DownstreamRouteFinder/Finder/UnableToFindDownstreamRouteError.cs @@ -4,9 +4,9 @@ namespace Ocelot.DownstreamRouteFinder.Finder { public class UnableToFindDownstreamRouteError : Error { - public UnableToFindDownstreamRouteError(string path, string httpVerb) + public UnableToFindDownstreamRouteError(string path, string httpVerb) : base($"Failed to match ReRoute configuration for upstream path: {path}, verb: {httpVerb}.", OcelotErrorCode.UnableToFindDownstreamRouteError) { } } -} +} diff --git a/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs b/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs index c9b534ed..8ac0705c 100644 --- a/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs +++ b/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs @@ -1,11 +1,10 @@ -using System.Threading.Tasks; -using System.Linq; -using Ocelot.Configuration.Repository; using Ocelot.DownstreamRouteFinder.Finder; using Ocelot.Infrastructure.Extensions; using Ocelot.Logging; using Ocelot.Middleware; using Ocelot.Middleware.Multiplexer; +using System.Linq; +using System.Threading.Tasks; namespace Ocelot.DownstreamRouteFinder.Middleware { @@ -19,7 +18,7 @@ namespace Ocelot.DownstreamRouteFinder.Middleware IOcelotLoggerFactory loggerFactory, IDownstreamRouteProviderFactory downstreamRouteFinder, IMultiplexer multiplexer) - :base(loggerFactory.CreateLogger()) + : base(loggerFactory.CreateLogger()) { _multiplexer = multiplexer; _next = next; @@ -46,10 +45,10 @@ namespace Ocelot.DownstreamRouteFinder.Middleware SetPipelineError(context, downstreamRoute.Errors); return; - } - + } + var downstreamPathTemplates = string.Join(", ", downstreamRoute.Data.ReRoute.DownstreamReRoute.Select(r => r.DownstreamPathTemplate.Value)); - + Logger.LogDebug($"downstream templates are {downstreamPathTemplates}"); context.TemplatePlaceholderNameAndValues = downstreamRoute.Data.TemplatePlaceholderNameAndValues; diff --git a/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddlewareExtensions.cs b/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddlewareExtensions.cs index 13dacac8..08a856b6 100644 --- a/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddlewareExtensions.cs +++ b/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddlewareExtensions.cs @@ -10,4 +10,4 @@ namespace Ocelot.DownstreamRouteFinder.Middleware return builder.UseMiddleware(); } } -} +} diff --git a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/IPlaceholderNameAndValueFinder.cs b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/IPlaceholderNameAndValueFinder.cs index 986d7b84..c9b16260 100644 --- a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/IPlaceholderNameAndValueFinder.cs +++ b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/IPlaceholderNameAndValueFinder.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; -using Ocelot.Responses; +using Ocelot.Responses; +using System.Collections.Generic; namespace Ocelot.DownstreamRouteFinder.UrlMatcher { diff --git a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/IUrlPathToUrlTemplateMatcher.cs b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/IUrlPathToUrlTemplateMatcher.cs index 9d6ffb4e..d9d3a45f 100644 --- a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/IUrlPathToUrlTemplateMatcher.cs +++ b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/IUrlPathToUrlTemplateMatcher.cs @@ -4,7 +4,7 @@ using Ocelot.Values; namespace Ocelot.DownstreamRouteFinder.UrlMatcher { public interface IUrlPathToUrlTemplateMatcher - { + { Response Match(string upstreamUrlPath, string upstreamQueryString, UpstreamPathTemplate pathTemplate); - } -} + } +} diff --git a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/PlaceholderNameAndValue.cs b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/PlaceholderNameAndValue.cs index 90099d58..4bd29414 100644 --- a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/PlaceholderNameAndValue.cs +++ b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/PlaceholderNameAndValue.cs @@ -8,7 +8,7 @@ namespace Ocelot.DownstreamRouteFinder.UrlMatcher Value = value; } - public string Name {get;private set;} - public string Value {get;private set;} + public string Name { get; private set; } + public string Value { get; private set; } } } diff --git a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/RegExUrlMatcher.cs b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/RegExUrlMatcher.cs index 84b91304..a4979f4d 100644 --- a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/RegExUrlMatcher.cs +++ b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/RegExUrlMatcher.cs @@ -1,5 +1,4 @@ -using System.Text.RegularExpressions; -using Ocelot.Responses; +using Ocelot.Responses; using Ocelot.Values; namespace Ocelot.DownstreamRouteFinder.UrlMatcher @@ -15,8 +14,8 @@ namespace Ocelot.DownstreamRouteFinder.UrlMatcher : new OkResponse(new UrlMatch(false)); } - return pathTemplate.Pattern.IsMatch($"{upstreamUrlPath}{upstreamQueryString}") - ? new OkResponse(new UrlMatch(true)) + return pathTemplate.Pattern.IsMatch($"{upstreamUrlPath}{upstreamQueryString}") + ? new OkResponse(new UrlMatch(true)) : new OkResponse(new UrlMatch(false)); } } diff --git a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlMatch.cs b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlMatch.cs index 9236ae39..9ef6396c 100644 --- a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlMatch.cs +++ b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlMatch.cs @@ -4,9 +4,9 @@ namespace Ocelot.DownstreamRouteFinder.UrlMatcher { public UrlMatch(bool match) { - Match = match; + Match = match; } - public bool Match {get;private set;} + public bool Match { get; private set; } } -} +} diff --git a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinder.cs b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinder.cs index bb59fac4..50f1ef7a 100644 --- a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinder.cs +++ b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinder.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; using Ocelot.Responses; +using System.Collections.Generic; namespace Ocelot.DownstreamRouteFinder.UrlMatcher { @@ -18,7 +18,7 @@ namespace Ocelot.DownstreamRouteFinder.UrlMatcher for (int counterForTemplate = 0; counterForTemplate < pathTemplate.Length; counterForTemplate++) { - if ((path.Length > counterForPath) && CharactersDontMatch(pathTemplate[counterForTemplate], path[counterForPath]) && ContinueScanningUrl(counterForPath,path.Length)) + if ((path.Length > counterForPath) && CharactersDontMatch(pathTemplate[counterForTemplate], path[counterForPath]) && ContinueScanningUrl(counterForPath, path.Length)) { if (IsPlaceholder(pathTemplate[counterForTemplate])) { @@ -51,13 +51,13 @@ namespace Ocelot.DownstreamRouteFinder.UrlMatcher return new OkResponse>(placeHolderNameAndValues); } - else if(IsCatchAll(path, counterForPath, pathTemplate)) + else if (IsCatchAll(path, counterForPath, pathTemplate)) { var endOfPlaceholder = GetNextCounterPosition(pathTemplate, counterForTemplate, '}'); var placeholderName = GetPlaceholderName(pathTemplate, 1); - if(NothingAfterFirstForwardSlash(path)) + if (NothingAfterFirstForwardSlash(path)) { placeHolderNameAndValues.Add(new PlaceholderNameAndValue(placeholderName, "")); } @@ -93,8 +93,8 @@ namespace Ocelot.DownstreamRouteFinder.UrlMatcher private bool IsCatchAll(string path, int counterForPath, string pathTemplate) { - return string.IsNullOrEmpty(path) || (path.Length > counterForPath && path[counterForPath] == '/') && pathTemplate.Length > 1 - && pathTemplate.Substring(0, 2) == "/{" + return string.IsNullOrEmpty(path) || (path.Length > counterForPath && path[counterForPath] == '/') && pathTemplate.Length > 1 + && pathTemplate.Substring(0, 2) == "/{" && pathTemplate.IndexOf('}') == pathTemplate.Length - 1; } @@ -127,9 +127,9 @@ namespace Ocelot.DownstreamRouteFinder.UrlMatcher } private int GetNextCounterPosition(string urlTemplate, int counterForTemplate, char delimiter) - { + { var closingPlaceHolderPositionOnTemplate = urlTemplate.IndexOf(delimiter, counterForTemplate); - return closingPlaceHolderPositionOnTemplate + 1; + return closingPlaceHolderPositionOnTemplate + 1; } private bool CharactersDontMatch(char characterOne, char characterTwo) diff --git a/src/Ocelot/DownstreamUrlCreator/Middleware/DownstreamUrlCreatorMiddleware.cs b/src/Ocelot/DownstreamUrlCreator/Middleware/DownstreamUrlCreatorMiddleware.cs index 1e545d28..d2e53b95 100644 --- a/src/Ocelot/DownstreamUrlCreator/Middleware/DownstreamUrlCreatorMiddleware.cs +++ b/src/Ocelot/DownstreamUrlCreator/Middleware/DownstreamUrlCreatorMiddleware.cs @@ -1,10 +1,10 @@ -using System.Threading.Tasks; using Ocelot.DownstreamUrlCreator.UrlTemplateReplacer; using Ocelot.Logging; using Ocelot.Middleware; -using System; using Ocelot.Responses; using Ocelot.Values; +using System; +using System.Threading.Tasks; namespace Ocelot.DownstreamUrlCreator.Middleware { @@ -18,7 +18,7 @@ namespace Ocelot.DownstreamUrlCreator.Middleware public DownstreamUrlCreatorMiddleware(OcelotRequestDelegate next, IOcelotLoggerFactory loggerFactory, IDownstreamPathPlaceholderReplacer replacer) - :base(loggerFactory.CreateLogger()) + : base(loggerFactory.CreateLogger()) { _next = next; _replacer = replacer; @@ -49,7 +49,7 @@ namespace Ocelot.DownstreamUrlCreator.Middleware { var dsPath = response.Data; - if(ContainsQueryString(dsPath)) + if (ContainsQueryString(dsPath)) { context.DownstreamRequest.AbsolutePath = GetPath(dsPath); @@ -115,7 +115,7 @@ namespace Ocelot.DownstreamUrlCreator.Middleware private (string path, string query) CreateServiceFabricUri(DownstreamContext context, Response dsPath) { - var query = context.DownstreamRequest.Query; + var query = context.DownstreamRequest.Query; var serviceName = _replacer.Replace(context.DownstreamReRoute.ServiceName, context.TemplatePlaceholderNameAndValues); var pathTemplate = $"/{serviceName.Data.Value}{dsPath.Data.Value}"; return (pathTemplate, query); diff --git a/src/Ocelot/DownstreamUrlCreator/Middleware/DownstreamUrlCreatorMiddlewareExtensions.cs b/src/Ocelot/DownstreamUrlCreator/Middleware/DownstreamUrlCreatorMiddlewareExtensions.cs index 671636c5..8904d3af 100644 --- a/src/Ocelot/DownstreamUrlCreator/Middleware/DownstreamUrlCreatorMiddlewareExtensions.cs +++ b/src/Ocelot/DownstreamUrlCreator/Middleware/DownstreamUrlCreatorMiddlewareExtensions.cs @@ -10,4 +10,4 @@ namespace Ocelot.DownstreamUrlCreator.Middleware return builder.UseMiddleware(); } } -} +} diff --git a/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/DownstreamTemplatePathPlaceholderReplacer.cs b/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/DownstreamTemplatePathPlaceholderReplacer.cs index ac91ef2e..a58c6607 100644 --- a/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/DownstreamTemplatePathPlaceholderReplacer.cs +++ b/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/DownstreamTemplatePathPlaceholderReplacer.cs @@ -1,8 +1,8 @@ -using System.Collections.Generic; -using System.Text; using Ocelot.DownstreamRouteFinder.UrlMatcher; using Ocelot.Responses; using Ocelot.Values; +using System.Collections.Generic; +using System.Text; namespace Ocelot.DownstreamUrlCreator.UrlTemplateReplacer { diff --git a/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/IDownstreamPathPlaceholderReplacer.cs b/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/IDownstreamPathPlaceholderReplacer.cs index 237f20fc..e6c0864a 100644 --- a/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/IDownstreamPathPlaceholderReplacer.cs +++ b/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/IDownstreamPathPlaceholderReplacer.cs @@ -1,12 +1,12 @@ -using System.Collections.Generic; using Ocelot.DownstreamRouteFinder.UrlMatcher; using Ocelot.Responses; using Ocelot.Values; +using System.Collections.Generic; namespace Ocelot.DownstreamUrlCreator.UrlTemplateReplacer { public interface IDownstreamPathPlaceholderReplacer { - Response Replace(string downstreamPathTemplate, List urlPathPlaceholderNameAndValues); + Response Replace(string downstreamPathTemplate, List urlPathPlaceholderNameAndValues); } } diff --git a/src/Ocelot/Errors/Error.cs b/src/Ocelot/Errors/Error.cs index e063934b..18c3c49f 100644 --- a/src/Ocelot/Errors/Error.cs +++ b/src/Ocelot/Errors/Error.cs @@ -1,6 +1,6 @@ namespace Ocelot.Errors { - public abstract class Error + public abstract class Error { protected Error(string message, OcelotErrorCode code) { @@ -16,4 +16,4 @@ namespace Ocelot.Errors return Message; } } -} +} diff --git a/src/Ocelot/Errors/Middleware/ExceptionHandlerMiddlewareExtensions.cs b/src/Ocelot/Errors/Middleware/ExceptionHandlerMiddlewareExtensions.cs index 5d8874b0..82e1050e 100644 --- a/src/Ocelot/Errors/Middleware/ExceptionHandlerMiddlewareExtensions.cs +++ b/src/Ocelot/Errors/Middleware/ExceptionHandlerMiddlewareExtensions.cs @@ -10,4 +10,4 @@ namespace Ocelot.Errors.Middleware return builder.UseMiddleware(); } } -} +} diff --git a/src/Ocelot/Headers/AddHeadersToRequest.cs b/src/Ocelot/Headers/AddHeadersToRequest.cs index d24f549a..9b0afee7 100644 --- a/src/Ocelot/Headers/AddHeadersToRequest.cs +++ b/src/Ocelot/Headers/AddHeadersToRequest.cs @@ -1,17 +1,16 @@ namespace Ocelot.Headers { - using System.Collections.Generic; - using System.Linq; using Infrastructure; using Logging; - using Ocelot.Configuration; - using Ocelot.Infrastructure.Claims.Parser; - using Ocelot.Responses; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Primitives; + using Ocelot.Configuration; using Ocelot.Configuration.Creator; - using Ocelot.Middleware; + using Ocelot.Infrastructure.Claims.Parser; using Ocelot.Request.Middleware; + using Ocelot.Responses; + using System.Collections.Generic; + using System.Linq; public class AddHeadersToRequest : IAddHeadersToRequest { @@ -49,7 +48,7 @@ return new OkResponse(); } - + public void SetHeadersOnDownstreamRequest(IEnumerable headers, HttpContext context) { var requestHeader = context.Request.Headers; diff --git a/src/Ocelot/Headers/AddHeadersToResponse.cs b/src/Ocelot/Headers/AddHeadersToResponse.cs index 7c440d6a..a4151860 100644 --- a/src/Ocelot/Headers/AddHeadersToResponse.cs +++ b/src/Ocelot/Headers/AddHeadersToResponse.cs @@ -1,11 +1,11 @@ namespace Ocelot.Headers { - using System.Collections.Generic; using Ocelot.Configuration.Creator; using Ocelot.Infrastructure; using Ocelot.Infrastructure.Extensions; using Ocelot.Logging; using Ocelot.Middleware; + using System.Collections.Generic; public class AddHeadersToResponse : IAddHeadersToResponse { @@ -20,13 +20,13 @@ namespace Ocelot.Headers public void Add(List addHeaders, DownstreamResponse response) { - foreach(var add in addHeaders) + foreach (var add in addHeaders) { - if(add.Value.StartsWith('{') && add.Value.EndsWith('}')) + if (add.Value.StartsWith('{') && add.Value.EndsWith('}')) { var value = _placeholders.Get(add.Value); - - if(value.IsError) + + if (value.IsError) { _logger.LogWarning($"Unable to add header to response {add.Key}: {add.Value}"); continue; diff --git a/src/Ocelot/Headers/HttpContextRequestHeaderReplacer.cs b/src/Ocelot/Headers/HttpContextRequestHeaderReplacer.cs index 2323258a..6709231d 100644 --- a/src/Ocelot/Headers/HttpContextRequestHeaderReplacer.cs +++ b/src/Ocelot/Headers/HttpContextRequestHeaderReplacer.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; using Microsoft.AspNetCore.Http; using Ocelot.Configuration; using Ocelot.Responses; +using System.Collections.Generic; namespace Ocelot.Headers { @@ -11,7 +11,7 @@ namespace Ocelot.Headers { foreach (var f in fAndRs) { - if(context.Request.Headers.TryGetValue(f.Key, out var values)) + if (context.Request.Headers.TryGetValue(f.Key, out var values)) { var replaced = values[f.Index].Replace(f.Find, f.Replace); context.Request.Headers.Remove(f.Key); diff --git a/src/Ocelot/Headers/HttpResponseHeaderReplacer.cs b/src/Ocelot/Headers/HttpResponseHeaderReplacer.cs index eb88af7a..a6992bf1 100644 --- a/src/Ocelot/Headers/HttpResponseHeaderReplacer.cs +++ b/src/Ocelot/Headers/HttpResponseHeaderReplacer.cs @@ -1,12 +1,12 @@ namespace Ocelot.Headers { - using System.Collections.Generic; - using System.Linq; using Ocelot.Configuration; using Ocelot.Infrastructure; using Ocelot.Infrastructure.Extensions; using Ocelot.Middleware; using Ocelot.Responses; + using System.Collections.Generic; + using System.Linq; public class HttpResponseHeaderReplacer : IHttpResponseHeaderReplacer { @@ -27,12 +27,12 @@ namespace Ocelot.Headers var dict = response.Headers.ToDictionary(x => x.Key); //if the response headers contain a matching find and replace - if(dict.TryGetValue(f.Key, out var values)) + if (dict.TryGetValue(f.Key, out var values)) { //check to see if it is a placeholder in the find... var placeholderValue = _placeholders.Get(f.Find, request); - if(!placeholderValue.IsError) + if (!placeholderValue.IsError) { //if it is we need to get the value of the placeholder var replaced = values.Values.ToList()[f.Index].Replace(placeholderValue.Data, f.Replace.LastCharAsForwardSlash()); diff --git a/src/Ocelot/Headers/IAddHeadersToRequest.cs b/src/Ocelot/Headers/IAddHeadersToRequest.cs index a0afb0c0..9abbb3b4 100644 --- a/src/Ocelot/Headers/IAddHeadersToRequest.cs +++ b/src/Ocelot/Headers/IAddHeadersToRequest.cs @@ -2,18 +2,16 @@ namespace Ocelot.Headers { - using System.Collections.Generic; - using System.Net.Http; - using Ocelot.Configuration; using Ocelot.Configuration.Creator; - using Ocelot.Infrastructure.RequestData; using Ocelot.Request.Middleware; using Ocelot.Responses; + using System.Collections.Generic; public interface IAddHeadersToRequest { Response SetHeadersOnDownstreamRequest(List claimsToThings, IEnumerable claims, DownstreamRequest downstreamRequest); + void SetHeadersOnDownstreamRequest(IEnumerable headers, HttpContext context); } -} +} diff --git a/src/Ocelot/Headers/IAddHeadersToResponse.cs b/src/Ocelot/Headers/IAddHeadersToResponse.cs index 210ddd32..bbd37f4d 100644 --- a/src/Ocelot/Headers/IAddHeadersToResponse.cs +++ b/src/Ocelot/Headers/IAddHeadersToResponse.cs @@ -2,9 +2,8 @@ using Ocelot.Middleware; namespace Ocelot.Headers { - using System.Collections.Generic; using Ocelot.Configuration.Creator; - using Ocelot.Middleware.Multiplexer; + using System.Collections.Generic; public interface IAddHeadersToResponse { diff --git a/src/Ocelot/Headers/IHttpContextRequestHeaderReplacer.cs b/src/Ocelot/Headers/IHttpContextRequestHeaderReplacer.cs index 5c985cfe..ba5ba348 100644 --- a/src/Ocelot/Headers/IHttpContextRequestHeaderReplacer.cs +++ b/src/Ocelot/Headers/IHttpContextRequestHeaderReplacer.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; using Microsoft.AspNetCore.Http; using Ocelot.Configuration; using Ocelot.Responses; +using System.Collections.Generic; namespace Ocelot.Headers { @@ -9,4 +9,4 @@ namespace Ocelot.Headers { Response Replace(HttpContext context, List fAndRs); } -} \ No newline at end of file +} diff --git a/src/Ocelot/Headers/IHttpResponseHeaderReplacer.cs b/src/Ocelot/Headers/IHttpResponseHeaderReplacer.cs index 7a180196..5ef5c84c 100644 --- a/src/Ocelot/Headers/IHttpResponseHeaderReplacer.cs +++ b/src/Ocelot/Headers/IHttpResponseHeaderReplacer.cs @@ -1,12 +1,12 @@ namespace Ocelot.Headers { - using System.Collections.Generic; using Ocelot.Configuration; using Ocelot.Middleware; using Ocelot.Responses; + using System.Collections.Generic; public interface IHttpResponseHeaderReplacer { Response Replace(DownstreamContext context, List fAndRs); } -} +} diff --git a/src/Ocelot/Headers/IRemoveOutputHeaders.cs b/src/Ocelot/Headers/IRemoveOutputHeaders.cs index 8c081c3b..bf2f7ff4 100644 --- a/src/Ocelot/Headers/IRemoveOutputHeaders.cs +++ b/src/Ocelot/Headers/IRemoveOutputHeaders.cs @@ -1,7 +1,6 @@ -using System.Collections.Generic; -using Ocelot.Middleware; -using Ocelot.Middleware.Multiplexer; +using Ocelot.Middleware; using Ocelot.Responses; +using System.Collections.Generic; namespace Ocelot.Headers { @@ -9,4 +8,4 @@ namespace Ocelot.Headers { Response Remove(List
headers); } -} +} diff --git a/src/Ocelot/Headers/Middleware/ClaimsToHeadersMiddleware.cs b/src/Ocelot/Headers/Middleware/ClaimsToHeadersMiddleware.cs index 1faf4fa6..e45bb4bb 100644 --- a/src/Ocelot/Headers/Middleware/ClaimsToHeadersMiddleware.cs +++ b/src/Ocelot/Headers/Middleware/ClaimsToHeadersMiddleware.cs @@ -1,10 +1,7 @@ -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Ocelot.DownstreamRouteFinder.Middleware; -using Ocelot.Infrastructure.RequestData; -using Ocelot.Logging; +using Ocelot.Logging; using Ocelot.Middleware; +using System.Linq; +using System.Threading.Tasks; namespace Ocelot.Headers.Middleware { @@ -15,8 +12,8 @@ namespace Ocelot.Headers.Middleware public ClaimsToHeadersMiddleware(OcelotRequestDelegate next, IOcelotLoggerFactory loggerFactory, - IAddHeadersToRequest addHeadersToRequest) - :base(loggerFactory.CreateLogger()) + IAddHeadersToRequest addHeadersToRequest) + : base(loggerFactory.CreateLogger()) { _next = next; _addHeadersToRequest = addHeadersToRequest; diff --git a/src/Ocelot/Headers/Middleware/HttpHeadersTransformationMiddleware.cs b/src/Ocelot/Headers/Middleware/HttpHeadersTransformationMiddleware.cs index 4ac0fc8c..79684385 100644 --- a/src/Ocelot/Headers/Middleware/HttpHeadersTransformationMiddleware.cs +++ b/src/Ocelot/Headers/Middleware/HttpHeadersTransformationMiddleware.cs @@ -1,6 +1,6 @@ -using System.Threading.Tasks; using Ocelot.Logging; using Ocelot.Middleware; +using System.Threading.Tasks; namespace Ocelot.Headers.Middleware { @@ -17,8 +17,8 @@ namespace Ocelot.Headers.Middleware IHttpContextRequestHeaderReplacer preReplacer, IHttpResponseHeaderReplacer postReplacer, IAddHeadersToResponse addHeadersToResponse, - IAddHeadersToRequest addHeadersToRequest) - :base(loggerFactory.CreateLogger()) + IAddHeadersToRequest addHeadersToRequest) + : base(loggerFactory.CreateLogger()) { _addHeadersToResponse = addHeadersToResponse; _addHeadersToRequest = addHeadersToRequest; @@ -38,7 +38,7 @@ namespace Ocelot.Headers.Middleware await _next.Invoke(context); - if(context.IsError) + if (context.IsError) { return; } diff --git a/src/Ocelot/Headers/Middleware/HttpHeadersTransformationMiddlewareExtensions.cs b/src/Ocelot/Headers/Middleware/HttpHeadersTransformationMiddlewareExtensions.cs index 46bb84dc..4cfec462 100644 --- a/src/Ocelot/Headers/Middleware/HttpHeadersTransformationMiddlewareExtensions.cs +++ b/src/Ocelot/Headers/Middleware/HttpHeadersTransformationMiddlewareExtensions.cs @@ -10,4 +10,4 @@ namespace Ocelot.Headers.Middleware return builder.UseMiddleware(); } } -} +} diff --git a/src/Ocelot/Headers/RemoveOutputHeaders.cs b/src/Ocelot/Headers/RemoveOutputHeaders.cs index 2664b696..82cd0051 100644 --- a/src/Ocelot/Headers/RemoveOutputHeaders.cs +++ b/src/Ocelot/Headers/RemoveOutputHeaders.cs @@ -1,8 +1,7 @@ +using Ocelot.Middleware; +using Ocelot.Responses; using System.Collections.Generic; using System.Linq; -using Ocelot.Middleware; -using Ocelot.Middleware.Multiplexer; -using Ocelot.Responses; namespace Ocelot.Headers { @@ -13,7 +12,7 @@ namespace Ocelot.Headers /// in a given context such as transfer encoding chunked when ASP.NET is not /// returning the response in this manner /// - private readonly string[] _unsupportedRequestHeaders = + private readonly string[] _unsupportedRequestHeaders = { "Transfer-Encoding" }; @@ -24,4 +23,4 @@ namespace Ocelot.Headers return new OkResponse(); } } -} +} diff --git a/src/Ocelot/Infrastructure/CannotAddPlaceholderError.cs b/src/Ocelot/Infrastructure/CannotAddPlaceholderError.cs index 93ca6857..5ff14542 100644 --- a/src/Ocelot/Infrastructure/CannotAddPlaceholderError.cs +++ b/src/Ocelot/Infrastructure/CannotAddPlaceholderError.cs @@ -9,4 +9,4 @@ namespace Ocelot.Infrastructure { } } -} +} diff --git a/src/Ocelot/Infrastructure/Claims/Parser/CannotFindClaimError.cs b/src/Ocelot/Infrastructure/Claims/Parser/CannotFindClaimError.cs index 5314d394..302bba06 100644 --- a/src/Ocelot/Infrastructure/Claims/Parser/CannotFindClaimError.cs +++ b/src/Ocelot/Infrastructure/Claims/Parser/CannotFindClaimError.cs @@ -4,9 +4,9 @@ public class CannotFindClaimError : Error { - public CannotFindClaimError(string message) + public CannotFindClaimError(string message) : base(message, OcelotErrorCode.CannotFindClaimError) { } } -} +} diff --git a/src/Ocelot/Infrastructure/Claims/Parser/IClaimsParser.cs b/src/Ocelot/Infrastructure/Claims/Parser/IClaimsParser.cs index 1575ba20..05ec4f5d 100644 --- a/src/Ocelot/Infrastructure/Claims/Parser/IClaimsParser.cs +++ b/src/Ocelot/Infrastructure/Claims/Parser/IClaimsParser.cs @@ -1,12 +1,13 @@ namespace Ocelot.Infrastructure.Claims.Parser { + using Responses; using System.Collections.Generic; using System.Security.Claims; - using Responses; public interface IClaimsParser { Response GetValue(IEnumerable claims, string key, string delimiter, int index); + Response> GetValuesByClaimType(IEnumerable claims, string claimType); } -} \ No newline at end of file +} diff --git a/src/Ocelot/Infrastructure/CouldNotFindPlaceholderError.cs b/src/Ocelot/Infrastructure/CouldNotFindPlaceholderError.cs index c6214e83..5c7121aa 100644 --- a/src/Ocelot/Infrastructure/CouldNotFindPlaceholderError.cs +++ b/src/Ocelot/Infrastructure/CouldNotFindPlaceholderError.cs @@ -4,9 +4,9 @@ namespace Ocelot.Infrastructure { public class CouldNotFindPlaceholderError : Error { - public CouldNotFindPlaceholderError(string placeholder) + public CouldNotFindPlaceholderError(string placeholder) : base($"Unable to find placeholder called {placeholder}", OcelotErrorCode.CouldNotFindPlaceholderError) - { - } + { + } } -} \ No newline at end of file +} diff --git a/src/Ocelot/Infrastructure/Extensions/ErrorListExtensions.cs b/src/Ocelot/Infrastructure/Extensions/ErrorListExtensions.cs index 9c06d607..5d9f00f1 100644 --- a/src/Ocelot/Infrastructure/Extensions/ErrorListExtensions.cs +++ b/src/Ocelot/Infrastructure/Extensions/ErrorListExtensions.cs @@ -1,9 +1,6 @@ -using System; +using Ocelot.Errors; using System.Collections.Generic; using System.Linq; -using System.Text; -using Microsoft.Extensions.Primitives; -using Ocelot.Errors; namespace Ocelot.Infrastructure.Extensions { @@ -13,6 +10,6 @@ namespace Ocelot.Infrastructure.Extensions { var listOfErrorStrings = errors.Select(x => "Error Code: " + x.Code.ToString() + " Message: " + x.Message); return string.Join(" ", listOfErrorStrings); - } - } -} + } + } +} diff --git a/src/Ocelot/Infrastructure/Extensions/StringExtensions.cs b/src/Ocelot/Infrastructure/Extensions/StringExtensions.cs index 743c8c9e..099d3252 100644 --- a/src/Ocelot/Infrastructure/Extensions/StringExtensions.cs +++ b/src/Ocelot/Infrastructure/Extensions/StringExtensions.cs @@ -22,7 +22,7 @@ namespace Ocelot.Infrastructure.Extensions public static string LastCharAsForwardSlash(this string source) { - if(source.EndsWith('/')) + if (source.EndsWith('/')) { return source; } @@ -30,4 +30,4 @@ namespace Ocelot.Infrastructure.Extensions return $"{source}/"; } } -} \ No newline at end of file +} diff --git a/src/Ocelot/Infrastructure/IBus.cs b/src/Ocelot/Infrastructure/IBus.cs index 0fc227dd..5aa183d2 100644 --- a/src/Ocelot/Infrastructure/IBus.cs +++ b/src/Ocelot/Infrastructure/IBus.cs @@ -4,7 +4,8 @@ namespace Ocelot.Infrastructure { public interface IBus { - void Subscribe(Action action); + void Subscribe(Action action); + void Publish(T message, int delay); } } diff --git a/src/Ocelot/Infrastructure/IPlaceholders.cs b/src/Ocelot/Infrastructure/IPlaceholders.cs index 24b8e2ae..9d4b39ec 100644 --- a/src/Ocelot/Infrastructure/IPlaceholders.cs +++ b/src/Ocelot/Infrastructure/IPlaceholders.cs @@ -1,15 +1,17 @@ -using System; -using System.Net.Http; using Ocelot.Request.Middleware; using Ocelot.Responses; +using System; namespace Ocelot.Infrastructure { public interface IPlaceholders { Response Get(string key); + Response Get(string key, DownstreamRequest request); + Response Add(string key, Func> func); + Response Remove(string key); } } diff --git a/src/Ocelot/Infrastructure/InMemoryBus.cs b/src/Ocelot/Infrastructure/InMemoryBus.cs index c4dcc7a2..96ed9285 100644 --- a/src/Ocelot/Infrastructure/InMemoryBus.cs +++ b/src/Ocelot/Infrastructure/InMemoryBus.cs @@ -33,7 +33,7 @@ namespace Ocelot.Infrastructure private async Task Process() { - foreach(var delayedMessage in _queue.GetConsumingEnumerable()) + foreach (var delayedMessage in _queue.GetConsumingEnumerable()) { await Task.Delay(delayedMessage.Delay); diff --git a/src/Ocelot/Infrastructure/Placeholders.cs b/src/Ocelot/Infrastructure/Placeholders.cs index 4069eb26..3c319e6d 100644 --- a/src/Ocelot/Infrastructure/Placeholders.cs +++ b/src/Ocelot/Infrastructure/Placeholders.cs @@ -1,12 +1,12 @@ namespace Ocelot.Infrastructure { - using System; - using System.Collections.Generic; using Microsoft.AspNetCore.Http; using Ocelot.Infrastructure.RequestData; using Ocelot.Middleware; using Ocelot.Request.Middleware; using Ocelot.Responses; + using System; + using System.Collections.Generic; public class Placeholders : IPlaceholders { diff --git a/src/Ocelot/Infrastructure/RequestData/CannotAddDataError.cs b/src/Ocelot/Infrastructure/RequestData/CannotAddDataError.cs index b96db870..e411f0d4 100644 --- a/src/Ocelot/Infrastructure/RequestData/CannotAddDataError.cs +++ b/src/Ocelot/Infrastructure/RequestData/CannotAddDataError.cs @@ -8,4 +8,4 @@ namespace Ocelot.Infrastructure.RequestData { } } -} +} diff --git a/src/Ocelot/Infrastructure/RequestData/CannotFindDataError.cs b/src/Ocelot/Infrastructure/RequestData/CannotFindDataError.cs index d80230ea..907742df 100644 --- a/src/Ocelot/Infrastructure/RequestData/CannotFindDataError.cs +++ b/src/Ocelot/Infrastructure/RequestData/CannotFindDataError.cs @@ -8,4 +8,4 @@ namespace Ocelot.Infrastructure.RequestData { } } -} +} diff --git a/src/Ocelot/Infrastructure/RequestData/HttpDataRepository.cs b/src/Ocelot/Infrastructure/RequestData/HttpDataRepository.cs index ec2ce4e0..c14a1b78 100644 --- a/src/Ocelot/Infrastructure/RequestData/HttpDataRepository.cs +++ b/src/Ocelot/Infrastructure/RequestData/HttpDataRepository.cs @@ -1,8 +1,6 @@ -using System; -using System.Collections.Generic; -using Microsoft.AspNetCore.Http; -using Ocelot.Errors; +using Microsoft.AspNetCore.Http; using Ocelot.Responses; +using System; namespace Ocelot.Infrastructure.RequestData { @@ -45,18 +43,18 @@ namespace Ocelot.Infrastructure.RequestData { object obj; - if(_httpContextAccessor.HttpContext == null || _httpContextAccessor.HttpContext.Items == null) + if (_httpContextAccessor.HttpContext == null || _httpContextAccessor.HttpContext.Items == null) { return new ErrorResponse(new CannotFindDataError($"Unable to find data for key: {key} because HttpContext or HttpContext.Items is null")); } - if(_httpContextAccessor.HttpContext.Items.TryGetValue(key, out obj)) + if (_httpContextAccessor.HttpContext.Items.TryGetValue(key, out obj)) { - var data = (T) obj; + var data = (T)obj; return new OkResponse(data); } return new ErrorResponse(new CannotFindDataError($"Unable to find data for key: {key}")); } } -} +} diff --git a/src/Ocelot/Infrastructure/RequestData/IRequestScopedDataRepository.cs b/src/Ocelot/Infrastructure/RequestData/IRequestScopedDataRepository.cs index 1431b446..47443ed9 100644 --- a/src/Ocelot/Infrastructure/RequestData/IRequestScopedDataRepository.cs +++ b/src/Ocelot/Infrastructure/RequestData/IRequestScopedDataRepository.cs @@ -5,7 +5,9 @@ namespace Ocelot.Infrastructure.RequestData public interface IRequestScopedDataRepository { Response Add(string key, T value); + Response Update(string key, T value); + Response Get(string key); } -} \ No newline at end of file +} diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/CookieStickySessions.cs b/src/Ocelot/LoadBalancer/LoadBalancers/CookieStickySessions.cs index 357ea84e..775ed7ce 100644 --- a/src/Ocelot/LoadBalancer/LoadBalancers/CookieStickySessions.cs +++ b/src/Ocelot/LoadBalancer/LoadBalancers/CookieStickySessions.cs @@ -1,13 +1,11 @@ namespace Ocelot.LoadBalancer.LoadBalancers { - using System; - using System.Collections.Concurrent; - using System.Collections.Generic; - using System.Threading; - using System.Threading.Tasks; using Ocelot.Infrastructure; using Ocelot.Middleware; using Responses; + using System; + using System.Collections.Concurrent; + using System.Threading.Tasks; using Values; public class CookieStickySessions : ILoadBalancer diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/ILoadBalancer.cs b/src/Ocelot/LoadBalancer/LoadBalancers/ILoadBalancer.cs index d56367b2..4f8ec2b7 100644 --- a/src/Ocelot/LoadBalancer/LoadBalancers/ILoadBalancer.cs +++ b/src/Ocelot/LoadBalancer/LoadBalancers/ILoadBalancer.cs @@ -1,13 +1,14 @@ -using System.Threading.Tasks; using Ocelot.Middleware; using Ocelot.Responses; using Ocelot.Values; +using System.Threading.Tasks; namespace Ocelot.LoadBalancer.LoadBalancers { public interface ILoadBalancer { Task> Lease(DownstreamContext context); + void Release(ServiceHostAndPort hostAndPort); } } diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/ILoadBalancerFactory.cs b/src/Ocelot/LoadBalancer/LoadBalancers/ILoadBalancerFactory.cs index 7ca857f5..df115c41 100644 --- a/src/Ocelot/LoadBalancer/LoadBalancers/ILoadBalancerFactory.cs +++ b/src/Ocelot/LoadBalancer/LoadBalancers/ILoadBalancerFactory.cs @@ -1,8 +1,8 @@ namespace Ocelot.LoadBalancer.LoadBalancers { - using System.Threading.Tasks; using Ocelot.Configuration; using Ocelot.Responses; + using System.Threading.Tasks; public interface ILoadBalancerFactory { diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/ILoadBalancerHouse.cs b/src/Ocelot/LoadBalancer/LoadBalancers/ILoadBalancerHouse.cs index 7f8d7381..92eb0e9e 100644 --- a/src/Ocelot/LoadBalancer/LoadBalancers/ILoadBalancerHouse.cs +++ b/src/Ocelot/LoadBalancer/LoadBalancers/ILoadBalancerHouse.cs @@ -1,6 +1,6 @@ -using System.Threading.Tasks; -using Ocelot.Configuration; +using Ocelot.Configuration; using Ocelot.Responses; +using System.Threading.Tasks; namespace Ocelot.LoadBalancer.LoadBalancers { diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/Lease.cs b/src/Ocelot/LoadBalancer/LoadBalancers/Lease.cs index 2713d44b..94bfd97e 100644 --- a/src/Ocelot/LoadBalancer/LoadBalancers/Lease.cs +++ b/src/Ocelot/LoadBalancer/LoadBalancers/Lease.cs @@ -13,4 +13,4 @@ namespace Ocelot.LoadBalancer.LoadBalancers public ServiceHostAndPort HostAndPort { get; private set; } public int Connections { get; private set; } } -} +} diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/LeastConnection.cs b/src/Ocelot/LoadBalancer/LoadBalancers/LeastConnection.cs index 59f260ca..ee7c0fdd 100644 --- a/src/Ocelot/LoadBalancer/LoadBalancers/LeastConnection.cs +++ b/src/Ocelot/LoadBalancer/LoadBalancers/LeastConnection.cs @@ -1,11 +1,10 @@ -using System; +using Ocelot.Middleware; +using Ocelot.Responses; +using Ocelot.Values; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Ocelot.Errors; -using Ocelot.Middleware; -using Ocelot.Responses; -using Ocelot.Values; namespace Ocelot.LoadBalancer.LoadBalancers { @@ -29,7 +28,7 @@ namespace Ocelot.LoadBalancer.LoadBalancers if (services == null) { - return new ErrorResponse(new ServicesAreNullError($"services were null for {_serviceName}") ); + return new ErrorResponse(new ServicesAreNullError($"services were null for {_serviceName}")); } if (!services.Any()) @@ -37,8 +36,8 @@ namespace Ocelot.LoadBalancer.LoadBalancers return new ErrorResponse(new ServicesAreEmptyError($"services were empty for {_serviceName}")); } - lock(_syncLock) - { + lock (_syncLock) + { //todo - maybe this should be moved somewhere else...? Maybe on a repeater on seperate thread? loop every second and update or something? UpdateServices(services); @@ -49,14 +48,14 @@ namespace Ocelot.LoadBalancer.LoadBalancers leaseWithLeastConnections = AddConnection(leaseWithLeastConnections); _leases.Add(leaseWithLeastConnections); - + return new OkResponse(new ServiceHostAndPort(leaseWithLeastConnections.HostAndPort.DownstreamHost, leaseWithLeastConnections.HostAndPort.DownstreamPort)); } } public void Release(ServiceHostAndPort hostAndPort) { - lock(_syncLock) + lock (_syncLock) { var matchingLease = _leases.FirstOrDefault(l => l.HostAndPort.DownstreamHost == hostAndPort.DownstreamHost && l.HostAndPort.DownstreamPort == hostAndPort.DownstreamPort); diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/LoadBalancerFactory.cs b/src/Ocelot/LoadBalancer/LoadBalancers/LoadBalancerFactory.cs index dce8d405..12725a57 100644 --- a/src/Ocelot/LoadBalancer/LoadBalancers/LoadBalancerFactory.cs +++ b/src/Ocelot/LoadBalancer/LoadBalancers/LoadBalancerFactory.cs @@ -1,8 +1,8 @@ -using System.Threading.Tasks; -using Ocelot.Configuration; +using Ocelot.Configuration; using Ocelot.Infrastructure; using Ocelot.Responses; using Ocelot.ServiceDiscovery; +using System.Threading.Tasks; namespace Ocelot.LoadBalancer.LoadBalancers { @@ -16,10 +16,10 @@ namespace Ocelot.LoadBalancer.LoadBalancers } public async Task> Get(DownstreamReRoute reRoute, ServiceProviderConfiguration config) - { + { var response = _serviceProviderFactory.Get(config, reRoute); - if(response.IsError) + if (response.IsError) { return new ErrorResponse(response.Errors); } @@ -30,12 +30,15 @@ namespace Ocelot.LoadBalancer.LoadBalancers { case nameof(RoundRobin): return new OkResponse(new RoundRobin(async () => await serviceProvider.Get())); + case nameof(LeastConnection): return new OkResponse(new LeastConnection(async () => await serviceProvider.Get(), reRoute.ServiceName)); + case nameof(CookieStickySessions): var loadBalancer = new RoundRobin(async () => await serviceProvider.Get()); var bus = new InMemoryBus(); return new OkResponse(new CookieStickySessions(loadBalancer, reRoute.LoadBalancerOptions.Key, reRoute.LoadBalancerOptions.ExpiryInMs, bus)); + default: return new OkResponse(new NoLoadBalancer(async () => await serviceProvider.Get())); } diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/NoLoadBalancer.cs b/src/Ocelot/LoadBalancer/LoadBalancers/NoLoadBalancer.cs index c24a50d2..112fd5bb 100644 --- a/src/Ocelot/LoadBalancer/LoadBalancers/NoLoadBalancer.cs +++ b/src/Ocelot/LoadBalancer/LoadBalancers/NoLoadBalancer.cs @@ -1,10 +1,10 @@ -using System; +using Ocelot.Middleware; +using Ocelot.Responses; +using Ocelot.Values; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Ocelot.Middleware; -using Ocelot.Responses; -using Ocelot.Values; namespace Ocelot.LoadBalancer.LoadBalancers { diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/RoundRobin.cs b/src/Ocelot/LoadBalancer/LoadBalancers/RoundRobin.cs index b130f6fe..3500efe0 100644 --- a/src/Ocelot/LoadBalancer/LoadBalancers/RoundRobin.cs +++ b/src/Ocelot/LoadBalancer/LoadBalancers/RoundRobin.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic; -using System.Threading.Tasks; +using Ocelot.Middleware; using Ocelot.Responses; using Ocelot.Values; using System; -using Ocelot.Middleware; +using System.Collections.Generic; +using System.Threading.Tasks; namespace Ocelot.LoadBalancer.LoadBalancers { @@ -22,7 +22,7 @@ namespace Ocelot.LoadBalancer.LoadBalancers public async Task> Lease(DownstreamContext downstreamContext) { var services = await _services(); - lock(_lock) + lock (_lock) { if (_last >= services.Count) { diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/StickySession.cs b/src/Ocelot/LoadBalancer/LoadBalancers/StickySession.cs index bce476c0..6f487ec7 100644 --- a/src/Ocelot/LoadBalancer/LoadBalancers/StickySession.cs +++ b/src/Ocelot/LoadBalancer/LoadBalancers/StickySession.cs @@ -1,5 +1,5 @@ -using System; using Ocelot.Values; +using System; namespace Ocelot.LoadBalancer.LoadBalancers { @@ -13,9 +13,9 @@ namespace Ocelot.LoadBalancer.LoadBalancers } public ServiceHostAndPort HostAndPort { get; } - + public DateTime Expiry { get; } - public string Key {get;} + public string Key { get; } } } diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/UnableToFindLoadBalancerError.cs b/src/Ocelot/LoadBalancer/LoadBalancers/UnableToFindLoadBalancerError.cs index 8ce7bcd4..04a305f5 100644 --- a/src/Ocelot/LoadBalancer/LoadBalancers/UnableToFindLoadBalancerError.cs +++ b/src/Ocelot/LoadBalancer/LoadBalancers/UnableToFindLoadBalancerError.cs @@ -4,9 +4,9 @@ namespace Ocelot.LoadBalancer.LoadBalancers { public class UnableToFindLoadBalancerError : Errors.Error { - public UnableToFindLoadBalancerError(string message) + public UnableToFindLoadBalancerError(string message) : base(message, OcelotErrorCode.UnableToFindLoadBalancerError) { } } -} +} diff --git a/src/Ocelot/LoadBalancer/Middleware/LoadBalancingMiddleware.cs b/src/Ocelot/LoadBalancer/Middleware/LoadBalancingMiddleware.cs index 9568b9cf..22456430 100644 --- a/src/Ocelot/LoadBalancer/Middleware/LoadBalancingMiddleware.cs +++ b/src/Ocelot/LoadBalancer/Middleware/LoadBalancingMiddleware.cs @@ -1,8 +1,8 @@ -using System; -using System.Threading.Tasks; -using Ocelot.LoadBalancer.LoadBalancers; +using Ocelot.LoadBalancer.LoadBalancers; using Ocelot.Logging; using Ocelot.Middleware; +using System; +using System.Threading.Tasks; namespace Ocelot.LoadBalancer.Middleware { @@ -13,8 +13,8 @@ namespace Ocelot.LoadBalancer.Middleware public LoadBalancingMiddleware(OcelotRequestDelegate next, IOcelotLoggerFactory loggerFactory, - ILoadBalancerHouse loadBalancerHouse) - :base(loggerFactory.CreateLogger()) + ILoadBalancerHouse loadBalancerHouse) + : base(loggerFactory.CreateLogger()) { _next = next; _loadBalancerHouse = loadBalancerHouse; @@ -23,7 +23,7 @@ namespace Ocelot.LoadBalancer.Middleware public async Task Invoke(DownstreamContext context) { var loadBalancer = await _loadBalancerHouse.Get(context.DownstreamReRoute, context.Configuration.ServiceProviderConfiguration); - if(loadBalancer.IsError) + if (loadBalancer.IsError) { Logger.LogDebug("there was an error retriving the loadbalancer, setting pipeline error"); SetPipelineError(context, loadBalancer.Errors); @@ -31,7 +31,7 @@ namespace Ocelot.LoadBalancer.Middleware } var hostAndPort = await loadBalancer.Data.Lease(context); - if(hostAndPort.IsError) + if (hostAndPort.IsError) { Logger.LogDebug("there was an error leasing the loadbalancer, setting pipeline error"); SetPipelineError(context, hostAndPort.Errors); diff --git a/src/Ocelot/LoadBalancer/Middleware/LoadBalancingMiddlewareExtensions.cs b/src/Ocelot/LoadBalancer/Middleware/LoadBalancingMiddlewareExtensions.cs index a2da1060..8f6558c7 100644 --- a/src/Ocelot/LoadBalancer/Middleware/LoadBalancingMiddlewareExtensions.cs +++ b/src/Ocelot/LoadBalancer/Middleware/LoadBalancingMiddlewareExtensions.cs @@ -2,12 +2,12 @@ using Microsoft.AspNetCore.Builder; using Ocelot.Middleware.Pipeline; namespace Ocelot.LoadBalancer.Middleware -{ - public static class LoadBalancingMiddlewareExtensions +{ + public static class LoadBalancingMiddlewareExtensions { public static IOcelotPipelineBuilder UseLoadBalancingMiddleware(this IOcelotPipelineBuilder builder) { return builder.UseMiddleware(); } } -} +} diff --git a/src/Ocelot/Logging/AspDotNetLogger.cs b/src/Ocelot/Logging/AspDotNetLogger.cs index 5ee04e13..598cbdd0 100644 --- a/src/Ocelot/Logging/AspDotNetLogger.cs +++ b/src/Ocelot/Logging/AspDotNetLogger.cs @@ -1,6 +1,6 @@ -using System; using Microsoft.Extensions.Logging; using Ocelot.Infrastructure.RequestData; +using System; namespace Ocelot.Logging { @@ -16,21 +16,21 @@ namespace Ocelot.Logging } public void LogTrace(string message) - { + { var requestId = GetOcelotRequestId(); var previousRequestId = GetOcelotPreviousRequestId(); _logger.LogTrace("requestId: {requestId}, previousRequestId: {previousRequestId}, message: {message}", requestId, previousRequestId, message); } public void LogDebug(string message) - { + { var requestId = GetOcelotRequestId(); var previousRequestId = GetOcelotPreviousRequestId(); _logger.LogDebug("requestId: {requestId}, previousRequestId: {previousRequestId}, message: {message}", requestId, previousRequestId, message); } public void LogInformation(string message) - { + { var requestId = GetOcelotRequestId(); var previousRequestId = GetOcelotPreviousRequestId(); _logger.LogInformation("requestId: {requestId}, previousRequestId: {previousRequestId}, message: {message}", requestId, previousRequestId, message); @@ -81,4 +81,4 @@ namespace Ocelot.Logging return requestId.Data; } } -} +} diff --git a/src/Ocelot/Logging/IOcelotLogger.cs b/src/Ocelot/Logging/IOcelotLogger.cs index 7d1c1205..9ffced20 100644 --- a/src/Ocelot/Logging/IOcelotLogger.cs +++ b/src/Ocelot/Logging/IOcelotLogger.cs @@ -8,10 +8,15 @@ namespace Ocelot.Logging public interface IOcelotLogger { void LogTrace(string message); + void LogDebug(string message); + void LogInformation(string message); + void LogWarning(string message); + void LogError(string message, Exception exception); + void LogCritical(string message, Exception exception); } } diff --git a/src/Ocelot/Logging/IOcelotLoggerFactory.cs b/src/Ocelot/Logging/IOcelotLoggerFactory.cs index 2407afcd..7b7c6c39 100644 --- a/src/Ocelot/Logging/IOcelotLoggerFactory.cs +++ b/src/Ocelot/Logging/IOcelotLoggerFactory.cs @@ -4,4 +4,4 @@ { IOcelotLogger CreateLogger(); } -} +} diff --git a/src/Ocelot/Logging/ITracer.cs b/src/Ocelot/Logging/ITracer.cs index 9e035d75..6dbf9149 100644 --- a/src/Ocelot/Logging/ITracer.cs +++ b/src/Ocelot/Logging/ITracer.cs @@ -1,10 +1,10 @@ namespace Ocelot.Logging { + using Microsoft.AspNetCore.Http; using System; using System.Net.Http; using System.Threading; using System.Threading.Tasks; - using Microsoft.AspNetCore.Http; public interface ITracer { diff --git a/src/Ocelot/Logging/OcelotDiagnosticListener.cs b/src/Ocelot/Logging/OcelotDiagnosticListener.cs index 8a5c0215..09beac49 100644 --- a/src/Ocelot/Logging/OcelotDiagnosticListener.cs +++ b/src/Ocelot/Logging/OcelotDiagnosticListener.cs @@ -1,8 +1,8 @@ -using System; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.DiagnosticAdapter; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DiagnosticAdapter; using Ocelot.Middleware; +using System; namespace Ocelot.Logging { diff --git a/src/Ocelot/Middleware/BaseUrlFinder.cs b/src/Ocelot/Middleware/BaseUrlFinder.cs index fe3acea7..d65fb769 100644 --- a/src/Ocelot/Middleware/BaseUrlFinder.cs +++ b/src/Ocelot/Middleware/BaseUrlFinder.cs @@ -20,4 +20,4 @@ namespace Ocelot.Middleware return string.IsNullOrEmpty(baseUrl) ? _config.GetValue("BaseUrl", "http://localhost:5000") : baseUrl; } } -} +} diff --git a/src/Ocelot/Middleware/DownstreamContext.cs b/src/Ocelot/Middleware/DownstreamContext.cs index eb21b4bb..5a2dc34a 100644 --- a/src/Ocelot/Middleware/DownstreamContext.cs +++ b/src/Ocelot/Middleware/DownstreamContext.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic; using Microsoft.AspNetCore.Http; using Ocelot.Configuration; using Ocelot.DownstreamRouteFinder.UrlMatcher; using Ocelot.Errors; using Ocelot.Request.Middleware; +using System.Collections.Generic; namespace Ocelot.Middleware { diff --git a/src/Ocelot/Middleware/DownstreamResponse.cs b/src/Ocelot/Middleware/DownstreamResponse.cs index c58a5198..3a27f6c9 100644 --- a/src/Ocelot/Middleware/DownstreamResponse.cs +++ b/src/Ocelot/Middleware/DownstreamResponse.cs @@ -16,18 +16,18 @@ namespace Ocelot.Middleware } public DownstreamResponse(HttpResponseMessage response) - :this(response.Content, response.StatusCode, response.Headers.Select(x => new Header(x.Key, x.Value)).ToList(), response.ReasonPhrase) + : this(response.Content, response.StatusCode, response.Headers.Select(x => new Header(x.Key, x.Value)).ToList(), response.ReasonPhrase) { } public DownstreamResponse(HttpContent content, HttpStatusCode statusCode, IEnumerable>> headers, string reasonPhrase) - :this(content, statusCode, headers.Select(x => new Header(x.Key, x.Value)).ToList(), reasonPhrase) + : this(content, statusCode, headers.Select(x => new Header(x.Key, x.Value)).ToList(), reasonPhrase) { } public HttpContent Content { get; } public HttpStatusCode StatusCode { get; } public List
Headers { get; } - public string ReasonPhrase {get;} + public string ReasonPhrase { get; } } } diff --git a/src/Ocelot/Middleware/Multiplexer/CouldNotFindAggregatorError.cs b/src/Ocelot/Middleware/Multiplexer/CouldNotFindAggregatorError.cs index 76a19d7c..e32109b7 100644 --- a/src/Ocelot/Middleware/Multiplexer/CouldNotFindAggregatorError.cs +++ b/src/Ocelot/Middleware/Multiplexer/CouldNotFindAggregatorError.cs @@ -4,7 +4,7 @@ namespace Ocelot.Middleware.Multiplexer { public class CouldNotFindAggregatorError : Error { - public CouldNotFindAggregatorError(string aggregator) + public CouldNotFindAggregatorError(string aggregator) : base($"Could not find Aggregator: {aggregator}", OcelotErrorCode.CouldNotFindAggregatorError) { } diff --git a/src/Ocelot/Middleware/Multiplexer/IMultiplexer.cs b/src/Ocelot/Middleware/Multiplexer/IMultiplexer.cs index f3a2975d..57a724e2 100644 --- a/src/Ocelot/Middleware/Multiplexer/IMultiplexer.cs +++ b/src/Ocelot/Middleware/Multiplexer/IMultiplexer.cs @@ -1,5 +1,5 @@ -using System.Threading.Tasks; -using Ocelot.Configuration; +using Ocelot.Configuration; +using System.Threading.Tasks; namespace Ocelot.Middleware.Multiplexer { diff --git a/src/Ocelot/Middleware/Multiplexer/IResponseAggregator.cs b/src/Ocelot/Middleware/Multiplexer/IResponseAggregator.cs index 89f2b00b..bd56ca09 100644 --- a/src/Ocelot/Middleware/Multiplexer/IResponseAggregator.cs +++ b/src/Ocelot/Middleware/Multiplexer/IResponseAggregator.cs @@ -1,6 +1,6 @@ -using System.Collections.Generic; +using Ocelot.Configuration; +using System.Collections.Generic; using System.Threading.Tasks; -using Ocelot.Configuration; namespace Ocelot.Middleware.Multiplexer { diff --git a/src/Ocelot/Middleware/Multiplexer/InMemoryResponseAggregatorFactory.cs b/src/Ocelot/Middleware/Multiplexer/InMemoryResponseAggregatorFactory.cs index b9721e1b..ce426d86 100644 --- a/src/Ocelot/Middleware/Multiplexer/InMemoryResponseAggregatorFactory.cs +++ b/src/Ocelot/Middleware/Multiplexer/InMemoryResponseAggregatorFactory.cs @@ -15,7 +15,7 @@ namespace Ocelot.Middleware.Multiplexer public IResponseAggregator Get(ReRoute reRoute) { - if(!string.IsNullOrEmpty(reRoute.Aggregator)) + if (!string.IsNullOrEmpty(reRoute.Aggregator)) { return _userDefined; } diff --git a/src/Ocelot/Middleware/Multiplexer/Multiplexer.cs b/src/Ocelot/Middleware/Multiplexer/Multiplexer.cs index d61678e3..a49e20c1 100644 --- a/src/Ocelot/Middleware/Multiplexer/Multiplexer.cs +++ b/src/Ocelot/Middleware/Multiplexer/Multiplexer.cs @@ -1,9 +1,8 @@ -using System.Collections.Generic; +using Ocelot.Configuration; +using Ocelot.DownstreamRouteFinder.UrlMatcher; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Newtonsoft.Json.Linq; -using Ocelot.Configuration; -using Ocelot.DownstreamRouteFinder.UrlMatcher; namespace Ocelot.Middleware.Multiplexer { diff --git a/src/Ocelot/Middleware/Multiplexer/ServiceLocatorDefinedAggregatorProvider.cs b/src/Ocelot/Middleware/Multiplexer/ServiceLocatorDefinedAggregatorProvider.cs index b7b85d26..c02a4bf7 100644 --- a/src/Ocelot/Middleware/Multiplexer/ServiceLocatorDefinedAggregatorProvider.cs +++ b/src/Ocelot/Middleware/Multiplexer/ServiceLocatorDefinedAggregatorProvider.cs @@ -1,9 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; using Microsoft.Extensions.DependencyInjection; using Ocelot.Configuration; using Ocelot.Responses; +using System; +using System.Collections.Generic; +using System.Linq; namespace Ocelot.Middleware.Multiplexer { @@ -18,7 +18,7 @@ namespace Ocelot.Middleware.Multiplexer public Response Get(ReRoute reRoute) { - if(_aggregators.ContainsKey(reRoute.Aggregator)) + if (_aggregators.ContainsKey(reRoute.Aggregator)) { return new OkResponse(_aggregators[reRoute.Aggregator]); } diff --git a/src/Ocelot/Middleware/Multiplexer/SimpleJsonResponseAggregator.cs b/src/Ocelot/Middleware/Multiplexer/SimpleJsonResponseAggregator.cs index 8524519e..f03b52c5 100644 --- a/src/Ocelot/Middleware/Multiplexer/SimpleJsonResponseAggregator.cs +++ b/src/Ocelot/Middleware/Multiplexer/SimpleJsonResponseAggregator.cs @@ -1,11 +1,11 @@ -using System.Collections.Generic; +using Ocelot.Configuration; +using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; -using Ocelot.Configuration; namespace Ocelot.Middleware.Multiplexer { diff --git a/src/Ocelot/Middleware/Multiplexer/UserDefinedResponseAggregator.cs b/src/Ocelot/Middleware/Multiplexer/UserDefinedResponseAggregator.cs index 0080b60e..47c07c00 100644 --- a/src/Ocelot/Middleware/Multiplexer/UserDefinedResponseAggregator.cs +++ b/src/Ocelot/Middleware/Multiplexer/UserDefinedResponseAggregator.cs @@ -1,6 +1,6 @@ +using Ocelot.Configuration; using System.Collections.Generic; using System.Threading.Tasks; -using Ocelot.Configuration; namespace Ocelot.Middleware.Multiplexer { diff --git a/src/Ocelot/Middleware/OcelotMiddleware.cs b/src/Ocelot/Middleware/OcelotMiddleware.cs index fe51fd24..0bf57afc 100644 --- a/src/Ocelot/Middleware/OcelotMiddleware.cs +++ b/src/Ocelot/Middleware/OcelotMiddleware.cs @@ -1,11 +1,11 @@ -using System.Collections.Generic; -using Ocelot.Errors; +using Ocelot.Errors; using Ocelot.Logging; +using System.Collections.Generic; namespace Ocelot.Middleware { public abstract class OcelotMiddleware - { + { protected OcelotMiddleware(IOcelotLogger logger) { Logger = logger; @@ -18,7 +18,7 @@ namespace Ocelot.Middleware public void SetPipelineError(DownstreamContext context, List errors) { - foreach(var error in errors) + foreach (var error in errors) { SetPipelineError(context, error); } @@ -30,4 +30,4 @@ namespace Ocelot.Middleware context.Errors.Add(error); } } -} +} diff --git a/src/Ocelot/Middleware/OcelotMiddlewareConfigurationDelegate.cs b/src/Ocelot/Middleware/OcelotMiddlewareConfigurationDelegate.cs index f0dbb5c1..f5e2061d 100644 --- a/src/Ocelot/Middleware/OcelotMiddlewareConfigurationDelegate.cs +++ b/src/Ocelot/Middleware/OcelotMiddlewareConfigurationDelegate.cs @@ -1,7 +1,7 @@ namespace Ocelot.Middleware { - using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; + using System.Threading.Tasks; public delegate Task OcelotMiddlewareConfigurationDelegate(IApplicationBuilder builder); } diff --git a/src/Ocelot/Middleware/Pipeline/IOcelotPipelineBuilder.cs b/src/Ocelot/Middleware/Pipeline/IOcelotPipelineBuilder.cs index a10a2369..b7199e2b 100644 --- a/src/Ocelot/Middleware/Pipeline/IOcelotPipelineBuilder.cs +++ b/src/Ocelot/Middleware/Pipeline/IOcelotPipelineBuilder.cs @@ -9,8 +9,11 @@ namespace Ocelot.Middleware.Pipeline public interface IOcelotPipelineBuilder { IServiceProvider ApplicationServices { get; } + IOcelotPipelineBuilder Use(Func middleware); + OcelotRequestDelegate Build(); + IOcelotPipelineBuilder New(); } } diff --git a/src/Ocelot/Middleware/Pipeline/OcelotPipelineBuilder.cs b/src/Ocelot/Middleware/Pipeline/OcelotPipelineBuilder.cs index 58f71122..5e3ee32e 100644 --- a/src/Ocelot/Middleware/Pipeline/OcelotPipelineBuilder.cs +++ b/src/Ocelot/Middleware/Pipeline/OcelotPipelineBuilder.cs @@ -19,7 +19,7 @@ namespace Ocelot.Middleware.Pipeline _middlewares = new List>(); } - public OcelotPipelineBuilder(IOcelotPipelineBuilder builder) + public OcelotPipelineBuilder(IOcelotPipelineBuilder builder) { ApplicationServices = builder.ApplicationServices; _middlewares = new List>(); diff --git a/src/Ocelot/Middleware/Pipeline/OcelotPipelineExtensions.cs b/src/Ocelot/Middleware/Pipeline/OcelotPipelineExtensions.cs index a35dc41f..b75a5b1d 100644 --- a/src/Ocelot/Middleware/Pipeline/OcelotPipelineExtensions.cs +++ b/src/Ocelot/Middleware/Pipeline/OcelotPipelineExtensions.cs @@ -1,6 +1,4 @@ -using System; -using System.Threading.Tasks; -using Ocelot.Authentication.Middleware; +using Ocelot.Authentication.Middleware; using Ocelot.Authorisation.Middleware; using Ocelot.Cache.Middleware; using Ocelot.Claims.Middleware; @@ -17,6 +15,8 @@ using Ocelot.RequestId.Middleware; using Ocelot.Responder.Middleware; using Ocelot.Security.Middleware; using Ocelot.WebSockets.Middleware; +using System; +using System.Threading.Tasks; namespace Ocelot.Middleware.Pipeline { @@ -96,7 +96,7 @@ namespace Ocelot.Middleware.Pipeline // Allow pre authorisation logic. The idea being people might want to run something custom before what is built in. builder.UseIfNotNull(pipelineConfiguration.PreAuthorisationMiddleware); - // Now we have authenticated and done any claims transformation we + // Now we have authenticated and done any claims transformation we // can authorise the request // We allow the ocelot middleware to be overriden by whatever the // user wants @@ -124,7 +124,7 @@ namespace Ocelot.Middleware.Pipeline // This takes the downstream route we retrieved earlier and replaces any placeholders with the variables that should be used builder.UseDownstreamUrlCreatorMiddleware(); - // Not sure if this is the best place for this but we use the downstream url + // Not sure if this is the best place for this but we use the downstream url // as the basis for our cache key. builder.UseOutputCacheMiddleware(); diff --git a/src/Ocelot/Middleware/UnauthenticatedError.cs b/src/Ocelot/Middleware/UnauthenticatedError.cs index d99d7503..f6ee444b 100644 --- a/src/Ocelot/Middleware/UnauthenticatedError.cs +++ b/src/Ocelot/Middleware/UnauthenticatedError.cs @@ -8,4 +8,4 @@ namespace Ocelot.Middleware { } } -} +} diff --git a/src/Ocelot/Properties/AssemblyInfo.cs b/src/Ocelot/Properties/AssemblyInfo.cs index cf28a510..c2a11a5b 100644 --- a/src/Ocelot/Properties/AssemblyInfo.cs +++ b/src/Ocelot/Properties/AssemblyInfo.cs @@ -15,4 +15,4 @@ using System.Runtime.InteropServices; [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("d6df4206-0dba-41d8-884d-c3e08290fdbb")] +[assembly: Guid("d6df4206-0dba-41d8-884d-c3e08290fdbb")] diff --git a/src/Ocelot/QueryStrings/AddQueriesToRequest.cs b/src/Ocelot/QueryStrings/AddQueriesToRequest.cs index 3cc2abdf..3df7ffb7 100644 --- a/src/Ocelot/QueryStrings/AddQueriesToRequest.cs +++ b/src/Ocelot/QueryStrings/AddQueriesToRequest.cs @@ -1,14 +1,11 @@ -using System.Collections.Generic; -using System.Linq; -using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Primitives; using Ocelot.Configuration; using Ocelot.Infrastructure.Claims.Parser; -using Ocelot.Responses; -using System.Security.Claims; -using System.Net.Http; -using System; using Ocelot.Request.Middleware; -using Microsoft.Extensions.Primitives; +using Ocelot.Responses; +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; using System.Text; namespace Ocelot.QueryStrings @@ -64,8 +61,8 @@ namespace Ocelot.QueryStrings { var builder = new StringBuilder(); - builder.Append("?"); - + builder.Append("?"); + int outerCount = 0; foreach (var query in queryDictionary) @@ -74,13 +71,13 @@ namespace Ocelot.QueryStrings { builder.Append($"{query.Key}={query.Value[innerCount]}"); - if(innerCount < (query.Value.Count - 1)) + if (innerCount < (query.Value.Count - 1)) { builder.Append("&"); } } - if(outerCount < (queryDictionary.Count - 1)) + if (outerCount < (queryDictionary.Count - 1)) { builder.Append("&"); } @@ -91,4 +88,4 @@ namespace Ocelot.QueryStrings return builder.ToString(); } } -} +} diff --git a/src/Ocelot/QueryStrings/IAddQueriesToRequest.cs b/src/Ocelot/QueryStrings/IAddQueriesToRequest.cs index bc017936..03c634ba 100644 --- a/src/Ocelot/QueryStrings/IAddQueriesToRequest.cs +++ b/src/Ocelot/QueryStrings/IAddQueriesToRequest.cs @@ -1,10 +1,8 @@ -using System.Collections.Generic; -using Microsoft.AspNetCore.Http; -using Ocelot.Configuration; -using Ocelot.Responses; -using System.Net.Http; -using System.Security.Claims; +using Ocelot.Configuration; using Ocelot.Request.Middleware; +using Ocelot.Responses; +using System.Collections.Generic; +using System.Security.Claims; namespace Ocelot.QueryStrings { @@ -12,4 +10,4 @@ namespace Ocelot.QueryStrings { Response SetQueriesOnDownstreamRequest(List claimsToThings, IEnumerable claims, DownstreamRequest downstreamRequest); } -} +} diff --git a/src/Ocelot/QueryStrings/Middleware/ClaimsToQueryStringMiddleware.cs b/src/Ocelot/QueryStrings/Middleware/ClaimsToQueryStringMiddleware.cs index 6af29464..4e1a1218 100644 --- a/src/Ocelot/QueryStrings/Middleware/ClaimsToQueryStringMiddleware.cs +++ b/src/Ocelot/QueryStrings/Middleware/ClaimsToQueryStringMiddleware.cs @@ -1,12 +1,9 @@ namespace Ocelot.QueryStrings.Middleware { - using System.Linq; - using System.Threading.Tasks; - using Microsoft.AspNetCore.Http; - using Ocelot.DownstreamRouteFinder.Middleware; - using Ocelot.Infrastructure.RequestData; using Ocelot.Logging; using Ocelot.Middleware; + using System.Linq; + using System.Threading.Tasks; public class ClaimsToQueryStringMiddleware : OcelotMiddleware { @@ -15,7 +12,7 @@ public ClaimsToQueryStringMiddleware(OcelotRequestDelegate next, IOcelotLoggerFactory loggerFactory, - IAddQueriesToRequest addQueriesToRequest) + IAddQueriesToRequest addQueriesToRequest) : base(loggerFactory.CreateLogger()) { _next = next; diff --git a/src/Ocelot/RateLimit/ClientRateLimitProcessor.cs b/src/Ocelot/RateLimit/ClientRateLimitProcessor.cs index 65a04504..06393ddb 100644 --- a/src/Ocelot/RateLimit/ClientRateLimitProcessor.cs +++ b/src/Ocelot/RateLimit/ClientRateLimitProcessor.cs @@ -1,9 +1,6 @@ using Microsoft.AspNetCore.Http; using Ocelot.Configuration; using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace Ocelot.RateLimit { @@ -38,4 +35,4 @@ namespace Ocelot.RateLimit return _core.ConvertToTimeSpan(timeSpan); } } -} +} diff --git a/src/Ocelot/RateLimit/DistributedCacheRateLimitCounterHanlder.cs b/src/Ocelot/RateLimit/DistributedCacheRateLimitCounterHanlder.cs index 91f933b7..d9eddfe3 100644 --- a/src/Ocelot/RateLimit/DistributedCacheRateLimitCounterHanlder.cs +++ b/src/Ocelot/RateLimit/DistributedCacheRateLimitCounterHanlder.cs @@ -1,9 +1,6 @@ using Microsoft.Extensions.Caching.Distributed; using Newtonsoft.Json; using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace Ocelot.RateLimit { @@ -43,4 +40,4 @@ namespace Ocelot.RateLimit _memoryCache.Remove(id); } } -} +} diff --git a/src/Ocelot/RateLimit/IRateLimitCounterHandler.cs b/src/Ocelot/RateLimit/IRateLimitCounterHandler.cs index 5ab7a5da..e4b4da0d 100644 --- a/src/Ocelot/RateLimit/IRateLimitCounterHandler.cs +++ b/src/Ocelot/RateLimit/IRateLimitCounterHandler.cs @@ -1,15 +1,15 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace Ocelot.RateLimit { public interface IRateLimitCounterHandler { bool Exists(string id); + RateLimitCounter? Get(string id); + void Remove(string id); + void Set(string id, RateLimitCounter counter, TimeSpan expirationTime); } -} +} diff --git a/src/Ocelot/RateLimit/MemoryCacheRateLimitCounterHandler.cs b/src/Ocelot/RateLimit/MemoryCacheRateLimitCounterHandler.cs index fdeeef66..f71766c8 100644 --- a/src/Ocelot/RateLimit/MemoryCacheRateLimitCounterHandler.cs +++ b/src/Ocelot/RateLimit/MemoryCacheRateLimitCounterHandler.cs @@ -1,8 +1,5 @@ using Microsoft.Extensions.Caching.Memory; using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace Ocelot.RateLimit { @@ -42,4 +39,4 @@ namespace Ocelot.RateLimit _memoryCache.Remove(id); } } -} +} diff --git a/src/Ocelot/RateLimit/Middleware/ClientRateLimitMiddleware.cs b/src/Ocelot/RateLimit/Middleware/ClientRateLimitMiddleware.cs index 4647644e..5437ca11 100644 --- a/src/Ocelot/RateLimit/Middleware/ClientRateLimitMiddleware.cs +++ b/src/Ocelot/RateLimit/Middleware/ClientRateLimitMiddleware.cs @@ -1,13 +1,9 @@ -using Ocelot.Middleware; -using System; -using System.Collections.Generic; +using Microsoft.AspNetCore.Http; +using Ocelot.Configuration; +using Ocelot.Logging; +using Ocelot.Middleware; using System.Linq; using System.Threading.Tasks; -using Ocelot.Infrastructure.RequestData; -using Microsoft.AspNetCore.Http; -using Ocelot.Logging; -using Ocelot.Configuration; -using Ocelot.DownstreamRouteFinder.Middleware; namespace Ocelot.RateLimit.Middleware { @@ -20,7 +16,7 @@ namespace Ocelot.RateLimit.Middleware public ClientRateLimitMiddleware(OcelotRequestDelegate next, IOcelotLoggerFactory loggerFactory, IRateLimitCounterHandler counterHandler) - :base(loggerFactory.CreateLogger()) + : base(loggerFactory.CreateLogger()) { _next = next; _counterHandler = counterHandler; @@ -29,9 +25,9 @@ namespace Ocelot.RateLimit.Middleware public async Task Invoke(DownstreamContext context) { - var options = context.DownstreamReRoute.RateLimitOptions; - - // check if rate limiting is enabled + var options = context.DownstreamReRoute.RateLimitOptions; + + // check if rate limiting is enabled if (!context.DownstreamReRoute.EnableEndpointEndpointRateLimiting) { Logger.LogInformation($"EndpointRateLimiting is not enabled for {context.DownstreamReRoute.DownstreamPathTemplate.Value}"); @@ -65,12 +61,12 @@ namespace Ocelot.RateLimit.Middleware // log blocked request LogBlockedRequest(context.HttpContext, identity, counter, rule, context.DownstreamReRoute); - var retrystring = retryAfter.ToString(System.Globalization.CultureInfo.InvariantCulture); - - // break execution - await ReturnQuotaExceededResponse(context.HttpContext, options, retrystring); - - // Set Error + var retrystring = retryAfter.ToString(System.Globalization.CultureInfo.InvariantCulture); + + // break execution + await ReturnQuotaExceededResponse(context.HttpContext, options, retrystring); + + // Set Error context.Errors.Add(new QuotaExceededError(this.GetResponseMessage(options))); return; @@ -116,8 +112,8 @@ namespace Ocelot.RateLimit.Middleware { Logger.LogInformation( $"Request {identity.HttpVerb}:{identity.Path} from ClientId {identity.ClientId} has been blocked, quota {rule.Limit}/{rule.Period} exceeded by {counter.TotalRequests}. Blocked by rule { downstreamReRoute.UpstreamPathTemplate.OriginalValue }, TraceIdentifier {httpContext.TraceIdentifier}."); - } - + } + public virtual Task ReturnQuotaExceededResponse(HttpContext httpContext, RateLimitOptions option, string retryAfter) { var message = this.GetResponseMessage(option); @@ -150,4 +146,4 @@ namespace Ocelot.RateLimit.Middleware return Task.CompletedTask; } } -} +} diff --git a/src/Ocelot/RateLimit/Middleware/RateLimitMiddlewareExtensions.cs b/src/Ocelot/RateLimit/Middleware/RateLimitMiddlewareExtensions.cs index 2583be4a..3d686196 100644 --- a/src/Ocelot/RateLimit/Middleware/RateLimitMiddlewareExtensions.cs +++ b/src/Ocelot/RateLimit/Middleware/RateLimitMiddlewareExtensions.cs @@ -9,4 +9,4 @@ namespace Ocelot.RateLimit.Middleware return builder.UseMiddleware(); } } -} +} diff --git a/src/Ocelot/RateLimit/RateLimitCore.cs b/src/Ocelot/RateLimit/RateLimitCore.cs index 4b0d5165..e2e93e01 100644 --- a/src/Ocelot/RateLimit/RateLimitCore.cs +++ b/src/Ocelot/RateLimit/RateLimitCore.cs @@ -1,12 +1,9 @@ using Microsoft.AspNetCore.Http; using Ocelot.Configuration; using System; -using System.Collections.Generic; using System.Globalization; -using System.Linq; using System.Security.Cryptography; using System.Text; -using System.Threading.Tasks; namespace Ocelot.RateLimit { @@ -38,7 +35,7 @@ namespace Ocelot.RateLimit { // increment request count var totalRequests = entry.Value.TotalRequests + 1; - + // deep copy counter = new RateLimitCounter(entry.Value.Timestamp, totalRequests); } @@ -71,7 +68,7 @@ namespace Ocelot.RateLimit { var counterId = ComputeCounterKey(requestIdentity, option); var rule = option.RateLimitRule; - + // stores: id (string) - timestamp (datetime) - total_requests (long) _counterHandler.Set(counterId, counter, expirationTime); } @@ -134,15 +131,19 @@ namespace Ocelot.RateLimit { case "d": return TimeSpan.FromDays(double.Parse(value)); + case "h": return TimeSpan.FromHours(double.Parse(value)); + case "m": return TimeSpan.FromMinutes(double.Parse(value)); + case "s": return TimeSpan.FromSeconds(double.Parse(value)); + default: throw new FormatException($"{timeSpan} can't be converted to TimeSpan, unknown type {type}"); } - } + } } } diff --git a/src/Ocelot/RateLimit/RateLimitCounter.cs b/src/Ocelot/RateLimit/RateLimitCounter.cs index 46462d04..ac355e39 100644 --- a/src/Ocelot/RateLimit/RateLimitCounter.cs +++ b/src/Ocelot/RateLimit/RateLimitCounter.cs @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Newtonsoft.Json; +using Newtonsoft.Json; +using System; namespace Ocelot.RateLimit { @@ -22,4 +19,4 @@ namespace Ocelot.RateLimit public long TotalRequests { get; private set; } } -} +} diff --git a/src/Ocelot/RateLimit/RateLimitHeaders.cs b/src/Ocelot/RateLimit/RateLimitHeaders.cs index 5849fa75..b93cf04d 100644 --- a/src/Ocelot/RateLimit/RateLimitHeaders.cs +++ b/src/Ocelot/RateLimit/RateLimitHeaders.cs @@ -1,8 +1,4 @@ using Microsoft.AspNetCore.Http; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace Ocelot.RateLimit { @@ -24,4 +20,4 @@ namespace Ocelot.RateLimit public string Reset { get; private set; } } -} +} diff --git a/src/Ocelot/Request/Creator/DownstreamRequestCreator.cs b/src/Ocelot/Request/Creator/DownstreamRequestCreator.cs index 352e70f3..560b6735 100644 --- a/src/Ocelot/Request/Creator/DownstreamRequestCreator.cs +++ b/src/Ocelot/Request/Creator/DownstreamRequestCreator.cs @@ -1,8 +1,8 @@ namespace Ocelot.Request.Creator { - using System.Net.Http; - using Ocelot.Request.Middleware; using Ocelot.Infrastructure; + using Ocelot.Request.Middleware; + using System.Net.Http; public class DownstreamRequestCreator : IDownstreamRequestCreator { @@ -16,14 +16,14 @@ namespace Ocelot.Request.Creator public DownstreamRequest Create(HttpRequestMessage request) { - /** + /** * According to https://tools.ietf.org/html/rfc7231 * GET,HEAD,DELETE,CONNECT,TRACE * Can have body but server can reject the request. * And MS HttpClient in Full Framework actually rejects it. - * see #366 issue + * see #366 issue **/ - if(_framework.Get().Contains(DotNetFramework)) + if (_framework.Get().Contains(DotNetFramework)) { if (request.Method == HttpMethod.Get || request.Method == HttpMethod.Head || diff --git a/src/Ocelot/Request/Creator/IDownstreamRequestCreator.cs b/src/Ocelot/Request/Creator/IDownstreamRequestCreator.cs index e6755399..dd87d5c8 100644 --- a/src/Ocelot/Request/Creator/IDownstreamRequestCreator.cs +++ b/src/Ocelot/Request/Creator/IDownstreamRequestCreator.cs @@ -1,7 +1,7 @@ namespace Ocelot.Request.Creator { - using System.Net.Http; using Ocelot.Request.Middleware; + using System.Net.Http; public interface IDownstreamRequestCreator { diff --git a/src/Ocelot/Request/Mapper/IRequestMapper.cs b/src/Ocelot/Request/Mapper/IRequestMapper.cs index 941a24f7..d16a2d06 100644 --- a/src/Ocelot/Request/Mapper/IRequestMapper.cs +++ b/src/Ocelot/Request/Mapper/IRequestMapper.cs @@ -1,9 +1,9 @@ namespace Ocelot.Request.Mapper { - using System.Net.Http; - using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Ocelot.Responses; + using System.Net.Http; + using System.Threading.Tasks; public interface IRequestMapper { diff --git a/src/Ocelot/Request/Mapper/RequestMapper.cs b/src/Ocelot/Request/Mapper/RequestMapper.cs index d0c45807..f669c286 100644 --- a/src/Ocelot/Request/Mapper/RequestMapper.cs +++ b/src/Ocelot/Request/Mapper/RequestMapper.cs @@ -1,15 +1,15 @@ namespace Ocelot.Request.Mapper { + using Microsoft.AspNetCore.Http; + using Microsoft.AspNetCore.Http.Extensions; + using Microsoft.Extensions.Primitives; + using Ocelot.Responses; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; using System.Threading.Tasks; - using Microsoft.AspNetCore.Http; - using Microsoft.AspNetCore.Http.Extensions; - using Microsoft.Extensions.Primitives; - using Ocelot.Responses; public class RequestMapper : IRequestMapper { @@ -38,7 +38,7 @@ private async Task MapContent(HttpRequest request) { - if (request.Body == null || (request.Body.CanSeek && request.Body.Length <= 0)) + if (request.Body == null || (request.Body.CanSeek && request.Body.Length <= 0)) { return null; } @@ -46,10 +46,10 @@ // Never change this to StreamContent again, I forgot it doesnt work in #464. var content = new ByteArrayContent(await ToByteArray(request.Body)); - if(!string.IsNullOrEmpty(request.ContentType)) + if (!string.IsNullOrEmpty(request.ContentType)) { content.Headers - .TryAddWithoutValidation("Content-Type", new[] {request.ContentType}); + .TryAddWithoutValidation("Content-Type", new[] { request.ContentType }); } AddHeaderIfExistsOnRequest("Content-Language", content, request); @@ -58,17 +58,17 @@ AddHeaderIfExistsOnRequest("Content-MD5", content, request); AddHeaderIfExistsOnRequest("Content-Disposition", content, request); AddHeaderIfExistsOnRequest("Content-Encoding", content, request); - + return content; } private void AddHeaderIfExistsOnRequest(string key, HttpContent content, HttpRequest request) { - if(request.Headers.ContainsKey(key)) + if (request.Headers.ContainsKey(key)) { content.Headers - .TryAddWithoutValidation(key, request.Headers[key].ToList()); - } + .TryAddWithoutValidation(key, request.Headers[key].ToList()); + } } private HttpMethod MapMethod(HttpRequest request) @@ -99,7 +99,7 @@ private async Task ToByteArray(Stream stream) { - using(stream) + using (stream) { using (var memStream = new MemoryStream()) { diff --git a/src/Ocelot/Request/Mapper/UnmappableRequestError.cs b/src/Ocelot/Request/Mapper/UnmappableRequestError.cs index 81668eef..fa5a602a 100644 --- a/src/Ocelot/Request/Mapper/UnmappableRequestError.cs +++ b/src/Ocelot/Request/Mapper/UnmappableRequestError.cs @@ -9,4 +9,4 @@ { } } -} +} diff --git a/src/Ocelot/Request/Middleware/DownstreamRequest.cs b/src/Ocelot/Request/Middleware/DownstreamRequest.cs index 49d27efe..256436e5 100644 --- a/src/Ocelot/Request/Middleware/DownstreamRequest.cs +++ b/src/Ocelot/Request/Middleware/DownstreamRequest.cs @@ -69,7 +69,7 @@ namespace Ocelot.Request.Middleware return uriBuilder.Uri.AbsoluteUri; } - public override string ToString() + public override string ToString() { return ToUri(); } diff --git a/src/Ocelot/Request/Middleware/DownstreamRequestInitialiserMiddleware.cs b/src/Ocelot/Request/Middleware/DownstreamRequestInitialiserMiddleware.cs index 4f3151d9..442bb4b9 100644 --- a/src/Ocelot/Request/Middleware/DownstreamRequestInitialiserMiddleware.cs +++ b/src/Ocelot/Request/Middleware/DownstreamRequestInitialiserMiddleware.cs @@ -1,12 +1,9 @@ namespace Ocelot.Request.Middleware { - using System.Threading.Tasks; - using Microsoft.AspNetCore.Http; - using Ocelot.DownstreamRouteFinder.Middleware; - using Ocelot.Infrastructure.RequestData; using Ocelot.Logging; using Ocelot.Middleware; using Ocelot.Request.Creator; + using System.Threading.Tasks; public class DownstreamRequestInitialiserMiddleware : OcelotMiddleware { @@ -18,7 +15,7 @@ namespace Ocelot.Request.Middleware IOcelotLoggerFactory loggerFactory, Mapper.IRequestMapper requestMapper, IDownstreamRequestCreator creator) - :base(loggerFactory.CreateLogger()) + : base(loggerFactory.CreateLogger()) { _next = next; _requestMapper = requestMapper; diff --git a/src/Ocelot/Request/Middleware/HttpRequestBuilderMiddlewareExtensions.cs b/src/Ocelot/Request/Middleware/HttpRequestBuilderMiddlewareExtensions.cs index 35084659..2d803e1e 100644 --- a/src/Ocelot/Request/Middleware/HttpRequestBuilderMiddlewareExtensions.cs +++ b/src/Ocelot/Request/Middleware/HttpRequestBuilderMiddlewareExtensions.cs @@ -10,4 +10,4 @@ namespace Ocelot.Request.Middleware return builder.UseMiddleware(); } } -} +} diff --git a/src/Ocelot/RequestId/DefaultRequestIdKey.cs b/src/Ocelot/RequestId/DefaultRequestIdKey.cs index 39f4b6ab..1dbd2e91 100644 --- a/src/Ocelot/RequestId/DefaultRequestIdKey.cs +++ b/src/Ocelot/RequestId/DefaultRequestIdKey.cs @@ -2,8 +2,8 @@ { public static class DefaultRequestIdKey { - // This is set incase anyone isnt doing this specifically with there requests. + // This is set incase anyone isnt doing this specifically with there requests. // It will not be forwarded on to downstream services unless specfied in the config. public const string Value = "RequestId"; } -} +} diff --git a/src/Ocelot/RequestId/Middleware/ReRouteRequestIdMiddleware.cs b/src/Ocelot/RequestId/Middleware/ReRouteRequestIdMiddleware.cs index b9ddf824..4c802a02 100644 --- a/src/Ocelot/RequestId/Middleware/ReRouteRequestIdMiddleware.cs +++ b/src/Ocelot/RequestId/Middleware/ReRouteRequestIdMiddleware.cs @@ -1,12 +1,11 @@ -using System; -using System.Linq; -using System.Threading.Tasks; using Ocelot.Infrastructure.RequestData; using Ocelot.Logging; using Ocelot.Middleware; -using System.Net.Http.Headers; -using System.Collections.Generic; using Ocelot.Request.Middleware; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http.Headers; +using System.Threading.Tasks; namespace Ocelot.RequestId.Middleware { @@ -16,7 +15,7 @@ namespace Ocelot.RequestId.Middleware private readonly IRequestScopedDataRepository _requestScopedDataRepository; public ReRouteRequestIdMiddleware(OcelotRequestDelegate next, - IOcelotLoggerFactory loggerFactory, + IOcelotLoggerFactory loggerFactory, IRequestScopedDataRepository requestScopedDataRepository) : base(loggerFactory.CreateLogger()) { @@ -76,4 +75,4 @@ namespace Ocelot.RequestId.Middleware httpRequestMessage.Headers.Add(requestId.RequestIdKey, requestId.RequestIdValue); } } -} +} diff --git a/src/Ocelot/RequestId/Middleware/RequestIdMiddlewareExtensions.cs b/src/Ocelot/RequestId/Middleware/RequestIdMiddlewareExtensions.cs index f450f9a5..ce4e892d 100644 --- a/src/Ocelot/RequestId/Middleware/RequestIdMiddlewareExtensions.cs +++ b/src/Ocelot/RequestId/Middleware/RequestIdMiddlewareExtensions.cs @@ -10,4 +10,4 @@ namespace Ocelot.RequestId.Middleware return builder.UseMiddleware(); } } -} +} diff --git a/src/Ocelot/RequestId/RequestId.cs b/src/Ocelot/RequestId/RequestId.cs index 85f9cbbc..5d24088e 100644 --- a/src/Ocelot/RequestId/RequestId.cs +++ b/src/Ocelot/RequestId/RequestId.cs @@ -11,4 +11,4 @@ public string RequestIdKey { get; private set; } public string RequestIdValue { get; private set; } } -} +} diff --git a/src/Ocelot/Requester/DelegatingHandlerHandlerFactory.cs b/src/Ocelot/Requester/DelegatingHandlerHandlerFactory.cs index 45858787..3e868b32 100644 --- a/src/Ocelot/Requester/DelegatingHandlerHandlerFactory.cs +++ b/src/Ocelot/Requester/DelegatingHandlerHandlerFactory.cs @@ -1,14 +1,14 @@ namespace Ocelot.Requester { - using System; - using System.Collections.Generic; - using System.Linq; - using System.Net.Http; using Logging; using Microsoft.Extensions.DependencyInjection; using Ocelot.Configuration; using Ocelot.Responses; using QoS; + using System; + using System.Collections.Generic; + using System.Linq; + using System.Net.Http; public class DelegatingHandlerHandlerFactory : IDelegatingHandlerHandlerFactory { diff --git a/src/Ocelot/Requester/HttpClientBuilder.cs b/src/Ocelot/Requester/HttpClientBuilder.cs index 6194a33f..64df44b1 100644 --- a/src/Ocelot/Requester/HttpClientBuilder.cs +++ b/src/Ocelot/Requester/HttpClientBuilder.cs @@ -1,10 +1,10 @@ -using System; +using Ocelot.Configuration; +using Ocelot.Logging; +using Ocelot.Middleware; +using System; using System.Linq; using System.Net; using System.Net.Http; -using Ocelot.Configuration; -using Ocelot.Logging; -using Ocelot.Middleware; namespace Ocelot.Requester { @@ -19,8 +19,8 @@ namespace Ocelot.Requester private readonly TimeSpan _defaultTimeout; public HttpClientBuilder( - IDelegatingHandlerHandlerFactory factory, - IHttpClientCache cacheHandlers, + IDelegatingHandlerHandlerFactory factory, + IHttpClientCache cacheHandlers, IOcelotLogger logger) { _factory = factory; @@ -55,7 +55,7 @@ namespace Ocelot.Requester } var timeout = context.DownstreamReRoute.QosOptions.TimeoutValue == 0 - ? _defaultTimeout + ? _defaultTimeout : TimeSpan.FromMilliseconds(context.DownstreamReRoute.QosOptions.TimeoutValue); _httpClient = new HttpClient(CreateHttpMessageHandler(handler, context.DownstreamReRoute)) @@ -73,7 +73,7 @@ namespace Ocelot.Requester // Dont' create the CookieContainer if UseCookies is not set or the HttpClient will complain // under .Net Full Framework bool useCookies = context.DownstreamReRoute.HttpHandlerOptions.UseCookieContainer; - + if (useCookies) { return UseCookiesHandler(context); @@ -97,12 +97,12 @@ namespace Ocelot.Requester private HttpClientHandler UseCookiesHandler(DownstreamContext context) { return new HttpClientHandler - { - AllowAutoRedirect = context.DownstreamReRoute.HttpHandlerOptions.AllowAutoRedirect, - UseCookies = context.DownstreamReRoute.HttpHandlerOptions.UseCookieContainer, - UseProxy = context.DownstreamReRoute.HttpHandlerOptions.UseProxy, - CookieContainer = new CookieContainer() - }; + { + AllowAutoRedirect = context.DownstreamReRoute.HttpHandlerOptions.AllowAutoRedirect, + UseCookies = context.DownstreamReRoute.HttpHandlerOptions.UseCookieContainer, + UseProxy = context.DownstreamReRoute.HttpHandlerOptions.UseProxy, + CookieContainer = new CookieContainer() + }; } public void Save() diff --git a/src/Ocelot/Requester/IDelegatingHandlerHandlerFactory.cs b/src/Ocelot/Requester/IDelegatingHandlerHandlerFactory.cs index 4d905c35..cf0b6d07 100644 --- a/src/Ocelot/Requester/IDelegatingHandlerHandlerFactory.cs +++ b/src/Ocelot/Requester/IDelegatingHandlerHandlerFactory.cs @@ -1,10 +1,10 @@ namespace Ocelot.Requester { + using Ocelot.Configuration; + using Ocelot.Responses; using System; using System.Collections.Generic; using System.Net.Http; - using Ocelot.Configuration; - using Ocelot.Responses; public interface IDelegatingHandlerHandlerFactory { diff --git a/src/Ocelot/Requester/IExceptionToErrorMapper.cs b/src/Ocelot/Requester/IExceptionToErrorMapper.cs index 9d765fa7..dd23f10b 100644 --- a/src/Ocelot/Requester/IExceptionToErrorMapper.cs +++ b/src/Ocelot/Requester/IExceptionToErrorMapper.cs @@ -1,5 +1,5 @@ -using System; -using Ocelot.Errors; +using Ocelot.Errors; +using System; namespace Ocelot.Requester { diff --git a/src/Ocelot/Requester/IHttpClientBuilder.cs b/src/Ocelot/Requester/IHttpClientBuilder.cs index cc8c6160..40bb2949 100644 --- a/src/Ocelot/Requester/IHttpClientBuilder.cs +++ b/src/Ocelot/Requester/IHttpClientBuilder.cs @@ -5,6 +5,7 @@ namespace Ocelot.Requester public interface IHttpClientBuilder { IHttpClient Create(DownstreamContext request); + void Save(); } } diff --git a/src/Ocelot/Requester/IHttpClientCache.cs b/src/Ocelot/Requester/IHttpClientCache.cs index c9e90f04..ac4cd2fd 100644 --- a/src/Ocelot/Requester/IHttpClientCache.cs +++ b/src/Ocelot/Requester/IHttpClientCache.cs @@ -1,11 +1,12 @@ namespace Ocelot.Requester { - using System; using Configuration; + using System; public interface IHttpClientCache { IHttpClient Get(DownstreamReRoute key); + void Set(DownstreamReRoute key, IHttpClient handler, TimeSpan expirationTime); } -} +} diff --git a/src/Ocelot/Requester/IHttpRequester.cs b/src/Ocelot/Requester/IHttpRequester.cs index 86f6209a..18f5ed78 100644 --- a/src/Ocelot/Requester/IHttpRequester.cs +++ b/src/Ocelot/Requester/IHttpRequester.cs @@ -1,7 +1,7 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Ocelot.Middleware; +using Ocelot.Middleware; using Ocelot.Responses; +using System.Net.Http; +using System.Threading.Tasks; namespace Ocelot.Requester { @@ -9,4 +9,4 @@ namespace Ocelot.Requester { Task> GetResponse(DownstreamContext context); } -} +} diff --git a/src/Ocelot/Requester/MemoryHttpClientCache.cs b/src/Ocelot/Requester/MemoryHttpClientCache.cs index b2fcc2a0..433d4ac6 100644 --- a/src/Ocelot/Requester/MemoryHttpClientCache.cs +++ b/src/Ocelot/Requester/MemoryHttpClientCache.cs @@ -1,8 +1,8 @@ namespace Ocelot.Requester { + using Configuration; using System; using System.Collections.Concurrent; - using Configuration; public class MemoryHttpClientCache : IHttpClientCache { @@ -22,6 +22,6 @@ { //todo handle error? return _httpClientsCache.TryGetValue(key, out var client) ? client : null; - } + } } } diff --git a/src/Ocelot/Requester/Middleware/HttpRequesterMiddlewareExtensions.cs b/src/Ocelot/Requester/Middleware/HttpRequesterMiddlewareExtensions.cs index 82013d4c..d92f7909 100644 --- a/src/Ocelot/Requester/Middleware/HttpRequesterMiddlewareExtensions.cs +++ b/src/Ocelot/Requester/Middleware/HttpRequesterMiddlewareExtensions.cs @@ -10,4 +10,4 @@ namespace Ocelot.Requester.Middleware return builder.UseMiddleware(); } } -} +} diff --git a/src/Ocelot/Requester/OcelotHttpTracingHandler.cs b/src/Ocelot/Requester/OcelotHttpTracingHandler.cs index 0ad4d410..0bf56922 100644 --- a/src/Ocelot/Requester/OcelotHttpTracingHandler.cs +++ b/src/Ocelot/Requester/OcelotHttpTracingHandler.cs @@ -1,11 +1,11 @@ namespace Ocelot.Requester { using Logging; + using Ocelot.Infrastructure.RequestData; using System; using System.Net.Http; using System.Threading; using System.Threading.Tasks; - using Ocelot.Infrastructure.RequestData; public class OcelotHttpTracingHandler : DelegatingHandler, ITracingHandler { diff --git a/src/Ocelot/Requester/QoS/IQosFactory.cs b/src/Ocelot/Requester/QoS/IQosFactory.cs index fb795504..5a3477cb 100644 --- a/src/Ocelot/Requester/QoS/IQosFactory.cs +++ b/src/Ocelot/Requester/QoS/IQosFactory.cs @@ -1,8 +1,8 @@ namespace Ocelot.Requester.QoS { - using System.Net.Http; using Configuration; using Responses; + using System.Net.Http; public interface IQoSFactory { diff --git a/src/Ocelot/Requester/QoS/QosFactory.cs b/src/Ocelot/Requester/QoS/QosFactory.cs index 37211f4b..711bc2c7 100644 --- a/src/Ocelot/Requester/QoS/QosFactory.cs +++ b/src/Ocelot/Requester/QoS/QosFactory.cs @@ -1,11 +1,11 @@ namespace Ocelot.Requester.QoS { - using System; - using System.Net.Http; using Configuration; using Logging; using Microsoft.Extensions.DependencyInjection; using Responses; + using System; + using System.Net.Http; public class QoSFactory : IQoSFactory { diff --git a/src/Ocelot/Requester/QoS/UnableToFindQoSProviderError.cs b/src/Ocelot/Requester/QoS/UnableToFindQoSProviderError.cs index e3c02b27..de0882ac 100644 --- a/src/Ocelot/Requester/QoS/UnableToFindQoSProviderError.cs +++ b/src/Ocelot/Requester/QoS/UnableToFindQoSProviderError.cs @@ -4,9 +4,9 @@ public class UnableToFindQoSProviderError : Error { - public UnableToFindQoSProviderError(string message) + public UnableToFindQoSProviderError(string message) : base(message, OcelotErrorCode.UnableToFindQoSProviderError) { } } -} +} diff --git a/src/Ocelot/Requester/QosDelegatingHandlerDelegate.cs b/src/Ocelot/Requester/QosDelegatingHandlerDelegate.cs index a0c66955..7b76c4c9 100644 --- a/src/Ocelot/Requester/QosDelegatingHandlerDelegate.cs +++ b/src/Ocelot/Requester/QosDelegatingHandlerDelegate.cs @@ -1,8 +1,8 @@ namespace Ocelot.Requester { - using System.Net.Http; using Configuration; using Logging; + using System.Net.Http; public delegate DelegatingHandler QosDelegatingHandlerDelegate(DownstreamReRoute reRoute, IOcelotLoggerFactory logger); } diff --git a/src/Ocelot/Requester/TracingHandlerFactory.cs b/src/Ocelot/Requester/TracingHandlerFactory.cs index 2740ef96..afb26845 100644 --- a/src/Ocelot/Requester/TracingHandlerFactory.cs +++ b/src/Ocelot/Requester/TracingHandlerFactory.cs @@ -1,9 +1,9 @@ namespace Ocelot.Requester { - using System; using Logging; - using Ocelot.Infrastructure.RequestData; using Microsoft.Extensions.DependencyInjection; + using Ocelot.Infrastructure.RequestData; + using System; public class TracingHandlerFactory : ITracingHandlerFactory { diff --git a/src/Ocelot/Requester/UnableToCompleteRequestError.cs b/src/Ocelot/Requester/UnableToCompleteRequestError.cs index c5eb7b31..26302039 100644 --- a/src/Ocelot/Requester/UnableToCompleteRequestError.cs +++ b/src/Ocelot/Requester/UnableToCompleteRequestError.cs @@ -1,13 +1,13 @@ -using System; -using Ocelot.Errors; +using Ocelot.Errors; +using System; namespace Ocelot.Requester { public class UnableToCompleteRequestError : Error { - public UnableToCompleteRequestError(Exception exception) + public UnableToCompleteRequestError(Exception exception) : base($"Error making http request, exception: {exception}", OcelotErrorCode.UnableToCompleteRequestError) { } } -} +} diff --git a/src/Ocelot/Responder/HttpContextResponder.cs b/src/Ocelot/Responder/HttpContextResponder.cs index ebb09ab2..509df689 100644 --- a/src/Ocelot/Responder/HttpContextResponder.cs +++ b/src/Ocelot/Responder/HttpContextResponder.cs @@ -1,12 +1,11 @@ -using System.IO; -using System.Linq; -using System.Net; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.Primitives; using Ocelot.Headers; using Ocelot.Middleware; +using System.Linq; +using System.Net; +using System.Threading.Tasks; namespace Ocelot.Responder { @@ -48,12 +47,12 @@ namespace Ocelot.Responder var content = await response.Content.ReadAsStreamAsync(); - if(response.Content.Headers.ContentLength != null) + if (response.Content.Headers.ContentLength != null) { - AddHeaderIfDoesntExist(context, new Header("Content-Length", new []{ response.Content.Headers.ContentLength.ToString() }) ); + AddHeaderIfDoesntExist(context, new Header("Content-Length", new[] { response.Content.Headers.ContentLength.ToString() })); } - using(content) + using (content) { if (response.StatusCode != HttpStatusCode.NotModified && context.Response.ContentLength != 0) { diff --git a/src/Ocelot/Responder/IErrorsToHttpStatusCodeMapper.cs b/src/Ocelot/Responder/IErrorsToHttpStatusCodeMapper.cs index 61330db9..26da864f 100644 --- a/src/Ocelot/Responder/IErrorsToHttpStatusCodeMapper.cs +++ b/src/Ocelot/Responder/IErrorsToHttpStatusCodeMapper.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; -using Ocelot.Errors; +using Ocelot.Errors; +using System.Collections.Generic; namespace Ocelot.Responder { diff --git a/src/Ocelot/Responder/IHttpResponder.cs b/src/Ocelot/Responder/IHttpResponder.cs index 73722f53..5a32950a 100644 --- a/src/Ocelot/Responder/IHttpResponder.cs +++ b/src/Ocelot/Responder/IHttpResponder.cs @@ -1,13 +1,13 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; using Ocelot.Middleware; -using Ocelot.Middleware.Multiplexer; +using System.Threading.Tasks; namespace Ocelot.Responder { public interface IHttpResponder { Task SetResponseOnHttpContext(HttpContext context, DownstreamResponse response); + void SetErrorResponseOnContext(HttpContext context, int statusCode); } -} +} diff --git a/src/Ocelot/Responder/Middleware/ResponderMiddleware.cs b/src/Ocelot/Responder/Middleware/ResponderMiddleware.cs index ec6696c5..43f01acb 100644 --- a/src/Ocelot/Responder/Middleware/ResponderMiddleware.cs +++ b/src/Ocelot/Responder/Middleware/ResponderMiddleware.cs @@ -1,10 +1,10 @@ using Microsoft.AspNetCore.Http; using Ocelot.Errors; +using Ocelot.Infrastructure.Extensions; using Ocelot.Logging; using Ocelot.Middleware; using System.Collections.Generic; using System.Threading.Tasks; -using Ocelot.Infrastructure.Extensions; namespace Ocelot.Responder.Middleware { @@ -17,12 +17,12 @@ namespace Ocelot.Responder.Middleware private readonly IHttpResponder _responder; private readonly IErrorsToHttpStatusCodeMapper _codeMapper; - public ResponderMiddleware(OcelotRequestDelegate next, + public ResponderMiddleware(OcelotRequestDelegate next, IHttpResponder responder, IOcelotLoggerFactory loggerFactory, IErrorsToHttpStatusCodeMapper codeMapper ) - :base(loggerFactory.CreateLogger()) + : base(loggerFactory.CreateLogger()) { _next = next; _responder = responder; @@ -30,13 +30,13 @@ namespace Ocelot.Responder.Middleware } public async Task Invoke(DownstreamContext context) - { + { await _next.Invoke(context); if (context.IsError) { Logger.LogWarning($"{context.Errors.ToErrorString()} errors found in {MiddlewareName}. Setting error response for request path:{context.HttpContext.Request.Path}, request method: {context.HttpContext.Request.Method}"); - + SetErrorResponse(context.HttpContext, context.Errors); } else diff --git a/src/Ocelot/Responder/Middleware/ResponderMiddlewareExtensions.cs b/src/Ocelot/Responder/Middleware/ResponderMiddlewareExtensions.cs index 9379708f..9e890412 100644 --- a/src/Ocelot/Responder/Middleware/ResponderMiddlewareExtensions.cs +++ b/src/Ocelot/Responder/Middleware/ResponderMiddlewareExtensions.cs @@ -10,4 +10,4 @@ namespace Ocelot.Responder.Middleware return builder.UseMiddleware(); } } -} +} diff --git a/src/Ocelot/Responses/ErrorResponse.cs b/src/Ocelot/Responses/ErrorResponse.cs index 156243ab..56a3eb23 100644 --- a/src/Ocelot/Responses/ErrorResponse.cs +++ b/src/Ocelot/Responses/ErrorResponse.cs @@ -1,18 +1,18 @@ -using System.Collections.Generic; using Ocelot.Errors; +using System.Collections.Generic; namespace Ocelot.Responses { public class ErrorResponse : Response { - public ErrorResponse(Error error) - : base(new List{error}) + public ErrorResponse(Error error) + : base(new List { error }) { } - public ErrorResponse(List errors) + public ErrorResponse(List errors) : base(errors) { } } -} +} diff --git a/src/Ocelot/Responses/ErrorResponseGeneric.cs b/src/Ocelot/Responses/ErrorResponseGeneric.cs index f57de97f..0dbf4272 100644 --- a/src/Ocelot/Responses/ErrorResponseGeneric.cs +++ b/src/Ocelot/Responses/ErrorResponseGeneric.cs @@ -1,20 +1,21 @@ -using System.Collections.Generic; using Ocelot.Errors; +using System.Collections.Generic; namespace Ocelot.Responses { #pragma warning disable SA1649 // File name must match first type name + public class ErrorResponse : Response #pragma warning restore SA1649 // File name must match first type name { - public ErrorResponse(Error error) - : base(new List {error}) - { + public ErrorResponse(Error error) + : base(new List { error }) + { } - public ErrorResponse(List errors) + public ErrorResponse(List errors) : base(errors) { } } -} +} diff --git a/src/Ocelot/Responses/OkResponseGeneric.cs b/src/Ocelot/Responses/OkResponseGeneric.cs index 73fcf1e2..cc0ccc12 100644 --- a/src/Ocelot/Responses/OkResponseGeneric.cs +++ b/src/Ocelot/Responses/OkResponseGeneric.cs @@ -1,6 +1,7 @@ namespace Ocelot.Responses { #pragma warning disable SA1649 // File name must match first type name + public class OkResponse : Response #pragma warning restore SA1649 // File name must match first type name { @@ -8,4 +9,4 @@ namespace Ocelot.Responses { } } -} +} diff --git a/src/Ocelot/Responses/Response.cs b/src/Ocelot/Responses/Response.cs index 3a387a2b..a10d480b 100644 --- a/src/Ocelot/Responses/Response.cs +++ b/src/Ocelot/Responses/Response.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; using Ocelot.Errors; +using System.Collections.Generic; namespace Ocelot.Responses { @@ -13,10 +13,10 @@ namespace Ocelot.Responses protected Response(List errors) { Errors = errors ?? new List(); - } - + } + public List Errors { get; } public bool IsError => Errors.Count > 0; } -} +} diff --git a/src/Ocelot/Responses/ResponseGeneric.cs b/src/Ocelot/Responses/ResponseGeneric.cs index 0b2514e9..2deeb113 100644 --- a/src/Ocelot/Responses/ResponseGeneric.cs +++ b/src/Ocelot/Responses/ResponseGeneric.cs @@ -1,9 +1,10 @@ -using System.Collections.Generic; using Ocelot.Errors; +using System.Collections.Generic; namespace Ocelot.Responses { #pragma warning disable SA1649 // File name must match first type name + public abstract class Response : Response #pragma warning restore SA1649 // File name must match first type name { @@ -16,6 +17,6 @@ namespace Ocelot.Responses { } - public T Data { get; private set; } + public T Data { get; private set; } } -} +} diff --git a/src/Ocelot/Security/IPSecurity/IPSecurityPolicy.cs b/src/Ocelot/Security/IPSecurity/IPSecurityPolicy.cs index bbf97778..19c75e59 100644 --- a/src/Ocelot/Security/IPSecurity/IPSecurityPolicy.cs +++ b/src/Ocelot/Security/IPSecurity/IPSecurityPolicy.cs @@ -1,11 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Text; -using System.Threading.Tasks; -using Ocelot.Configuration; +using Ocelot.Configuration; using Ocelot.Middleware; using Ocelot.Responses; +using System.Net; +using System.Threading.Tasks; namespace Ocelot.Security.IPSecurity { @@ -37,7 +34,7 @@ namespace Ocelot.Security.IPSecurity return new ErrorResponse(error); } } - + return await Task.FromResult(new OkResponse()); } } diff --git a/src/Ocelot/Security/ISecurityPolicy.cs b/src/Ocelot/Security/ISecurityPolicy.cs index 2b3457ec..c6854610 100644 --- a/src/Ocelot/Security/ISecurityPolicy.cs +++ b/src/Ocelot/Security/ISecurityPolicy.cs @@ -1,8 +1,5 @@ using Ocelot.Middleware; using Ocelot.Responses; -using System; -using System.Collections.Generic; -using System.Text; using System.Threading.Tasks; namespace Ocelot.Security diff --git a/src/Ocelot/Security/Middleware/SecurityMiddleware.cs b/src/Ocelot/Security/Middleware/SecurityMiddleware.cs index 1665ba3b..657445b8 100644 --- a/src/Ocelot/Security/Middleware/SecurityMiddleware.cs +++ b/src/Ocelot/Security/Middleware/SecurityMiddleware.cs @@ -10,6 +10,7 @@ namespace Ocelot.Security.Middleware private readonly OcelotRequestDelegate _next; private readonly IOcelotLogger _logger; private readonly IEnumerable _securityPolicies; + public SecurityMiddleware(IOcelotLoggerFactory loggerFactory, IEnumerable securityPolicies, OcelotRequestDelegate next) diff --git a/src/Ocelot/Security/Middleware/SecurityMiddlewareExtensions.cs b/src/Ocelot/Security/Middleware/SecurityMiddlewareExtensions.cs index 1e454d3a..6230dae4 100644 --- a/src/Ocelot/Security/Middleware/SecurityMiddlewareExtensions.cs +++ b/src/Ocelot/Security/Middleware/SecurityMiddlewareExtensions.cs @@ -1,7 +1,4 @@ using Ocelot.Middleware.Pipeline; -using System; -using System.Collections.Generic; -using System.Text; namespace Ocelot.Security.Middleware { diff --git a/src/Ocelot/ServiceDiscovery/Providers/ConfigurationServiceProvider.cs b/src/Ocelot/ServiceDiscovery/Providers/ConfigurationServiceProvider.cs index 04369996..f494e087 100644 --- a/src/Ocelot/ServiceDiscovery/Providers/ConfigurationServiceProvider.cs +++ b/src/Ocelot/ServiceDiscovery/Providers/ConfigurationServiceProvider.cs @@ -1,6 +1,6 @@ +using Ocelot.Values; using System.Collections.Generic; using System.Threading.Tasks; -using Ocelot.Values; namespace Ocelot.ServiceDiscovery.Providers { diff --git a/src/Ocelot/ServiceDiscovery/Providers/IServiceDiscoveryProvider.cs b/src/Ocelot/ServiceDiscovery/Providers/IServiceDiscoveryProvider.cs index ef28375e..440a9cae 100644 --- a/src/Ocelot/ServiceDiscovery/Providers/IServiceDiscoveryProvider.cs +++ b/src/Ocelot/ServiceDiscovery/Providers/IServiceDiscoveryProvider.cs @@ -1,11 +1,11 @@ +using Ocelot.Values; using System.Collections.Generic; using System.Threading.Tasks; -using Ocelot.Values; namespace Ocelot.ServiceDiscovery.Providers { public interface IServiceDiscoveryProvider { - Task> Get(); + Task> Get(); } } diff --git a/src/Ocelot/ServiceDiscovery/Providers/ServiceFabricServiceDiscoveryProvider.cs b/src/Ocelot/ServiceDiscovery/Providers/ServiceFabricServiceDiscoveryProvider.cs index bc7ebf6e..a397b322 100644 --- a/src/Ocelot/ServiceDiscovery/Providers/ServiceFabricServiceDiscoveryProvider.cs +++ b/src/Ocelot/ServiceDiscovery/Providers/ServiceFabricServiceDiscoveryProvider.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Ocelot.ServiceDiscovery.Configuration; +using Ocelot.ServiceDiscovery.Configuration; using Ocelot.Values; +using System.Collections.Generic; +using System.Threading.Tasks; namespace Ocelot.ServiceDiscovery.Providers { @@ -18,10 +18,10 @@ namespace Ocelot.ServiceDiscovery.Providers { return Task.FromResult(new List { - new Service(_configuration.ServiceName, - new ServiceHostAndPort(_configuration.HostName, _configuration.Port), - "doesnt matter with service fabric", - "doesnt matter with service fabric", + new Service(_configuration.ServiceName, + new ServiceHostAndPort(_configuration.HostName, _configuration.Port), + "doesnt matter with service fabric", + "doesnt matter with service fabric", new List()) }); } diff --git a/src/Ocelot/ServiceDiscovery/ServiceDiscoveryFinderDelegate.cs b/src/Ocelot/ServiceDiscovery/ServiceDiscoveryFinderDelegate.cs index e3b0f20c..848b0eef 100644 --- a/src/Ocelot/ServiceDiscovery/ServiceDiscoveryFinderDelegate.cs +++ b/src/Ocelot/ServiceDiscovery/ServiceDiscoveryFinderDelegate.cs @@ -1,8 +1,8 @@ namespace Ocelot.ServiceDiscovery { - using System; using Ocelot.Configuration; using Providers; + using System; public delegate IServiceDiscoveryProvider ServiceDiscoveryFinderDelegate(IServiceProvider provider, ServiceProviderConfiguration config, string key); } diff --git a/src/Ocelot/ServiceDiscovery/ServiceDiscoveryProviderFactory.cs b/src/Ocelot/ServiceDiscovery/ServiceDiscoveryProviderFactory.cs index 1fa8c7c0..b7f6ef4e 100644 --- a/src/Ocelot/ServiceDiscovery/ServiceDiscoveryProviderFactory.cs +++ b/src/Ocelot/ServiceDiscovery/ServiceDiscoveryProviderFactory.cs @@ -1,15 +1,14 @@ namespace Ocelot.ServiceDiscovery { - using System.Collections.Generic; + using Microsoft.Extensions.DependencyInjection; using Ocelot.Configuration; using Ocelot.Logging; + using Ocelot.Responses; using Ocelot.ServiceDiscovery.Configuration; using Ocelot.ServiceDiscovery.Providers; using Ocelot.Values; using System; - using System.Linq; - using Microsoft.Extensions.DependencyInjection; - using Ocelot.Responses; + using System.Collections.Generic; public class ServiceDiscoveryProviderFactory : IServiceDiscoveryProviderFactory { @@ -55,7 +54,7 @@ namespace Ocelot.ServiceDiscovery { var provider = _delegates?.Invoke(_provider, config, key); - if(provider.GetType().Name.ToLower() == config.Type.ToLower()) + if (provider.GetType().Name.ToLower() == config.Type.ToLower()) { return new OkResponse(provider); } diff --git a/src/Ocelot/Values/DownstreamPath.cs b/src/Ocelot/Values/DownstreamPath.cs index f0821118..0e845598 100644 --- a/src/Ocelot/Values/DownstreamPath.cs +++ b/src/Ocelot/Values/DownstreamPath.cs @@ -9,4 +9,4 @@ public string Value { get; } } -} +} diff --git a/src/Ocelot/Values/Service.cs b/src/Ocelot/Values/Service.cs index 234b248b..5194f731 100644 --- a/src/Ocelot/Values/Service.cs +++ b/src/Ocelot/Values/Service.cs @@ -27,4 +27,4 @@ namespace Ocelot.Values public ServiceHostAndPort HostAndPort { get; } } -} +} diff --git a/src/Ocelot/Values/ServiceHostAndPort.cs b/src/Ocelot/Values/ServiceHostAndPort.cs index 4e4271b8..4a8e3748 100644 --- a/src/Ocelot/Values/ServiceHostAndPort.cs +++ b/src/Ocelot/Values/ServiceHostAndPort.cs @@ -12,4 +12,4 @@ public int DownstreamPort { get; } } -} +} diff --git a/src/Ocelot/Values/UpstreamPathTemplate.cs b/src/Ocelot/Values/UpstreamPathTemplate.cs index 8497d85e..04e23e5c 100644 --- a/src/Ocelot/Values/UpstreamPathTemplate.cs +++ b/src/Ocelot/Values/UpstreamPathTemplate.cs @@ -10,8 +10,8 @@ namespace Ocelot.Values Priority = priority; ContainsQueryString = containsQueryString; OriginalValue = originalValue; - Pattern = template == null ? - new Regex("$^", RegexOptions.Compiled | RegexOptions.Singleline) : + Pattern = template == null ? + new Regex("$^", RegexOptions.Compiled | RegexOptions.Singleline) : new Regex(template, RegexOptions.Compiled | RegexOptions.Singleline); } @@ -22,7 +22,7 @@ namespace Ocelot.Values public bool ContainsQueryString { get; } public string OriginalValue { get; } - + public Regex Pattern { get; } } } diff --git a/src/Ocelot/WebSockets/Middleware/WebSocketsProxyMiddleware.cs b/src/Ocelot/WebSockets/Middleware/WebSocketsProxyMiddleware.cs index eb5279e6..6d56a489 100644 --- a/src/Ocelot/WebSockets/Middleware/WebSocketsProxyMiddleware.cs +++ b/src/Ocelot/WebSockets/Middleware/WebSocketsProxyMiddleware.cs @@ -2,14 +2,14 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Modified https://github.com/aspnet/Proxy websockets class to use in Ocelot. +using Microsoft.AspNetCore.Http; +using Ocelot.Logging; +using Ocelot.Middleware; using System; using System.Linq; using System.Net.WebSockets; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Ocelot.Logging; -using Ocelot.Middleware; namespace Ocelot.WebSockets.Middleware { diff --git a/test/Ocelot.AcceptanceTests/AggregateTests.cs b/test/Ocelot.AcceptanceTests/AggregateTests.cs index 6de4d8c7..21573f61 100644 --- a/test/Ocelot.AcceptanceTests/AggregateTests.cs +++ b/test/Ocelot.AcceptanceTests/AggregateTests.cs @@ -1,18 +1,15 @@ +using Microsoft.AspNetCore.Http; +using Ocelot.Configuration.File; +using Ocelot.Middleware; +using Ocelot.Middleware.Multiplexer; +using Shouldly; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Net.Http; -using System.Net.Http.Headers; using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; -using Ocelot.Configuration.File; -using Ocelot.Middleware; -using Ocelot.Middleware.Multiplexer; -using Shouldly; using TestStack.BDDfy; using Xunit; @@ -422,7 +419,6 @@ namespace Ocelot.AcceptanceTests { "Laura", "Tom" - } } } diff --git a/test/Ocelot.AcceptanceTests/AuthenticationTests.cs b/test/Ocelot.AcceptanceTests/AuthenticationTests.cs index a5ba79dd..65d9a878 100644 --- a/test/Ocelot.AcceptanceTests/AuthenticationTests.cs +++ b/test/Ocelot.AcceptanceTests/AuthenticationTests.cs @@ -1,18 +1,18 @@ namespace Ocelot.AcceptanceTests { - using IdentityServer4.Test; - using System; - using System.Collections.Generic; - using System.IO; - using System.Net; - using System.Security.Claims; using IdentityServer4.AccessTokenValidation; using IdentityServer4.Models; + using IdentityServer4.Test; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Ocelot.Configuration.File; + using System; + using System.Collections.Generic; + using System.IO; + using System.Net; + using System.Security.Claims; using TestStack.BDDfy; using Xunit; @@ -46,10 +46,10 @@ namespace Ocelot.AcceptanceTests public void should_return_401_using_identity_server_access_token() { int port = 54329; - - var configuration = new FileConfiguration - { - ReRoutes = new List + + var configuration = new FileConfiguration + { + ReRoutes = new List { new FileReRoute { @@ -70,8 +70,8 @@ namespace Ocelot.AcceptanceTests AuthenticationProviderKey = "Test" } } - } - }; + } + }; this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", "api2", AccessTokenType.Jwt)) .And(x => x.GivenThereIsAServiceRunningOn($"{_downstreamServiceUrl}{port}", 201, string.Empty)) @@ -88,9 +88,9 @@ namespace Ocelot.AcceptanceTests { int port = 54099; - var configuration = new FileConfiguration - { - ReRoutes = new List + var configuration = new FileConfiguration + { + ReRoutes = new List { new FileReRoute { @@ -111,19 +111,19 @@ namespace Ocelot.AcceptanceTests AuthenticationProviderKey = "Test" } } - } - }; - - this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", "api2", AccessTokenType.Jwt)) - .And(x => x.GivenThereIsAServiceRunningOn($"{_downstreamServiceUrl}{port}", 200, "Hello from Laura")) - .And(x => _steps.GivenIHaveAToken(_identityServerRootUrl)) - .And(x => _steps.GivenThereIsAConfiguration(configuration)) - .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) - .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) - .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) - .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) - .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura")) - .BDDfy(); + } + }; + + this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", "api2", AccessTokenType.Jwt)) + .And(x => x.GivenThereIsAServiceRunningOn($"{_downstreamServiceUrl}{port}", 200, "Hello from Laura")) + .And(x => _steps.GivenIHaveAToken(_identityServerRootUrl)) + .And(x => _steps.GivenThereIsAConfiguration(configuration)) + .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) + .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) + .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) + .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) + .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura")) + .BDDfy(); } [Fact] @@ -131,9 +131,9 @@ namespace Ocelot.AcceptanceTests { int port = 54196; - var configuration = new FileConfiguration - { - ReRoutes = new List + var configuration = new FileConfiguration + { + ReRoutes = new List { new FileReRoute { @@ -154,18 +154,18 @@ namespace Ocelot.AcceptanceTests AuthenticationProviderKey = "Test" } } - } - }; - - this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", "api2", AccessTokenType.Jwt)) - .And(x => x.GivenThereIsAServiceRunningOn($"{_downstreamServiceUrl}{port}", 200, "Hello from Laura")) - .And(x => _steps.GivenIHaveATokenForApi2(_identityServerRootUrl)) - .And(x => _steps.GivenThereIsAConfiguration(configuration)) - .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) - .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) - .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) - .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.Unauthorized)) - .BDDfy(); + } + }; + + this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", "api2", AccessTokenType.Jwt)) + .And(x => x.GivenThereIsAServiceRunningOn($"{_downstreamServiceUrl}{port}", 200, "Hello from Laura")) + .And(x => _steps.GivenIHaveATokenForApi2(_identityServerRootUrl)) + .And(x => _steps.GivenThereIsAConfiguration(configuration)) + .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) + .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) + .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) + .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.Unauthorized)) + .BDDfy(); } [Fact] @@ -173,9 +173,9 @@ namespace Ocelot.AcceptanceTests { int port = 52226; - var configuration = new FileConfiguration - { - ReRoutes = new List + var configuration = new FileConfiguration + { + ReRoutes = new List { new FileReRoute { @@ -196,19 +196,19 @@ namespace Ocelot.AcceptanceTests AuthenticationProviderKey = "Test" } } - } - }; - - this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", "api2", AccessTokenType.Jwt)) - .And(x => x.GivenThereIsAServiceRunningOn($"{_downstreamServiceUrl}{port}", 201, string.Empty)) - .And(x => _steps.GivenIHaveAToken(_identityServerRootUrl)) - .And(x => _steps.GivenThereIsAConfiguration(configuration)) - .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) - .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) - .And(x => _steps.GivenThePostHasContent("postContent")) - .When(x => _steps.WhenIPostUrlOnTheApiGateway("/")) - .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.Created)) - .BDDfy(); + } + }; + + this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", "api2", AccessTokenType.Jwt)) + .And(x => x.GivenThereIsAServiceRunningOn($"{_downstreamServiceUrl}{port}", 201, string.Empty)) + .And(x => _steps.GivenIHaveAToken(_identityServerRootUrl)) + .And(x => _steps.GivenThereIsAConfiguration(configuration)) + .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) + .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) + .And(x => _steps.GivenThePostHasContent("postContent")) + .When(x => _steps.WhenIPostUrlOnTheApiGateway("/")) + .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.Created)) + .BDDfy(); } [Fact] @@ -216,9 +216,9 @@ namespace Ocelot.AcceptanceTests { int port = 52222; - var configuration = new FileConfiguration - { - ReRoutes = new List + var configuration = new FileConfiguration + { + ReRoutes = new List { new FileReRoute { @@ -239,19 +239,19 @@ namespace Ocelot.AcceptanceTests AuthenticationProviderKey = "Test" } } - } - }; - - this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", "api2", AccessTokenType.Reference)) - .And(x => x.GivenThereIsAServiceRunningOn($"{_downstreamServiceUrl}{port}", 201, string.Empty)) - .And(x => _steps.GivenIHaveAToken(_identityServerRootUrl)) - .And(x => _steps.GivenThereIsAConfiguration(configuration)) - .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) - .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) - .And(x => _steps.GivenThePostHasContent("postContent")) - .When(x => _steps.WhenIPostUrlOnTheApiGateway("/")) - .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.Created)) - .BDDfy(); + } + }; + + this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", "api2", AccessTokenType.Reference)) + .And(x => x.GivenThereIsAServiceRunningOn($"{_downstreamServiceUrl}{port}", 201, string.Empty)) + .And(x => _steps.GivenIHaveAToken(_identityServerRootUrl)) + .And(x => _steps.GivenThereIsAConfiguration(configuration)) + .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) + .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) + .And(x => _steps.GivenThePostHasContent("postContent")) + .When(x => _steps.WhenIPostUrlOnTheApiGateway("/")) + .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.Created)) + .BDDfy(); } private void GivenThereIsAServiceRunningOn(string url, int statusCode, string responseBody) @@ -373,4 +373,4 @@ namespace Ocelot.AcceptanceTests _identityServerBuilder?.Dispose(); } } -} +} diff --git a/test/Ocelot.AcceptanceTests/AuthorisationTests.cs b/test/Ocelot.AcceptanceTests/AuthorisationTests.cs index 5dc59b9e..6df6755c 100644 --- a/test/Ocelot.AcceptanceTests/AuthorisationTests.cs +++ b/test/Ocelot.AcceptanceTests/AuthorisationTests.cs @@ -1,20 +1,20 @@ namespace Ocelot.AcceptanceTests { - using System; - using System.Collections.Generic; - using System.IO; - using System.Net; - using System.Security.Claims; using IdentityServer4.AccessTokenValidation; using IdentityServer4.Models; + using IdentityServer4.Test; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Ocelot.Configuration.File; + using System; + using System.Collections.Generic; + using System.IO; + using System.Net; + using System.Security.Claims; using TestStack.BDDfy; using Xunit; - using IdentityServer4.Test; public class AuthorisationTests : IDisposable { @@ -44,8 +44,8 @@ namespace Ocelot.AcceptanceTests int port = 52875; var configuration = new FileConfiguration - { - ReRoutes = new List + { + ReRoutes = new List { new FileReRoute { @@ -84,18 +84,18 @@ namespace Ocelot.AcceptanceTests } } } - }; - - this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt)) - .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura")) - .And(x => _steps.GivenIHaveAToken("http://localhost:51888")) - .And(x => _steps.GivenThereIsAConfiguration(configuration)) - .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) - .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) - .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) - .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) - .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura")) - .BDDfy(); + }; + + this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt)) + .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura")) + .And(x => _steps.GivenIHaveAToken("http://localhost:51888")) + .And(x => _steps.GivenThereIsAConfiguration(configuration)) + .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) + .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) + .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) + .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) + .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura")) + .BDDfy(); } [Fact] @@ -103,9 +103,9 @@ namespace Ocelot.AcceptanceTests { int port = 59471; - var configuration = new FileConfiguration - { - ReRoutes = new List + var configuration = new FileConfiguration + { + ReRoutes = new List { new FileReRoute { @@ -142,18 +142,18 @@ namespace Ocelot.AcceptanceTests {"UserType", "registered"} } } - } - }; - - this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt)) - .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura")) - .And(x => _steps.GivenIHaveAToken("http://localhost:51888")) - .And(x => _steps.GivenThereIsAConfiguration(configuration)) - .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) - .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) - .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) - .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.Forbidden)) - .BDDfy(); + } + }; + + this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt)) + .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura")) + .And(x => _steps.GivenIHaveAToken("http://localhost:51888")) + .And(x => _steps.GivenThereIsAConfiguration(configuration)) + .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) + .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) + .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) + .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.Forbidden)) + .BDDfy(); } [Fact] @@ -161,9 +161,9 @@ namespace Ocelot.AcceptanceTests { int port = 63471; - var configuration = new FileConfiguration - { - ReRoutes = new List + var configuration = new FileConfiguration + { + ReRoutes = new List { new FileReRoute { @@ -185,18 +185,18 @@ namespace Ocelot.AcceptanceTests AllowedScopes = new List{ "api", "api.readOnly", "openid", "offline_access" }, }, } - } - }; - - this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt)) - .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura")) - .And(x => _steps.GivenIHaveATokenForApiReadOnlyScope("http://localhost:51888")) - .And(x => _steps.GivenThereIsAConfiguration(configuration)) - .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) - .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) - .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) - .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) - .BDDfy(); + } + }; + + this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt)) + .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura")) + .And(x => _steps.GivenIHaveATokenForApiReadOnlyScope("http://localhost:51888")) + .And(x => _steps.GivenThereIsAConfiguration(configuration)) + .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) + .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) + .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) + .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) + .BDDfy(); } [Fact] @@ -204,9 +204,9 @@ namespace Ocelot.AcceptanceTests { int port = 60571; - var configuration = new FileConfiguration - { - ReRoutes = new List + var configuration = new FileConfiguration + { + ReRoutes = new List { new FileReRoute { @@ -228,18 +228,18 @@ namespace Ocelot.AcceptanceTests AllowedScopes = new List{ "api", "openid", "offline_access" }, }, } - } - }; - - this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt)) - .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura")) - .And(x => _steps.GivenIHaveATokenForApiReadOnlyScope("http://localhost:51888")) - .And(x => _steps.GivenThereIsAConfiguration(configuration)) - .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) - .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) - .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) - .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.Forbidden)) - .BDDfy(); + } + }; + + this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt)) + .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura")) + .And(x => _steps.GivenIHaveATokenForApiReadOnlyScope("http://localhost:51888")) + .And(x => _steps.GivenThereIsAConfiguration(configuration)) + .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) + .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) + .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) + .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.Forbidden)) + .BDDfy(); } [Fact] @@ -247,9 +247,9 @@ namespace Ocelot.AcceptanceTests { int port = 61071; - var configuration = new FileConfiguration - { - ReRoutes = new List + var configuration = new FileConfiguration + { + ReRoutes = new List { new FileReRoute { @@ -274,8 +274,8 @@ namespace Ocelot.AcceptanceTests {"Role", "User"} } } - } - }; + } + }; var users = new List { @@ -286,22 +286,22 @@ namespace Ocelot.AcceptanceTests SubjectId = "registered|1231231", Claims = new List { - new Claim("Role", "AdminUser"), + new Claim("Role", "AdminUser"), new Claim("Role", "User") }, } - }; - - this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt, users)) - .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura")) - .And(x => _steps.GivenIHaveAToken("http://localhost:51888")) - .And(x => _steps.GivenThereIsAConfiguration(configuration)) - .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) - .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) - .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) - .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) - .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura")) - .BDDfy(); + }; + + this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt, users)) + .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura")) + .And(x => _steps.GivenIHaveAToken("http://localhost:51888")) + .And(x => _steps.GivenThereIsAConfiguration(configuration)) + .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) + .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) + .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) + .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) + .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura")) + .BDDfy(); } private void GivenThereIsAServiceRunningOn(string url, int statusCode, string responseBody) @@ -467,4 +467,4 @@ namespace Ocelot.AcceptanceTests _identityServerBuilder?.Dispose(); } } -} +} diff --git a/test/Ocelot.AcceptanceTests/BearerToken.cs b/test/Ocelot.AcceptanceTests/BearerToken.cs index 019b4d99..6c52ced1 100644 --- a/test/Ocelot.AcceptanceTests/BearerToken.cs +++ b/test/Ocelot.AcceptanceTests/BearerToken.cs @@ -2,7 +2,7 @@ using Newtonsoft.Json; namespace Ocelot.AcceptanceTests { - class BearerToken + internal class BearerToken { [JsonProperty("access_token")] public string AccessToken { get; set; } @@ -13,4 +13,4 @@ namespace Ocelot.AcceptanceTests [JsonProperty("token_type")] public string TokenType { get; set; } } -} \ No newline at end of file +} diff --git a/test/Ocelot.AcceptanceTests/ButterflyTracingTests.cs b/test/Ocelot.AcceptanceTests/ButterflyTracingTests.cs index ea18131c..1b587cb8 100644 --- a/test/Ocelot.AcceptanceTests/ButterflyTracingTests.cs +++ b/test/Ocelot.AcceptanceTests/ButterflyTracingTests.cs @@ -1,9 +1,5 @@ namespace Ocelot.AcceptanceTests { - using System; - using System.Collections.Generic; - using System.IO; - using System.Net; using Butterfly.Client.AspNetCore; using Configuration.File; using Microsoft.AspNetCore.Builder; @@ -11,6 +7,10 @@ namespace Ocelot.AcceptanceTests using Microsoft.AspNetCore.Http; using Rafty.Infrastructure; using Shouldly; + using System; + using System.Collections.Generic; + using System.IO; + using System.Net; using TestStack.BDDfy; using Xunit; using Xunit.Abstractions; @@ -157,7 +157,8 @@ namespace Ocelot.AcceptanceTests .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() - .ConfigureServices(services => { + .ConfigureServices(services => + { services.AddButterfly(option => { option.CollectorUrl = butterflyUrl; @@ -169,10 +170,10 @@ namespace Ocelot.AcceptanceTests { app.UsePathBase(basePath); app.Run(async context => - { + { _downstreamPathOne = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value; - if(_downstreamPathOne != basePath) + if (_downstreamPathOne != basePath) { context.Response.StatusCode = statusCode; await context.Response.WriteAsync("downstream path didnt match base path"); @@ -216,7 +217,8 @@ namespace Ocelot.AcceptanceTests .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() - .ConfigureServices(services => { + .ConfigureServices(services => + { services.AddButterfly(option => { option.CollectorUrl = butterflyUrl; @@ -228,10 +230,10 @@ namespace Ocelot.AcceptanceTests { app.UsePathBase(basePath); app.Run(async context => - { + { _downstreamPathTwo = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value; - if(_downstreamPathTwo != basePath) + if (_downstreamPathTwo != basePath) { context.Response.StatusCode = statusCode; await context.Response.WriteAsync("downstream path didnt match base path"); diff --git a/test/Ocelot.AcceptanceTests/Caching/InMemoryJsonHandle.cs b/test/Ocelot.AcceptanceTests/Caching/InMemoryJsonHandle.cs index fc376445..9c12ad60 100644 --- a/test/Ocelot.AcceptanceTests/Caching/InMemoryJsonHandle.cs +++ b/test/Ocelot.AcceptanceTests/Caching/InMemoryJsonHandle.cs @@ -1,12 +1,12 @@ namespace Ocelot.AcceptanceTests.Caching { - using System; - using System.Collections.Concurrent; - using System.Linq; using CacheManager.Core; using CacheManager.Core.Internal; using CacheManager.Core.Logging; using CacheManager.Core.Utility; + using System; + using System.Collections.Concurrent; + using System.Linq; public class InMemoryJsonHandle : BaseCacheHandle { diff --git a/test/Ocelot.AcceptanceTests/CachingTests.cs b/test/Ocelot.AcceptanceTests/CachingTests.cs index b74e4051..dc0bd99d 100644 --- a/test/Ocelot.AcceptanceTests/CachingTests.cs +++ b/test/Ocelot.AcceptanceTests/CachingTests.cs @@ -1,11 +1,11 @@ namespace Ocelot.AcceptanceTests { + using Configuration.File; + using Microsoft.AspNetCore.Http; using System; using System.Collections.Generic; using System.Net; using System.Threading; - using Configuration.File; - using Microsoft.AspNetCore.Http; using TestStack.BDDfy; using Xunit; diff --git a/test/Ocelot.AcceptanceTests/CannotStartOcelotTests.cs b/test/Ocelot.AcceptanceTests/CannotStartOcelotTests.cs index 5ba30fa3..c08d5eb5 100644 --- a/test/Ocelot.AcceptanceTests/CannotStartOcelotTests.cs +++ b/test/Ocelot.AcceptanceTests/CannotStartOcelotTests.cs @@ -1,9 +1,9 @@ namespace Ocelot.AcceptanceTests { - using System; - using System.Collections.Generic; using Ocelot.Configuration.File; using Shouldly; + using System; + using System.Collections.Generic; using Xunit; public class CannotStartOcelotTests : IDisposable diff --git a/test/Ocelot.AcceptanceTests/CaseSensitiveRoutingTests.cs b/test/Ocelot.AcceptanceTests/CaseSensitiveRoutingTests.cs index ada4355c..405a7c8e 100644 --- a/test/Ocelot.AcceptanceTests/CaseSensitiveRoutingTests.cs +++ b/test/Ocelot.AcceptanceTests/CaseSensitiveRoutingTests.cs @@ -1,10 +1,10 @@ namespace Ocelot.AcceptanceTests { + using Microsoft.AspNetCore.Http; + using Ocelot.Configuration.File; using System; using System.Collections.Generic; using System.Net; - using Microsoft.AspNetCore.Http; - using Ocelot.Configuration.File; using TestStack.BDDfy; using Xunit; @@ -237,4 +237,4 @@ namespace Ocelot.AcceptanceTests _steps.Dispose(); } } -} +} diff --git a/test/Ocelot.AcceptanceTests/ClaimsToHeadersForwardingTests.cs b/test/Ocelot.AcceptanceTests/ClaimsToHeadersForwardingTests.cs index 683b7196..5f16c96f 100644 --- a/test/Ocelot.AcceptanceTests/ClaimsToHeadersForwardingTests.cs +++ b/test/Ocelot.AcceptanceTests/ClaimsToHeadersForwardingTests.cs @@ -1,22 +1,23 @@ using Xunit; [assembly: CollectionBehavior(DisableTestParallelization = true)] + namespace Ocelot.AcceptanceTests { + using IdentityServer4.AccessTokenValidation; + using IdentityServer4.Models; using IdentityServer4.Test; + using Microsoft.AspNetCore.Builder; + using Microsoft.AspNetCore.Hosting; + using Microsoft.AspNetCore.Http; + using Microsoft.Extensions.DependencyInjection; + using Ocelot.Configuration.File; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Security.Claims; - using IdentityServer4.AccessTokenValidation; - using IdentityServer4.Models; - using Microsoft.AspNetCore.Builder; - using Microsoft.AspNetCore.Hosting; - using Microsoft.AspNetCore.Http; - using Microsoft.Extensions.DependencyInjection; - using Ocelot.Configuration.File; using TestStack.BDDfy; public class ClaimsToHeadersForwardingTests : IDisposable @@ -43,22 +44,22 @@ namespace Ocelot.AcceptanceTests [Fact] public void should_return_response_200_and_foward_claim_as_header() - { - var user = new TestUser() - { - Username = "test", - Password = "test", - SubjectId = "registered|1231231", - Claims = new List + { + var user = new TestUser() + { + Username = "test", + Password = "test", + SubjectId = "registered|1231231", + Claims = new List { new Claim("CustomerId", "123"), new Claim("LocationId", "1") - } - }; - - var configuration = new FileConfiguration - { - ReRoutes = new List + } + }; + + var configuration = new FileConfiguration + { + ReRoutes = new List { new FileReRoute { @@ -90,19 +91,19 @@ namespace Ocelot.AcceptanceTests {"UserId", "Claims[sub] > value[1] > |"} } } - } - }; - - this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:52888", "api", AccessTokenType.Jwt, user)) - .And(x => x.GivenThereIsAServiceRunningOn("http://localhost:52876", 200)) - .And(x => _steps.GivenIHaveAToken("http://localhost:52888")) - .And(x => _steps.GivenThereIsAConfiguration(configuration)) - .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) - .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) - .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) - .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) - .And(x => _steps.ThenTheResponseBodyShouldBe("CustomerId: 123 LocationId: 1 UserType: registered UserId: 1231231")) - .BDDfy(); + } + }; + + this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:52888", "api", AccessTokenType.Jwt, user)) + .And(x => x.GivenThereIsAServiceRunningOn("http://localhost:52876", 200)) + .And(x => _steps.GivenIHaveAToken("http://localhost:52888")) + .And(x => _steps.GivenThereIsAConfiguration(configuration)) + .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) + .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) + .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) + .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) + .And(x => _steps.ThenTheResponseBodyShouldBe("CustomerId: 123 LocationId: 1 UserType: registered UserId: 1231231")) + .BDDfy(); } private void GivenThereIsAServiceRunningOn(string url, int statusCode) @@ -196,4 +197,4 @@ namespace Ocelot.AcceptanceTests _identityServerBuilder?.Dispose(); } } -} +} diff --git a/test/Ocelot.AcceptanceTests/ClaimsToQueryStringForwardingTests.cs b/test/Ocelot.AcceptanceTests/ClaimsToQueryStringForwardingTests.cs index 1b9469e1..ad077eb7 100644 --- a/test/Ocelot.AcceptanceTests/ClaimsToQueryStringForwardingTests.cs +++ b/test/Ocelot.AcceptanceTests/ClaimsToQueryStringForwardingTests.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using System.Security.Claims; -using IdentityServer4.AccessTokenValidation; +using IdentityServer4.AccessTokenValidation; using IdentityServer4.Models; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; @@ -12,12 +6,16 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Primitives; using Ocelot.Configuration.File; +using System; +using System.Collections.Generic; +using System.IO; +using System.Net; +using System.Security.Claims; using TestStack.BDDfy; using Xunit; namespace Ocelot.AcceptanceTests { - using IdentityServer4; using IdentityServer4.Test; using Shouldly; @@ -45,22 +43,22 @@ namespace Ocelot.AcceptanceTests [Fact] public void should_return_response_200_and_foward_claim_as_query_string() - { - var user = new TestUser() - { - Username = "test", - Password = "test", - SubjectId = "registered|1231231", - Claims = new List + { + var user = new TestUser() + { + Username = "test", + Password = "test", + SubjectId = "registered|1231231", + Claims = new List { new Claim("CustomerId", "123"), new Claim("LocationId", "1") - } - }; - - var configuration = new FileConfiguration - { - ReRoutes = new List + } + }; + + var configuration = new FileConfiguration + { + ReRoutes = new List { new FileReRoute { @@ -92,39 +90,39 @@ namespace Ocelot.AcceptanceTests {"UserId", "Claims[sub] > value[1] > |"} } } - } - }; - - this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:57888", "api", AccessTokenType.Jwt, user)) - .And(x => x.GivenThereIsAServiceRunningOn("http://localhost:57876", 200)) - .And(x => _steps.GivenIHaveAToken("http://localhost:57888")) - .And(x => _steps.GivenThereIsAConfiguration(configuration)) - .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) - .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) - .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) - .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) - .And(x => _steps.ThenTheResponseBodyShouldBe("CustomerId: 123 LocationId: 1 UserType: registered UserId: 1231231")) - .BDDfy(); + } + }; + + this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:57888", "api", AccessTokenType.Jwt, user)) + .And(x => x.GivenThereIsAServiceRunningOn("http://localhost:57876", 200)) + .And(x => _steps.GivenIHaveAToken("http://localhost:57888")) + .And(x => _steps.GivenThereIsAConfiguration(configuration)) + .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) + .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) + .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) + .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) + .And(x => _steps.ThenTheResponseBodyShouldBe("CustomerId: 123 LocationId: 1 UserType: registered UserId: 1231231")) + .BDDfy(); } [Fact] public void should_return_response_200_and_foward_claim_as_query_string_and_preserve_original_string() - { - var user = new TestUser() - { - Username = "test", - Password = "test", - SubjectId = "registered|1231231", - Claims = new List + { + var user = new TestUser() + { + Username = "test", + Password = "test", + SubjectId = "registered|1231231", + Claims = new List { new Claim("CustomerId", "123"), new Claim("LocationId", "1") - } - }; - - var configuration = new FileConfiguration - { - ReRoutes = new List + } + }; + + var configuration = new FileConfiguration + { + ReRoutes = new List { new FileReRoute { @@ -156,20 +154,20 @@ namespace Ocelot.AcceptanceTests {"UserId", "Claims[sub] > value[1] > |"} } } - } - }; - - this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:57888", "api", AccessTokenType.Jwt, user)) - .And(x => x.GivenThereIsAServiceRunningOn("http://localhost:57876", 200)) - .And(x => _steps.GivenIHaveAToken("http://localhost:57888")) - .And(x => _steps.GivenThereIsAConfiguration(configuration)) - .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) - .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) - .When(x => _steps.WhenIGetUrlOnTheApiGateway("/?test=1&test=2")) - .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) - .And(x => _steps.ThenTheResponseBodyShouldBe("CustomerId: 123 LocationId: 1 UserType: registered UserId: 1231231")) - .And(_ => _downstreamQueryString.ShouldBe("?test=1&test=2&CustomerId=123&LocationId=1&UserId=1231231&UserType=registered")) - .BDDfy(); + } + }; + + this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:57888", "api", AccessTokenType.Jwt, user)) + .And(x => x.GivenThereIsAServiceRunningOn("http://localhost:57876", 200)) + .And(x => _steps.GivenIHaveAToken("http://localhost:57888")) + .And(x => _steps.GivenThereIsAConfiguration(configuration)) + .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) + .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) + .When(x => _steps.WhenIGetUrlOnTheApiGateway("/?test=1&test=2")) + .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) + .And(x => _steps.ThenTheResponseBodyShouldBe("CustomerId: 123 LocationId: 1 UserType: registered UserId: 1231231")) + .And(_ => _downstreamQueryString.ShouldBe("?test=1&test=2&CustomerId=123&LocationId=1&UserId=1231231&UserType=registered")) + .BDDfy(); } private void GivenThereIsAServiceRunningOn(string url, int statusCode) @@ -284,4 +282,4 @@ namespace Ocelot.AcceptanceTests _identityServerBuilder?.Dispose(); } } -} +} diff --git a/test/Ocelot.AcceptanceTests/ClientRateLimitTests.cs b/test/Ocelot.AcceptanceTests/ClientRateLimitTests.cs index d7d31abe..f598d4ad 100644 --- a/test/Ocelot.AcceptanceTests/ClientRateLimitTests.cs +++ b/test/Ocelot.AcceptanceTests/ClientRateLimitTests.cs @@ -60,20 +60,20 @@ DisableRateLimitHeaders = false, QuotaExceededMessage = "", RateLimitCounterPrefix = "", - HttpStatusCode = 428 + HttpStatusCode = 428 }, - RequestIdKey ="oceclientrequest" + RequestIdKey = "oceclientrequest" } }; this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51876", "/api/ClientRateLimit")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) - .When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit("/api/ClientRateLimit",1)) + .When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit("/api/ClientRateLimit", 1)) .Then(x => _steps.ThenTheStatusCodeShouldBe(200)) .When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit("/api/ClientRateLimit", 2)) .Then(x => _steps.ThenTheStatusCodeShouldBe(200)) - .When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit("/api/ClientRateLimit",1)) + .When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit("/api/ClientRateLimit", 1)) .Then(x => _steps.ThenTheStatusCodeShouldBe(428)) .BDDfy(); } @@ -100,7 +100,7 @@ UpstreamPathTemplate = "/api/ClientRateLimit", UpstreamHttpMethod = new List { "Get" }, RequestIdKey = _steps.RequestIdKey, - + RateLimitOptions = new FileRateLimitRule() { EnableRateLimiting = true, @@ -121,24 +121,24 @@ RateLimitCounterPrefix = "", HttpStatusCode = 428 }, - RequestIdKey ="oceclientrequest" + RequestIdKey = "oceclientrequest" } }; this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51926", "/api/ClientRateLimit")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) - .When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit("/api/ClientRateLimit",1)) + .When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit("/api/ClientRateLimit", 1)) .Then(x => _steps.ThenTheStatusCodeShouldBe(200)) .When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit("/api/ClientRateLimit", 2)) .Then(x => _steps.ThenTheStatusCodeShouldBe(200)) - .When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit("/api/ClientRateLimit",1)) + .When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit("/api/ClientRateLimit", 1)) .Then(x => _steps.ThenTheStatusCodeShouldBe(428)) .And(x => _steps.GivenIWait(1000)) - .When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit("/api/ClientRateLimit",1)) + .When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit("/api/ClientRateLimit", 1)) .Then(x => _steps.ThenTheStatusCodeShouldBe(428)) .And(x => _steps.GivenIWait(1000)) - .When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit("/api/ClientRateLimit",1)) + .When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit("/api/ClientRateLimit", 1)) .Then(x => _steps.ThenTheStatusCodeShouldBe(200)) .BDDfy(); } diff --git a/test/Ocelot.AcceptanceTests/ConfigurationInConsulTests.cs b/test/Ocelot.AcceptanceTests/ConfigurationInConsulTests.cs index fdbbb2d2..ae7d6b0a 100644 --- a/test/Ocelot.AcceptanceTests/ConfigurationInConsulTests.cs +++ b/test/Ocelot.AcceptanceTests/ConfigurationInConsulTests.cs @@ -1,16 +1,16 @@ namespace Ocelot.AcceptanceTests { - using System; - using System.Collections.Generic; - using System.IO; - using System.Net; - using System.Text; using Configuration.File; using Consul; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Newtonsoft.Json; + using System; + using System.Collections.Generic; + using System.IO; + using System.Net; + using System.Text; using TestStack.BDDfy; using Xunit; @@ -96,7 +96,7 @@ namespace Ocelot.AcceptanceTests var kvp = new FakeConsulGetResponse(base64); await context.Response.WriteJsonAsync(new FakeConsulGetResponse[] { kvp }); - } + } else if (context.Request.Method.ToLower() == "put" && context.Request.Path.Value == "/v1/kv/InternalConfiguration") { try diff --git a/test/Ocelot.AcceptanceTests/ConfigurationReloadTests.cs b/test/Ocelot.AcceptanceTests/ConfigurationReloadTests.cs index f5a23938..90d57504 100644 --- a/test/Ocelot.AcceptanceTests/ConfigurationReloadTests.cs +++ b/test/Ocelot.AcceptanceTests/ConfigurationReloadTests.cs @@ -1,10 +1,5 @@ using Ocelot.Configuration.File; -using Ocelot.Configuration.Setter; -using Ocelot.Middleware; -using Shouldly; using System; -using System.Collections.Generic; -using System.Text; using TestStack.BDDfy; using Xunit; @@ -39,7 +34,7 @@ namespace Ocelot.AcceptanceTests [Fact] public void should_reload_config_on_change() - { + { this.Given(x => _steps.GivenThereIsAConfiguration(_initialConfig)) .And(x => _steps.GivenOcelotIsRunningReloadingConfig(true)) .And(x => _steps.GivenThereIsAConfiguration(_anotherConfig)) @@ -51,7 +46,6 @@ namespace Ocelot.AcceptanceTests [Fact] public void should_not_reload_config_on_change() { - this.Given(x => _steps.GivenThereIsAConfiguration(_initialConfig)) .And(x => _steps.GivenOcelotIsRunningReloadingConfig(false)) .And(x => _steps.GivenThereIsAConfiguration(_anotherConfig)) diff --git a/test/Ocelot.AcceptanceTests/ConsulConfigurationInConsulTests.cs b/test/Ocelot.AcceptanceTests/ConsulConfigurationInConsulTests.cs index 1cc19260..27f8dee8 100644 --- a/test/Ocelot.AcceptanceTests/ConsulConfigurationInConsulTests.cs +++ b/test/Ocelot.AcceptanceTests/ConsulConfigurationInConsulTests.cs @@ -1,10 +1,5 @@ namespace Ocelot.AcceptanceTests { - using System; - using System.Collections.Generic; - using System.IO; - using System.Net; - using System.Text; using Cache; using Configuration.File; using Consul; @@ -14,6 +9,11 @@ using Microsoft.AspNetCore.Http; using Newtonsoft.Json; using Shouldly; + using System; + using System.Collections.Generic; + using System.IO; + using System.Net; + using System.Text; using TestStack.BDDfy; using Xunit; @@ -312,7 +312,8 @@ private void ThenTheConfigIsUpdatedInOcelot() { - var result = Wait.WaitFor(20000).Until(() => { + var result = Wait.WaitFor(20000).Until(() => + { try { _steps.WhenIGetUrlOnTheApiGateway("/cs/status/awesome"); @@ -444,7 +445,7 @@ _steps.Dispose(); } - class FakeCache : IOcelotCache + private class FakeCache : IOcelotCache { public void Add(string key, FileConfiguration value, TimeSpan ttl, string region) { diff --git a/test/Ocelot.AcceptanceTests/ConsulWebSocketTests.cs b/test/Ocelot.AcceptanceTests/ConsulWebSocketTests.cs index 10ec9880..8ed9b140 100644 --- a/test/Ocelot.AcceptanceTests/ConsulWebSocketTests.cs +++ b/test/Ocelot.AcceptanceTests/ConsulWebSocketTests.cs @@ -1,16 +1,16 @@ namespace Ocelot.AcceptanceTests { + using Configuration.File; + using Consul; + using Microsoft.AspNetCore.Http; + using Newtonsoft.Json; + using Shouldly; using System; using System.Collections.Generic; using System.Net.WebSockets; using System.Text; using System.Threading; using System.Threading.Tasks; - using Configuration.File; - using Consul; - using Microsoft.AspNetCore.Http; - using Newtonsoft.Json; - using Shouldly; using TestStack.BDDfy; using Xunit; @@ -130,7 +130,7 @@ { if (context.Request.Path.Value == $"/v1/health/service/{serviceName}") { - var json = JsonConvert.SerializeObject(_serviceEntries); + var json = JsonConvert.SerializeObject(_serviceEntries); context.Response.Headers.Add("Content-Type", "application/json"); await context.Response.WriteAsync(json); } diff --git a/test/Ocelot.AcceptanceTests/ContentTests.cs b/test/Ocelot.AcceptanceTests/ContentTests.cs index b92b4a99..39299f74 100644 --- a/test/Ocelot.AcceptanceTests/ContentTests.cs +++ b/test/Ocelot.AcceptanceTests/ContentTests.cs @@ -1,11 +1,11 @@ namespace Ocelot.AcceptanceTests { - using System; - using System.Collections.Generic; - using System.Net; using Microsoft.AspNetCore.Http; using Ocelot.Configuration.File; using Shouldly; + using System; + using System.Collections.Generic; + using System.Net; using TestStack.BDDfy; using Xunit; @@ -123,7 +123,6 @@ namespace Ocelot.AcceptanceTests } }; - this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51359", "/", 201, string.Empty)) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) diff --git a/test/Ocelot.AcceptanceTests/CustomMiddlewareTests.cs b/test/Ocelot.AcceptanceTests/CustomMiddlewareTests.cs index 7ed105c3..bbfce600 100644 --- a/test/Ocelot.AcceptanceTests/CustomMiddlewareTests.cs +++ b/test/Ocelot.AcceptanceTests/CustomMiddlewareTests.cs @@ -1,14 +1,14 @@ namespace Ocelot.AcceptanceTests { + using Microsoft.AspNetCore.Http; + using Ocelot.Configuration.File; + using Ocelot.Middleware; + using Shouldly; using System; using System.Collections.Generic; using System.Diagnostics; using System.Net; using System.Threading.Tasks; - using Microsoft.AspNetCore.Http; - using Ocelot.Configuration.File; - using Ocelot.Middleware; - using Shouldly; using TestStack.BDDfy; using Xunit; @@ -283,8 +283,8 @@ .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .And(x => x.ThenTheCounterIs(1)) .BDDfy(); - } - + } + [Fact(Skip = "This is just an example to show how you could hook into Ocelot pipeline with your own middleware. At the moment you must use Response.OnCompleted callback and cannot change the response :( I will see if this can be changed one day!")] public void should_fix_issue_237() { @@ -293,7 +293,7 @@ var httpContext = (HttpContext)state; if (httpContext.Response.StatusCode > 400) - { + { Debug.WriteLine("COUNT CALLED"); Console.WriteLine("COUNT CALLED"); } @@ -362,8 +362,8 @@ public class FakeMiddleware { private readonly RequestDelegate _next; - private readonly Func _callback; - + private readonly Func _callback; + public FakeMiddleware(RequestDelegate next, Func callback) { _next = next; @@ -372,10 +372,10 @@ public async Task Invoke(HttpContext context) { - await _next(context); - + await _next(context); + context.Response.OnCompleted(_callback, context); } } } -} +} diff --git a/test/Ocelot.AcceptanceTests/EurekaServiceDiscoveryTests.cs b/test/Ocelot.AcceptanceTests/EurekaServiceDiscoveryTests.cs index 75a7eaeb..3029249c 100644 --- a/test/Ocelot.AcceptanceTests/EurekaServiceDiscoveryTests.cs +++ b/test/Ocelot.AcceptanceTests/EurekaServiceDiscoveryTests.cs @@ -1,12 +1,12 @@ namespace Ocelot.AcceptanceTests { - using System; - using System.Collections.Generic; - using System.Net; using Configuration.File; using Microsoft.AspNetCore.Http; using Newtonsoft.Json; using Steeltoe.Common.Discovery; + using System; + using System.Collections.Generic; + using System.Net; using TestStack.BDDfy; using Xunit; diff --git a/test/Ocelot.AcceptanceTests/GzipTests.cs b/test/Ocelot.AcceptanceTests/GzipTests.cs index faa0c55d..bb03c9c5 100644 --- a/test/Ocelot.AcceptanceTests/GzipTests.cs +++ b/test/Ocelot.AcceptanceTests/GzipTests.cs @@ -1,14 +1,14 @@ namespace Ocelot.AcceptanceTests { + using Microsoft.AspNetCore.Http; + using Ocelot.Configuration.File; + using Shouldly; using System; using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Linq; using System.Net; - using Microsoft.AspNetCore.Http; - using Ocelot.Configuration.File; - using Shouldly; using TestStack.BDDfy; using Xunit; @@ -48,8 +48,8 @@ namespace Ocelot.AcceptanceTests } }; - var input = "people"; - + var input = "people"; + this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879", "/", 200, "Hello from Laura", "\"people\"")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) @@ -99,4 +99,4 @@ namespace Ocelot.AcceptanceTests _steps.Dispose(); } } -} +} diff --git a/test/Ocelot.AcceptanceTests/HeaderTests.cs b/test/Ocelot.AcceptanceTests/HeaderTests.cs index 839157e5..d3c82307 100644 --- a/test/Ocelot.AcceptanceTests/HeaderTests.cs +++ b/test/Ocelot.AcceptanceTests/HeaderTests.cs @@ -1,13 +1,12 @@ namespace Ocelot.AcceptanceTests { + using Microsoft.AspNetCore.Http; + using Ocelot.Configuration.File; using System; using System.Collections.Generic; using System.Linq; using System.Net; - using System.Net.Sockets; using System.Threading.Tasks; - using Microsoft.AspNetCore.Http; - using Ocelot.Configuration.File; using TestStack.BDDfy; using Xunit; @@ -215,10 +214,10 @@ namespace Ocelot.AcceptanceTests } } }, - GlobalConfiguration = new FileGlobalConfiguration - { - BaseUrl = "http://anotherapp.azurewebsites.net" - } + GlobalConfiguration = new FileGlobalConfiguration + { + BaseUrl = "http://anotherapp.azurewebsites.net" + } }; this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:6773", "/", 302, "Location", "http://localhost:6773/pay/Receive")) diff --git a/test/Ocelot.AcceptanceTests/HttpClientCachingTests.cs b/test/Ocelot.AcceptanceTests/HttpClientCachingTests.cs index 85b17daf..f653865a 100644 --- a/test/Ocelot.AcceptanceTests/HttpClientCachingTests.cs +++ b/test/Ocelot.AcceptanceTests/HttpClientCachingTests.cs @@ -1,14 +1,14 @@ namespace Ocelot.AcceptanceTests { - using System; - using System.Collections.Concurrent; - using System.Collections.Generic; - using System.Net; using Configuration; using Microsoft.AspNetCore.Http; using Ocelot.Configuration.File; using Requester; using Shouldly; + using System; + using System.Collections.Concurrent; + using System.Collections.Generic; + using System.Net; using TestStack.BDDfy; using Xunit; @@ -122,7 +122,7 @@ namespace Ocelot.AcceptanceTests .BDDfy(); } - private void GivenThereIsAServiceRunningOn(string baseUrl, int statusCode, string responseBody) + private void GivenThereIsAServiceRunningOn(string baseUrl, int statusCode, string responseBody) { _serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, async context => { diff --git a/test/Ocelot.AcceptanceTests/HttpDelegatingHandlersTests.cs b/test/Ocelot.AcceptanceTests/HttpDelegatingHandlersTests.cs index a508f1d4..dc985e42 100644 --- a/test/Ocelot.AcceptanceTests/HttpDelegatingHandlersTests.cs +++ b/test/Ocelot.AcceptanceTests/HttpDelegatingHandlersTests.cs @@ -1,14 +1,14 @@ namespace Ocelot.AcceptanceTests { + using Microsoft.AspNetCore.Http; + using Ocelot.Configuration.File; + using Shouldly; using System; using System.Collections.Generic; using System.Net; using System.Net.Http; using System.Threading; using System.Threading.Tasks; - using Microsoft.AspNetCore.Http; - using Ocelot.Configuration.File; - using Shouldly; using TestStack.BDDfy; using Xunit; @@ -147,7 +147,7 @@ .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura")) - .BDDfy(); + .BDDfy(); } [Fact] @@ -203,7 +203,7 @@ } public class FakeDependency - { + { public bool Called; } @@ -226,7 +226,7 @@ // ReSharper disable once ClassNeverInstantiated.Local private class FakeHandler : DelegatingHandler - { + { public static DateTime TimeCalled { get; private set; } protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) @@ -238,7 +238,7 @@ // ReSharper disable once ClassNeverInstantiated.Local private class FakeHandlerTwo : DelegatingHandler - { + { public static DateTime TimeCalled { get; private set; } protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) diff --git a/test/Ocelot.AcceptanceTests/LoadBalancerTests.cs b/test/Ocelot.AcceptanceTests/LoadBalancerTests.cs index e6832efc..b3adf531 100644 --- a/test/Ocelot.AcceptanceTests/LoadBalancerTests.cs +++ b/test/Ocelot.AcceptanceTests/LoadBalancerTests.cs @@ -1,11 +1,11 @@ namespace Ocelot.AcceptanceTests { - using System; - using System.Collections.Generic; using Microsoft.AspNetCore.Http; using Ocelot.Configuration.File; using Ocelot.LoadBalancer.LoadBalancers; using Shouldly; + using System; + using System.Collections.Generic; using TestStack.BDDfy; using Xunit; @@ -58,9 +58,9 @@ namespace Ocelot.AcceptanceTests } } }, - GlobalConfiguration = new FileGlobalConfiguration() - { - } + GlobalConfiguration = new FileGlobalConfiguration() + { + } }; this.Given(x => x.GivenProductServiceOneIsRunning(downstreamServiceOneUrl, 200)) @@ -107,9 +107,9 @@ namespace Ocelot.AcceptanceTests } } }, - GlobalConfiguration = new FileGlobalConfiguration() - { - } + GlobalConfiguration = new FileGlobalConfiguration() + { + } }; this.Given(x => x.GivenProductServiceOneIsRunning(downstreamServiceOneUrl, 200)) diff --git a/test/Ocelot.AcceptanceTests/PollyQoSTests.cs b/test/Ocelot.AcceptanceTests/PollyQoSTests.cs index 61e39a98..9829e8f3 100644 --- a/test/Ocelot.AcceptanceTests/PollyQoSTests.cs +++ b/test/Ocelot.AcceptanceTests/PollyQoSTests.cs @@ -1,12 +1,12 @@ namespace Ocelot.AcceptanceTests { + using Configuration.File; + using Microsoft.AspNetCore.Http; using System; using System.Collections.Generic; using System.Net; using System.Threading; using System.Threading.Tasks; - using Configuration.File; - using Microsoft.AspNetCore.Http; using TestStack.BDDfy; using Xunit; @@ -218,7 +218,7 @@ .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura")) .BDDfy(); } - + private void GivenIWaitMilliseconds(int ms) { Thread.Sleep(ms); diff --git a/test/Ocelot.AcceptanceTests/Properties/AssemblyInfo.cs b/test/Ocelot.AcceptanceTests/Properties/AssemblyInfo.cs index 7ad0f5bb..e764d205 100644 --- a/test/Ocelot.AcceptanceTests/Properties/AssemblyInfo.cs +++ b/test/Ocelot.AcceptanceTests/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following @@ -16,4 +15,4 @@ using System.Runtime.InteropServices; [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("f8c224fe-36be-45f5-9b0e-666d8f4a9b52")] +[assembly: Guid("f8c224fe-36be-45f5-9b0e-666d8f4a9b52")] diff --git a/test/Ocelot.AcceptanceTests/ReasonPhraseTests.cs b/test/Ocelot.AcceptanceTests/ReasonPhraseTests.cs index 14742b86..44874115 100644 --- a/test/Ocelot.AcceptanceTests/ReasonPhraseTests.cs +++ b/test/Ocelot.AcceptanceTests/ReasonPhraseTests.cs @@ -1,12 +1,10 @@ namespace Ocelot.AcceptanceTests { - using System; - using System.Collections.Generic; - using System.Net; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Ocelot.Configuration.File; - using Shouldly; + using System; + using System.Collections.Generic; using TestStack.BDDfy; using Xunit; diff --git a/test/Ocelot.AcceptanceTests/RequestIdTests.cs b/test/Ocelot.AcceptanceTests/RequestIdTests.cs index 6acc36bd..bef0bc51 100644 --- a/test/Ocelot.AcceptanceTests/RequestIdTests.cs +++ b/test/Ocelot.AcceptanceTests/RequestIdTests.cs @@ -1,10 +1,10 @@ namespace Ocelot.AcceptanceTests { + using Ocelot.Configuration.File; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; - using Ocelot.Configuration.File; using TestStack.BDDfy; using Xunit; @@ -180,4 +180,4 @@ _steps.Dispose(); } } -} +} diff --git a/test/Ocelot.AcceptanceTests/ResponseCodeTests.cs b/test/Ocelot.AcceptanceTests/ResponseCodeTests.cs index 244511c4..4da4ca74 100644 --- a/test/Ocelot.AcceptanceTests/ResponseCodeTests.cs +++ b/test/Ocelot.AcceptanceTests/ResponseCodeTests.cs @@ -1,9 +1,9 @@ namespace Ocelot.AcceptanceTests { + using Ocelot.Configuration.File; using System; using System.Collections.Generic; using System.Net; - using Ocelot.Configuration.File; using TestStack.BDDfy; using Xunit; diff --git a/test/Ocelot.AcceptanceTests/ReturnsErrorTests.cs b/test/Ocelot.AcceptanceTests/ReturnsErrorTests.cs index 7615e0b4..f72efff8 100644 --- a/test/Ocelot.AcceptanceTests/ReturnsErrorTests.cs +++ b/test/Ocelot.AcceptanceTests/ReturnsErrorTests.cs @@ -1,10 +1,9 @@ namespace Ocelot.AcceptanceTests { + using Ocelot.Configuration.File; using System; using System.Collections.Generic; using System.Net; - using Microsoft.AspNetCore.Http; - using Ocelot.Configuration.File; using TestStack.BDDfy; using Xunit; @@ -63,4 +62,4 @@ _steps.Dispose(); } } -} +} diff --git a/test/Ocelot.AcceptanceTests/RoutingTests.cs b/test/Ocelot.AcceptanceTests/RoutingTests.cs index d3379aa1..9c20a8f0 100644 --- a/test/Ocelot.AcceptanceTests/RoutingTests.cs +++ b/test/Ocelot.AcceptanceTests/RoutingTests.cs @@ -1,11 +1,11 @@ namespace Ocelot.AcceptanceTests { - using System; - using System.Collections.Generic; - using System.Net; using Microsoft.AspNetCore.Http; using Ocelot.Configuration.File; using Shouldly; + using System; + using System.Collections.Generic; + using System.Net; using TestStack.BDDfy; using Xunit; diff --git a/test/Ocelot.AcceptanceTests/RoutingWithQueryStringTests.cs b/test/Ocelot.AcceptanceTests/RoutingWithQueryStringTests.cs index ccb9fa4a..58e54b2f 100644 --- a/test/Ocelot.AcceptanceTests/RoutingWithQueryStringTests.cs +++ b/test/Ocelot.AcceptanceTests/RoutingWithQueryStringTests.cs @@ -1,10 +1,10 @@ namespace Ocelot.AcceptanceTests { + using Microsoft.AspNetCore.Http; + using Ocelot.Configuration.File; using System; using System.Collections.Generic; using System.Net; - using Microsoft.AspNetCore.Http; - using Ocelot.Configuration.File; using TestStack.BDDfy; using Xunit; diff --git a/test/Ocelot.AcceptanceTests/ServiceDiscoveryTests.cs b/test/Ocelot.AcceptanceTests/ServiceDiscoveryTests.cs index d93e6911..b464a3d1 100644 --- a/test/Ocelot.AcceptanceTests/ServiceDiscoveryTests.cs +++ b/test/Ocelot.AcceptanceTests/ServiceDiscoveryTests.cs @@ -1,14 +1,14 @@ namespace Ocelot.AcceptanceTests { - using System; - using System.Collections.Generic; - using System.Linq; - using System.Net; using Configuration.File; using Consul; using Microsoft.AspNetCore.Http; using Newtonsoft.Json; using Shouldly; + using System; + using System.Collections.Generic; + using System.Linq; + using System.Net; using TestStack.BDDfy; using Xunit; diff --git a/test/Ocelot.AcceptanceTests/ServiceFabricTests.cs b/test/Ocelot.AcceptanceTests/ServiceFabricTests.cs index 606bd691..57dd3855 100644 --- a/test/Ocelot.AcceptanceTests/ServiceFabricTests.cs +++ b/test/Ocelot.AcceptanceTests/ServiceFabricTests.cs @@ -1,10 +1,10 @@ namespace Ocelot.AcceptanceTests { + using Microsoft.AspNetCore.Http; + using Ocelot.Configuration.File; using System; using System.Collections.Generic; using System.Net; - using Microsoft.AspNetCore.Http; - using Ocelot.Configuration.File; using TestStack.BDDfy; using Xunit; diff --git a/test/Ocelot.AcceptanceTests/ServiceHandler.cs b/test/Ocelot.AcceptanceTests/ServiceHandler.cs index 6af5ba6a..c10c122b 100644 --- a/test/Ocelot.AcceptanceTests/ServiceHandler.cs +++ b/test/Ocelot.AcceptanceTests/ServiceHandler.cs @@ -1,15 +1,14 @@ namespace Ocelot.AcceptanceTests { - using System; - using System.IO; - using System.Net; - using System.Net.WebSockets; - using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; + using System; + using System.IO; + using System.Net; + using System.Threading.Tasks; public class ServiceHandler : IDisposable { diff --git a/test/Ocelot.AcceptanceTests/SslTests.cs b/test/Ocelot.AcceptanceTests/SslTests.cs index e0ee5977..a0ea17a4 100644 --- a/test/Ocelot.AcceptanceTests/SslTests.cs +++ b/test/Ocelot.AcceptanceTests/SslTests.cs @@ -1,10 +1,10 @@ namespace Ocelot.AcceptanceTests { + using Microsoft.AspNetCore.Http; + using Ocelot.Configuration.File; using System; using System.Collections.Generic; using System.Net; - using Microsoft.AspNetCore.Http; - using Ocelot.Configuration.File; using TestStack.BDDfy; using Xunit; @@ -118,4 +118,4 @@ namespace Ocelot.AcceptanceTests _steps.Dispose(); } } -} +} diff --git a/test/Ocelot.AcceptanceTests/StartupTests.cs b/test/Ocelot.AcceptanceTests/StartupTests.cs index e0dbe0ac..3bab3f57 100644 --- a/test/Ocelot.AcceptanceTests/StartupTests.cs +++ b/test/Ocelot.AcceptanceTests/StartupTests.cs @@ -1,14 +1,14 @@ namespace Ocelot.AcceptanceTests { + using Configuration.Repository; + using Microsoft.AspNetCore.Http; + using Ocelot.Configuration.File; + using Responses; using System; using System.Collections.Generic; using System.IO; using System.Net; using System.Threading.Tasks; - using Configuration.Repository; - using Microsoft.AspNetCore.Http; - using Ocelot.Configuration.File; - using Responses; using TestStack.BDDfy; using Xunit; @@ -84,7 +84,7 @@ _steps.Dispose(); } - class FakeFileConfigurationRepository : IFileConfigurationRepository + private class FakeFileConfigurationRepository : IFileConfigurationRepository { public Task> Get() { diff --git a/test/Ocelot.AcceptanceTests/Steps.cs b/test/Ocelot.AcceptanceTests/Steps.cs index dd1fdab8..6b9870bd 100644 --- a/test/Ocelot.AcceptanceTests/Steps.cs +++ b/test/Ocelot.AcceptanceTests/Steps.cs @@ -1,14 +1,8 @@ namespace Ocelot.AcceptanceTests { - using System; - using System.Collections.Generic; - using System.IO; - using System.Linq; - using System.Net; - using System.Net.Http; - using System.Net.Http.Headers; - using System.Threading; - using System.Threading.Tasks; + using Caching; + using Configuration.Repository; + using global::CacheManager.Core; using IdentityServer4.AccessTokenValidation; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; @@ -17,29 +11,34 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Newtonsoft.Json; + using Ocelot.Cache.CacheManager; + using Ocelot.Configuration.Creator; using Ocelot.Configuration.File; using Ocelot.DependencyInjection; + using Ocelot.Infrastructure; using Ocelot.Middleware; - using Shouldly; - using ConfigurationBuilder = Microsoft.Extensions.Configuration.ConfigurationBuilder; - using System.IO.Compression; - using System.Text; - using Caching; - using static Ocelot.AcceptanceTests.HttpDelegatingHandlersTests; using Ocelot.Middleware.Multiplexer; - using static Ocelot.Infrastructure.Wait; - using Configuration.Repository; - using Ocelot.Configuration.Creator; - using Requester; - using CookieHeaderValue = System.Net.Http.Headers.CookieHeaderValue; - using MediaTypeHeaderValue = System.Net.Http.Headers.MediaTypeHeaderValue; - using global::CacheManager.Core; - using Ocelot.Cache.CacheManager; using Ocelot.Provider.Consul; using Ocelot.Provider.Eureka; - using Ocelot.Infrastructure; using Ocelot.Provider.Polly; using Ocelot.Tracing.Butterfly; + using Requester; + using Shouldly; + using System; + using System.Collections.Generic; + using System.IO; + using System.IO.Compression; + using System.Linq; + using System.Net; + using System.Net.Http; + using System.Net.Http.Headers; + using System.Text; + using System.Threading; + using System.Threading.Tasks; + using static Ocelot.AcceptanceTests.HttpDelegatingHandlersTests; + using ConfigurationBuilder = Microsoft.Extensions.Configuration.ConfigurationBuilder; + using CookieHeaderValue = System.Net.Http.Headers.CookieHeaderValue; + using MediaTypeHeaderValue = System.Net.Http.Headers.MediaTypeHeaderValue; public class Steps : IDisposable { diff --git a/test/Ocelot.AcceptanceTests/StickySessionsTests.cs b/test/Ocelot.AcceptanceTests/StickySessionsTests.cs index 68bb7c3f..77f8b176 100644 --- a/test/Ocelot.AcceptanceTests/StickySessionsTests.cs +++ b/test/Ocelot.AcceptanceTests/StickySessionsTests.cs @@ -1,10 +1,10 @@ namespace Ocelot.AcceptanceTests { - using System; - using System.Collections.Generic; using Microsoft.AspNetCore.Http; using Ocelot.Configuration.File; using Shouldly; + using System; + using System.Collections.Generic; using TestStack.BDDfy; using Xunit; diff --git a/test/Ocelot.AcceptanceTests/TestConfiguration.cs b/test/Ocelot.AcceptanceTests/TestConfiguration.cs index 6f5818ca..2bc9d807 100644 --- a/test/Ocelot.AcceptanceTests/TestConfiguration.cs +++ b/test/Ocelot.AcceptanceTests/TestConfiguration.cs @@ -7,4 +7,4 @@ namespace Ocelot.AcceptanceTests { public static string ConfigurationPath => Path.Combine(AppContext.BaseDirectory, "ocelot.json"); } -} +} diff --git a/test/Ocelot.AcceptanceTests/TwoDownstreamServicesTests.cs b/test/Ocelot.AcceptanceTests/TwoDownstreamServicesTests.cs index de54b0e0..284ebd6f 100644 --- a/test/Ocelot.AcceptanceTests/TwoDownstreamServicesTests.cs +++ b/test/Ocelot.AcceptanceTests/TwoDownstreamServicesTests.cs @@ -1,12 +1,12 @@ namespace Ocelot.AcceptanceTests { - using System; - using System.Collections.Generic; - using System.Net; using Configuration.File; using Consul; using Microsoft.AspNetCore.Http; using Newtonsoft.Json; + using System; + using System.Collections.Generic; + using System.Net; using TestStack.BDDfy; using Xunit; diff --git a/test/Ocelot.AcceptanceTests/UpstreamHostTests.cs b/test/Ocelot.AcceptanceTests/UpstreamHostTests.cs index aa4affde..4af5a974 100644 --- a/test/Ocelot.AcceptanceTests/UpstreamHostTests.cs +++ b/test/Ocelot.AcceptanceTests/UpstreamHostTests.cs @@ -1,10 +1,10 @@ namespace Ocelot.AcceptanceTests { + using Microsoft.AspNetCore.Http; + using Ocelot.Configuration.File; using System; using System.Collections.Generic; using System.Net; - using Microsoft.AspNetCore.Http; - using Ocelot.Configuration.File; using TestStack.BDDfy; using Xunit; diff --git a/test/Ocelot.AcceptanceTests/WebSocketTests.cs b/test/Ocelot.AcceptanceTests/WebSocketTests.cs index 77661613..e98a1bf9 100644 --- a/test/Ocelot.AcceptanceTests/WebSocketTests.cs +++ b/test/Ocelot.AcceptanceTests/WebSocketTests.cs @@ -1,13 +1,13 @@ namespace Ocelot.AcceptanceTests { + using Ocelot.Configuration.File; + using Shouldly; using System; using System.Collections.Generic; using System.Net.WebSockets; using System.Text; using System.Threading; using System.Threading.Tasks; - using Ocelot.Configuration.File; - using Shouldly; using TestStack.BDDfy; using Xunit; @@ -99,7 +99,7 @@ namespace Ocelot.AcceptanceTests this.Given(_ => _steps.GivenThereIsAConfiguration(config)) .And(_ => _steps.StartFakeOcelotWithWebSockets()) .And(_ => StartFakeDownstreamService($"http://{downstreamHost}:{downstreamPort}", "/ws")) - .And(_ => StartSecondFakeDownstreamService($"http://{secondDownstreamHost}:{secondDownstreamPort}","/ws")) + .And(_ => StartSecondFakeDownstreamService($"http://{secondDownstreamHost}:{secondDownstreamPort}", "/ws")) .When(_ => WhenIStartTheClients()) .Then(_ => ThenBothDownstreamServicesAreCalled()) .BDDfy(); @@ -132,7 +132,7 @@ namespace Ocelot.AcceptanceTests private async Task StartClient(string url) { var client = new ClientWebSocket(); - + await client.ConnectAsync(new Uri(url), CancellationToken.None); var sending = Task.Run(async () => @@ -221,7 +221,7 @@ namespace Ocelot.AcceptanceTests private async Task StartFakeDownstreamService(string url, string path) { - await _serviceHandler.StartFakeDownstreamService(url, path, async(context, next) => + await _serviceHandler.StartFakeDownstreamService(url, path, async (context, next) => { if (context.Request.Path == path) { diff --git a/test/Ocelot.AcceptanceTests/appsettings.json b/test/Ocelot.AcceptanceTests/appsettings.json index 36499f4d..fd57aaac 100644 --- a/test/Ocelot.AcceptanceTests/appsettings.json +++ b/test/Ocelot.AcceptanceTests/appsettings.json @@ -18,7 +18,7 @@ "shouldRegisterWithEureka": true, "shouldFetchRegistry": true, "port": 5000, - "hostName": "localhost" + "hostName": "localhost" } } -} +} diff --git a/test/Ocelot.Benchmarks/DictionaryBenchmarks.cs b/test/Ocelot.Benchmarks/DictionaryBenchmarks.cs index 05d5b6ba..5799ca42 100644 --- a/test/Ocelot.Benchmarks/DictionaryBenchmarks.cs +++ b/test/Ocelot.Benchmarks/DictionaryBenchmarks.cs @@ -1,16 +1,16 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Columns; using BenchmarkDotNet.Configs; -using System.Net.Http; using BenchmarkDotNet.Diagnosers; using BenchmarkDotNet.Validators; +using System.Net.Http; namespace Ocelot.Benchmarks { - using System.Collections.Concurrent; using Configuration; using Configuration.Builder; using Requester; + using System.Collections.Concurrent; [Config(typeof(DictionaryBenchmarks))] public class DictionaryBenchmarks : ManualConfig diff --git a/test/Ocelot.Benchmarks/Properties/AssemblyInfo.cs b/test/Ocelot.Benchmarks/Properties/AssemblyInfo.cs index e39a657b..5a8d8f37 100644 --- a/test/Ocelot.Benchmarks/Properties/AssemblyInfo.cs +++ b/test/Ocelot.Benchmarks/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following @@ -16,4 +15,4 @@ using System.Runtime.InteropServices; [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("106b49e6-95f6-4a7b-b81c-96bfa74af035")] +[assembly: Guid("106b49e6-95f6-4a7b-b81c-96bfa74af035")] diff --git a/test/Ocelot.Benchmarks/UrlPathToUrlPathTemplateMatcherBenchmarks.cs b/test/Ocelot.Benchmarks/UrlPathToUrlPathTemplateMatcherBenchmarks.cs index a7ee0d7e..4bd20b1e 100644 --- a/test/Ocelot.Benchmarks/UrlPathToUrlPathTemplateMatcherBenchmarks.cs +++ b/test/Ocelot.Benchmarks/UrlPathToUrlPathTemplateMatcherBenchmarks.cs @@ -1,4 +1,3 @@ -using System; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Columns; using BenchmarkDotNet.Configs; diff --git a/test/Ocelot.IntegrationTests/AdministrationTests.cs b/test/Ocelot.IntegrationTests/AdministrationTests.cs index ac1ce4e8..5b5895cd 100644 --- a/test/Ocelot.IntegrationTests/AdministrationTests.cs +++ b/test/Ocelot.IntegrationTests/AdministrationTests.cs @@ -1,10 +1,3 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Security.Claims; using IdentityServer4.AccessTokenValidation; using IdentityServer4.Models; using IdentityServer4.Test; @@ -13,17 +6,21 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; using Newtonsoft.Json; +using Ocelot.Administration; using Ocelot.Cache; using Ocelot.Configuration.File; using Ocelot.DependencyInjection; using Ocelot.Middleware; using Shouldly; +using System; +using System.Collections.Generic; +using System.IO; +using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; using TestStack.BDDfy; using Xunit; -using Ocelot.Administration; -using Ocelot.IntegrationTests; namespace Ocelot.IntegrationTests { @@ -62,19 +59,19 @@ namespace Ocelot.IntegrationTests .BDDfy(); } - [Fact] - public void should_return_response_200_with_call_re_routes_controller() - { + [Fact] + public void should_return_response_200_with_call_re_routes_controller() + { var configuration = new FileConfiguration(); - this.Given(x => GivenThereIsAConfiguration(configuration)) - .And(x => GivenOcelotIsRunning()) - .And(x => GivenIHaveAnOcelotToken("/administration")) - .And(x => GivenIHaveAddedATokenToMyRequest()) - .When(x => WhenIGetUrlOnTheApiGateway("/administration/configuration")) - .Then(x => ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) - .BDDfy(); - } + this.Given(x => GivenThereIsAConfiguration(configuration)) + .And(x => GivenOcelotIsRunning()) + .And(x => GivenIHaveAnOcelotToken("/administration")) + .And(x => GivenIHaveAddedATokenToMyRequest()) + .When(x => WhenIGetUrlOnTheApiGateway("/administration/configuration")) + .Then(x => ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) + .BDDfy(); + } [Fact] public void should_return_response_200_with_call_re_routes_controller_using_base_url_added_in_file_config() @@ -226,7 +223,7 @@ namespace Ocelot.IntegrationTests } }; - var updatedConfiguration = new FileConfiguration + var updatedConfiguration = new FileConfiguration { GlobalConfiguration = new FileGlobalConfiguration { @@ -321,7 +318,7 @@ namespace Ocelot.IntegrationTests } }; - var updatedConfiguration = new FileConfiguration + var updatedConfiguration = new FileConfiguration { GlobalConfiguration = new FileGlobalConfiguration { @@ -429,14 +426,15 @@ namespace Ocelot.IntegrationTests .BDDfy(); } - [Fact] - public void should_return_response_200_with_call_re_routes_controller_when_using_own_identity_server_to_secure_admin_area() - { + [Fact] + public void should_return_response_200_with_call_re_routes_controller_when_using_own_identity_server_to_secure_admin_area() + { var configuration = new FileConfiguration(); var identityServerRootUrl = "http://localhost:5123"; - Action options = o => { + Action options = o => + { o.Authority = identityServerRootUrl; o.ApiName = "api"; o.RequireHttpsMetadata = false; @@ -444,15 +442,15 @@ namespace Ocelot.IntegrationTests o.ApiSecret = "secret"; }; - this.Given(x => GivenThereIsAConfiguration(configuration)) - .And(x => GivenThereIsAnIdentityServerOn(identityServerRootUrl, "api")) - .And(x => GivenOcelotIsRunningWithIdentityServerSettings(options)) - .And(x => GivenIHaveAToken(identityServerRootUrl)) - .And(x => GivenIHaveAddedATokenToMyRequest()) - .When(x => WhenIGetUrlOnTheApiGateway("/administration/configuration")) - .Then(x => ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) - .BDDfy(); - } + this.Given(x => GivenThereIsAConfiguration(configuration)) + .And(x => GivenThereIsAnIdentityServerOn(identityServerRootUrl, "api")) + .And(x => GivenOcelotIsRunningWithIdentityServerSettings(options)) + .And(x => GivenIHaveAToken(identityServerRootUrl)) + .And(x => GivenIHaveAddedATokenToMyRequest()) + .When(x => WhenIGetUrlOnTheApiGateway("/administration/configuration")) + .Then(x => ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) + .BDDfy(); + } private void GivenIHaveAToken(string url) { @@ -476,7 +474,7 @@ namespace Ocelot.IntegrationTests } } - private void GivenThereIsAnIdentityServerOn(string url, string apiName) + private void GivenThereIsAnIdentityServerOn(string url, string apiName) { _identityServerBuilder = new WebHostBuilder() .UseUrls(url) @@ -529,14 +527,14 @@ namespace Ocelot.IntegrationTests }) .Build(); - _identityServerBuilder.Start(); + _identityServerBuilder.Start(); - using (var httpClient = new HttpClient()) - { - var response = httpClient.GetAsync($"{url}/.well-known/openid-configuration").Result; - response.EnsureSuccessStatusCode(); - } + using (var httpClient = new HttpClient()) + { + var response = httpClient.GetAsync($"{url}/.well-known/openid-configuration").Result; + response.EnsureSuccessStatusCode(); } + } private void GivenAnotherOcelotIsRunning(string baseUrl) { @@ -669,16 +667,18 @@ namespace Ocelot.IntegrationTests config.AddJsonFile("ocelot.json", false, false); config.AddEnvironmentVariables(); }) - .ConfigureServices(x => { + .ConfigureServices(x => + { x.AddSingleton(_webHostBuilder); x.AddOcelot() .AddAdministration("/administration", configOptions); - }) - .Configure(app => { + }) + .Configure(app => + { app.UseOcelot().Wait(); }); - _builder = _webHostBuilder.Build(); + _builder = _webHostBuilder.Build(); _builder.Start(); } @@ -728,12 +728,14 @@ namespace Ocelot.IntegrationTests config.AddJsonFile("ocelot.json", false, false); config.AddEnvironmentVariables(); }) - .ConfigureServices(x => { + .ConfigureServices(x => + { x.AddSingleton(_webHostBuilder); x.AddOcelot() .AddAdministration("/administration", "secret"); }) - .Configure(app => { + .Configure(app => + { app.UseOcelot().Wait(); }); @@ -804,7 +806,7 @@ namespace Ocelot.IntegrationTests { app.UsePathBase("/foo"); app.Run(async context => - { + { context.Response.StatusCode = 200; await context.Response.WriteAsync("foo"); }); @@ -825,7 +827,7 @@ namespace Ocelot.IntegrationTests { app.UsePathBase("/bar"); app.Run(async context => - { + { context.Response.StatusCode = 200; await context.Response.WriteAsync("bar"); }); diff --git a/test/Ocelot.IntegrationTests/BearerToken.cs b/test/Ocelot.IntegrationTests/BearerToken.cs index 055f28fd..836d72c7 100644 --- a/test/Ocelot.IntegrationTests/BearerToken.cs +++ b/test/Ocelot.IntegrationTests/BearerToken.cs @@ -2,7 +2,7 @@ using Newtonsoft.Json; namespace Ocelot.IntegrationTests { - class BearerToken + internal class BearerToken { [JsonProperty("access_token")] public string AccessToken { get; set; } diff --git a/test/Ocelot.IntegrationTests/CacheManagerTests.cs b/test/Ocelot.IntegrationTests/CacheManagerTests.cs index b2327451..beab8ca3 100644 --- a/test/Ocelot.IntegrationTests/CacheManagerTests.cs +++ b/test/Ocelot.IntegrationTests/CacheManagerTests.cs @@ -1,13 +1,5 @@ -using Xunit; - namespace Ocelot.IntegrationTests { - using System; - using System.Collections.Generic; - using System.IO; - using System.Net; - using System.Net.Http; - using System.Net.Http.Headers; using Configuration.File; using DependencyInjection; using global::CacheManager.Core; @@ -15,13 +7,18 @@ namespace Ocelot.IntegrationTests using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Newtonsoft.Json; + using Ocelot.Administration; + using Ocelot.Cache.CacheManager; using Ocelot.Middleware; using Shouldly; + using System; + using System.Collections.Generic; + using System.IO; + using System.Net; + using System.Net.Http; + using System.Net.Http.Headers; using TestStack.BDDfy; using Xunit; - using Ocelot.Administration; - using Ocelot.IntegrationTests; - using Ocelot.Cache.CacheManager; public class CacheManagerTests : IDisposable { @@ -107,7 +104,7 @@ namespace Ocelot.IntegrationTests .Then(x => ThenTheStatusCodeShouldBe(HttpStatusCode.NoContent)) .BDDfy(); } - + private void GivenIHaveAddedATokenToMyRequest() { _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _token.AccessToken); @@ -219,6 +216,5 @@ namespace Ocelot.IntegrationTests _httpClient?.Dispose(); _identityServerBuilder?.Dispose(); } - } } diff --git a/test/Ocelot.IntegrationTests/HeaderTests.cs b/test/Ocelot.IntegrationTests/HeaderTests.cs index c5120813..cf2222c2 100644 --- a/test/Ocelot.IntegrationTests/HeaderTests.cs +++ b/test/Ocelot.IntegrationTests/HeaderTests.cs @@ -4,23 +4,23 @@ using Xunit; namespace Ocelot.IntegrationTests { + using Microsoft.AspNetCore.Builder; + using Microsoft.AspNetCore.Hosting; + using Microsoft.AspNetCore.Http; + using Microsoft.Extensions.Configuration; + using Newtonsoft.Json; + using Ocelot.Configuration.File; + using Ocelot.DependencyInjection; + using Ocelot.Middleware; + using Shouldly; using System; using System.Collections.Generic; using System.IO; - using System.Net.Http; - using Microsoft.AspNetCore.Builder; - using Microsoft.AspNetCore.Hosting; - using Newtonsoft.Json; - using Ocelot.Configuration.File; - using Shouldly; - using TestStack.BDDfy; - using Microsoft.AspNetCore.Http; - using System.Threading.Tasks; - using Microsoft.Extensions.Configuration; - using Ocelot.DependencyInjection; - using Ocelot.Middleware; using System.Linq; using System.Net; + using System.Net.Http; + using System.Threading.Tasks; + using TestStack.BDDfy; public class HeaderTests : IDisposable { @@ -180,8 +180,8 @@ namespace Ocelot.IntegrationTests var header = _response.Content.ReadAsStringAsync().Result; bool passed = false; - - if(header == windowsOrMac || header == linux) + + if (header == windowsOrMac || header == linux) { passed = true; } diff --git a/test/Ocelot.IntegrationTests/Properties/AssemblyInfo.cs b/test/Ocelot.IntegrationTests/Properties/AssemblyInfo.cs index 6ddcdad3..49ad308f 100644 --- a/test/Ocelot.IntegrationTests/Properties/AssemblyInfo.cs +++ b/test/Ocelot.IntegrationTests/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following @@ -16,4 +15,4 @@ using System.Runtime.InteropServices; [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("d4575572-99ca-4530-8737-c296eda326f8")] +[assembly: Guid("d4575572-99ca-4530-8737-c296eda326f8")] diff --git a/test/Ocelot.IntegrationTests/RaftTests.cs b/test/Ocelot.IntegrationTests/RaftTests.cs index 26af5725..4fbbb3db 100644 --- a/test/Ocelot.IntegrationTests/RaftTests.cs +++ b/test/Ocelot.IntegrationTests/RaftTests.cs @@ -1,13 +1,5 @@ namespace Ocelot.IntegrationTests { - using System; - using System.Collections.Generic; - using System.IO; - using System.Linq; - using System.Net.Http; - using System.Net.Http.Headers; - using System.Threading; - using System.Threading.Tasks; using Administration; using Configuration.File; using DependencyInjection; @@ -17,14 +9,19 @@ using Microsoft.Extensions.DependencyInjection; using Middleware; using Newtonsoft.Json; + using Ocelot.Provider.Rafty; + using Rafty.Infrastructure; using Shouldly; + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Net.Http; + using System.Net.Http.Headers; + using System.Threading; + using System.Threading.Tasks; using Xunit; using Xunit.Abstractions; - using Ocelot.Administration; - using Ocelot.IntegrationTests; - using Ocelot.Provider.Rafty; - using Ocelot.Infrastructure; - using Rafty.Infrastructure; using Wait = Rafty.Infrastructure.Wait; public class RaftTests : IDisposable diff --git a/test/Ocelot.IntegrationTests/ThreadSafeHeadersTests.cs b/test/Ocelot.IntegrationTests/ThreadSafeHeadersTests.cs index 1e9c0dd8..2f170229 100644 --- a/test/Ocelot.IntegrationTests/ThreadSafeHeadersTests.cs +++ b/test/Ocelot.IntegrationTests/ThreadSafeHeadersTests.cs @@ -1,21 +1,20 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Configuration; +using Newtonsoft.Json; +using Ocelot.Configuration.File; +using Ocelot.DependencyInjection; +using Ocelot.Middleware; +using Shouldly; using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Net.Http; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Newtonsoft.Json; -using Ocelot.Configuration.File; -using Shouldly; +using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; -using Microsoft.AspNetCore.Http; -using System.Threading.Tasks; -using System.Collections.Concurrent; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; -using Ocelot.DependencyInjection; -using Ocelot.Middleware; namespace Ocelot.IntegrationTests { @@ -177,7 +176,7 @@ namespace Ocelot.IntegrationTests private void ThenTheSameHeaderValuesAreReturnedByTheDownstreamService() { - foreach(var result in _results) + foreach (var result in _results) { result.Result.ShouldBe(result.Random); } @@ -190,7 +189,7 @@ namespace Ocelot.IntegrationTests _downstreamBuilder?.Dispose(); } - class ThreadSafeHeadersTestResult + private class ThreadSafeHeadersTestResult { public ThreadSafeHeadersTestResult(int result, int random) { diff --git a/test/Ocelot.IntegrationTests/appsettings.json b/test/Ocelot.IntegrationTests/appsettings.json index 6d9b7c55..4a33a1a1 100644 --- a/test/Ocelot.IntegrationTests/appsettings.json +++ b/test/Ocelot.IntegrationTests/appsettings.json @@ -7,4 +7,4 @@ "Microsoft": "Error" } } -} +} diff --git a/test/Ocelot.IntegrationTests/ocelot.json b/test/Ocelot.IntegrationTests/ocelot.json index 75bf2d31..a4ca4ce5 100644 --- a/test/Ocelot.IntegrationTests/ocelot.json +++ b/test/Ocelot.IntegrationTests/ocelot.json @@ -1 +1,57 @@ -{"ReRoutes":[{"DownstreamPathTemplate":"/","UpstreamPathTemplate":"/","UpstreamHttpMethod":"Get","AuthenticationOptions":{"Provider":null,"ProviderRootUrl":null,"ApiName":null,"RequireHttps":false,"AllowedScopes":[],"ApiSecret":null},"AddHeadersToRequest":{},"AddClaimsToRequest":{},"RouteClaimsRequirement":{},"AddQueriesToRequest":{},"RequestIdKey":null,"FileCacheOptions":{"TtlSeconds":0},"ReRouteIsCaseSensitive":false,"ServiceName":null,"DownstreamScheme":"http","DownstreamHost":"localhost","DownstreamPort":51879,"QoSOptions":{"ExceptionsAllowedBeforeBreaking":0,"DurationOfBreak":0,"TimeoutValue":0},"LoadBalancer":null,"RateLimitOptions":{"ClientWhitelist":[],"EnableRateLimiting":false,"Period":null,"PeriodTimespan":0.0,"Limit":0}}],"GlobalConfiguration":{"RequestIdKey":null,"ServiceDiscoveryProvider":{"Provider":null,"Host":null,"Port":0},"AdministrationPath":null,"RateLimitOptions":{"ClientIdHeader":"ClientId","QuotaExceededMessage":null,"RateLimitCounterPrefix":"ocelot","DisableRateLimitHeaders":false,"HttpStatusCode":429}}} \ No newline at end of file +{ + "ReRoutes": [ + { + "DownstreamPathTemplate": "/", + "UpstreamPathTemplate": "/", + "UpstreamHttpMethod": "Get", + "AuthenticationOptions": { + "Provider": null, + "ProviderRootUrl": null, + "ApiName": null, + "RequireHttps": false, + "AllowedScopes": [], + "ApiSecret": null + }, + "AddHeadersToRequest": {}, + "AddClaimsToRequest": {}, + "RouteClaimsRequirement": {}, + "AddQueriesToRequest": {}, + "RequestIdKey": null, + "FileCacheOptions": { "TtlSeconds": 0 }, + "ReRouteIsCaseSensitive": false, + "ServiceName": null, + "DownstreamScheme": "http", + "DownstreamHost": "localhost", + "DownstreamPort": 51879, + "QoSOptions": { + "ExceptionsAllowedBeforeBreaking": 0, + "DurationOfBreak": 0, + "TimeoutValue": 0 + }, + "LoadBalancer": null, + "RateLimitOptions": { + "ClientWhitelist": [], + "EnableRateLimiting": false, + "Period": null, + "PeriodTimespan": 0.0, + "Limit": 0 + } + } + ], + "GlobalConfiguration": { + "RequestIdKey": null, + "ServiceDiscoveryProvider": { + "Provider": null, + "Host": null, + "Port": 0 + }, + "AdministrationPath": null, + "RateLimitOptions": { + "ClientIdHeader": "ClientId", + "QuotaExceededMessage": null, + "RateLimitCounterPrefix": "ocelot", + "DisableRateLimitHeaders": false, + "HttpStatusCode": 429 + } + } +} diff --git a/test/Ocelot.IntegrationTests/peers.json b/test/Ocelot.IntegrationTests/peers.json index 95b50a6e..0f474779 100644 --- a/test/Ocelot.IntegrationTests/peers.json +++ b/test/Ocelot.IntegrationTests/peers.json @@ -1,18 +1,19 @@ { - "Peers": [{ - "HostAndPort": "http://localhost:5000" - }, - { - "HostAndPort": "http://localhost:5002" - }, - { - "HostAndPort": "http://localhost:5003" - }, - { - "HostAndPort": "http://localhost:5004" - }, - { - "HostAndPort": "http://localhost:5001" - } - ] -} \ No newline at end of file + "Peers": [ + { + "HostAndPort": "http://localhost:5000" + }, + { + "HostAndPort": "http://localhost:5002" + }, + { + "HostAndPort": "http://localhost:5003" + }, + { + "HostAndPort": "http://localhost:5004" + }, + { + "HostAndPort": "http://localhost:5001" + } + ] +} diff --git a/test/Ocelot.ManualTest/Ocelot.postman_collection.json b/test/Ocelot.ManualTest/Ocelot.postman_collection.json index 92ac9c73..76428fb9 100644 --- a/test/Ocelot.ManualTest/Ocelot.postman_collection.json +++ b/test/Ocelot.ManualTest/Ocelot.postman_collection.json @@ -1,197 +1,197 @@ { - "id": "4dbde9fe-89f5-be35-bb9f-d3b438e16375", - "name": "Ocelot", - "description": "", - "order": [ - "a1c95935-ed18-d5dc-bcb8-a3db8ba1934f", - "ea0ed57a-2cb9-8acc-47dd-006b8db2f1b2", - "c4494401-3985-a5bf-71fb-6e4171384ac6", - "09af8dda-a9cb-20d2-5ee3-0a3023773a1a", - "e8825dc3-4137-99a7-0000-ef5786610dc3", - "fddfc4fa-5114-69e3-4744-203ed71a526b", - "c45d30d7-d9c4-fa05-8110-d6e769bb6ff9", - "4684c2fa-f38c-c193-5f55-bf563a1978c6", - "37bfa9f1-fe29-6a68-e558-66d125d2c96f", - "5f308240-79e3-cf74-7a6b-fe462f0d54f1", - "178f16da-c61b-c881-1c33-9d64a56851a4" - ], - "folders": [], - "folders_order": [], - "timestamp": 0, - "owner": "212120", - "public": false, - "requests": [ - { - "folder": null, - "id": "09af8dda-a9cb-20d2-5ee3-0a3023773a1a", - "name": "GET http://localhost:5000/comments?postId=1", - "dataMode": "params", - "data": null, - "rawModeData": null, - "descriptionFormat": "html", - "description": "", - "headers": "", - "method": "GET", - "pathVariables": {}, - "url": "http://localhost:5000/comments?postId=1", - "preRequestScript": null, - "tests": null, - "currentHelper": "normal", - "helperAttributes": "{}", - "queryParams": [], - "headerData": [], - "pathVariableData": [], - "responses": [], - "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375" - }, - { - "id": "178f16da-c61b-c881-1c33-9d64a56851a4", - "headers": "Authorization: Bearer {{AccessToken}}\n", - "headerData": [ - { - "key": "Authorization", - "value": "Bearer {{AccessToken}}", - "enabled": true, - "description": "" - } - ], - "url": "http://localhost:5000/administration/configuration", - "folder": null, - "queryParams": [], - "preRequestScript": null, - "pathVariables": {}, - "pathVariableData": [], - "method": "GET", - "data": null, - "dataMode": "params", - "tests": null, - "currentHelper": "normal", - "helperAttributes": "{}", - "time": 1508849878025, - "name": "GET http://localhost:5000/admin/configuration", - "description": "", - "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375", - "responses": [], - "isFromCollection": true, - "collectionRequestId": "178f16da-c61b-c881-1c33-9d64a56851a4", - "rawModeData": null, - "descriptionFormat": null - }, - { - "id": "37bfa9f1-fe29-6a68-e558-66d125d2c96f", - "headers": "", - "headerData": [], - "url": "http://localhost:5000/administration/connect/token", - "folder": null, - "queryParams": [], - "preRequestScript": null, - "pathVariables": {}, - "pathVariableData": [], - "method": "POST", - "data": [ - { - "key": "client_id", - "value": "admin", - "type": "text", - "enabled": true - }, - { - "key": "client_secret", - "value": "secret", - "type": "text", - "enabled": true - }, - { - "key": "scope", - "value": "admin", - "type": "text", - "enabled": true - }, - { - "key": "username", - "value": "admin", - "type": "text", - "enabled": true - }, - { - "key": "password", - "value": "secret", - "type": "text", - "enabled": true - }, - { - "key": "grant_type", - "value": "password", - "type": "text", - "enabled": true - } - ], - "dataMode": "params", - "tests": "var jsonData = JSON.parse(responseBody);\npostman.setGlobalVariable(\"AccessToken\", jsonData.access_token);\npostman.setGlobalVariable(\"RefreshToken\", jsonData.refresh_token);", - "currentHelper": "normal", - "helperAttributes": "{}", - "time": 1506359585080, - "name": "POST http://localhost:5000/admin/connect/token copy", - "description": "", - "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375", - "responses": [], - "isFromCollection": true, - "collectionRequestId": "37bfa9f1-fe29-6a68-e558-66d125d2c96f", - "rawModeData": null, - "descriptionFormat": null - }, - { - "folder": null, - "id": "4684c2fa-f38c-c193-5f55-bf563a1978c6", - "name": "DELETE http://localhost:5000/posts/1", - "dataMode": "params", - "data": null, - "rawModeData": null, - "descriptionFormat": "html", - "description": "", - "headers": "", - "method": "DELETE", - "pathVariables": {}, - "url": "http://localhost:5000/posts/1", - "preRequestScript": null, - "tests": null, - "currentHelper": "normal", - "helperAttributes": "{}", - "queryParams": [], - "headerData": [], - "pathVariableData": [], - "responses": [], - "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375" - }, - { - "id": "5f308240-79e3-cf74-7a6b-fe462f0d54f1", - "headers": "Authorization: Bearer {{AccessToken}}\n", - "headerData": [ - { - "key": "Authorization", - "value": "Bearer {{AccessToken}}", - "description": "", - "enabled": true - } - ], - "url": "http://localhost:5000/administration/.well-known/openid-configuration", - "folder": null, - "queryParams": [], - "preRequestScript": null, - "pathVariables": {}, - "pathVariableData": [], - "method": "GET", - "data": null, - "dataMode": "params", - "tests": null, - "currentHelper": "normal", - "helperAttributes": {}, - "time": 1508849923518, - "name": "GET http://localhost:5000/admin/.well-known/openid-configuration", - "description": "", - "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375", - "responses": [] - }, + "id": "4dbde9fe-89f5-be35-bb9f-d3b438e16375", + "name": "Ocelot", + "description": "", + "order": [ + "a1c95935-ed18-d5dc-bcb8-a3db8ba1934f", + "ea0ed57a-2cb9-8acc-47dd-006b8db2f1b2", + "c4494401-3985-a5bf-71fb-6e4171384ac6", + "09af8dda-a9cb-20d2-5ee3-0a3023773a1a", + "e8825dc3-4137-99a7-0000-ef5786610dc3", + "fddfc4fa-5114-69e3-4744-203ed71a526b", + "c45d30d7-d9c4-fa05-8110-d6e769bb6ff9", + "4684c2fa-f38c-c193-5f55-bf563a1978c6", + "37bfa9f1-fe29-6a68-e558-66d125d2c96f", + "5f308240-79e3-cf74-7a6b-fe462f0d54f1", + "178f16da-c61b-c881-1c33-9d64a56851a4" + ], + "folders": [], + "folders_order": [], + "timestamp": 0, + "owner": "212120", + "public": false, + "requests": [ + { + "folder": null, + "id": "09af8dda-a9cb-20d2-5ee3-0a3023773a1a", + "name": "GET http://localhost:5000/comments?postId=1", + "dataMode": "params", + "data": null, + "rawModeData": null, + "descriptionFormat": "html", + "description": "", + "headers": "", + "method": "GET", + "pathVariables": {}, + "url": "http://localhost:5000/comments?postId=1", + "preRequestScript": null, + "tests": null, + "currentHelper": "normal", + "helperAttributes": "{}", + "queryParams": [], + "headerData": [], + "pathVariableData": [], + "responses": [], + "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375" + }, + { + "id": "178f16da-c61b-c881-1c33-9d64a56851a4", + "headers": "Authorization: Bearer {{AccessToken}}\n", + "headerData": [ + { + "key": "Authorization", + "value": "Bearer {{AccessToken}}", + "enabled": true, + "description": "" + } + ], + "url": "http://localhost:5000/administration/configuration", + "folder": null, + "queryParams": [], + "preRequestScript": null, + "pathVariables": {}, + "pathVariableData": [], + "method": "GET", + "data": null, + "dataMode": "params", + "tests": null, + "currentHelper": "normal", + "helperAttributes": "{}", + "time": 1508849878025, + "name": "GET http://localhost:5000/admin/configuration", + "description": "", + "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375", + "responses": [], + "isFromCollection": true, + "collectionRequestId": "178f16da-c61b-c881-1c33-9d64a56851a4", + "rawModeData": null, + "descriptionFormat": null + }, + { + "id": "37bfa9f1-fe29-6a68-e558-66d125d2c96f", + "headers": "", + "headerData": [], + "url": "http://localhost:5000/administration/connect/token", + "folder": null, + "queryParams": [], + "preRequestScript": null, + "pathVariables": {}, + "pathVariableData": [], + "method": "POST", + "data": [ + { + "key": "client_id", + "value": "admin", + "type": "text", + "enabled": true + }, + { + "key": "client_secret", + "value": "secret", + "type": "text", + "enabled": true + }, + { + "key": "scope", + "value": "admin", + "type": "text", + "enabled": true + }, + { + "key": "username", + "value": "admin", + "type": "text", + "enabled": true + }, + { + "key": "password", + "value": "secret", + "type": "text", + "enabled": true + }, + { + "key": "grant_type", + "value": "password", + "type": "text", + "enabled": true + } + ], + "dataMode": "params", + "tests": "var jsonData = JSON.parse(responseBody);\npostman.setGlobalVariable(\"AccessToken\", jsonData.access_token);\npostman.setGlobalVariable(\"RefreshToken\", jsonData.refresh_token);", + "currentHelper": "normal", + "helperAttributes": "{}", + "time": 1506359585080, + "name": "POST http://localhost:5000/admin/connect/token copy", + "description": "", + "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375", + "responses": [], + "isFromCollection": true, + "collectionRequestId": "37bfa9f1-fe29-6a68-e558-66d125d2c96f", + "rawModeData": null, + "descriptionFormat": null + }, + { + "folder": null, + "id": "4684c2fa-f38c-c193-5f55-bf563a1978c6", + "name": "DELETE http://localhost:5000/posts/1", + "dataMode": "params", + "data": null, + "rawModeData": null, + "descriptionFormat": "html", + "description": "", + "headers": "", + "method": "DELETE", + "pathVariables": {}, + "url": "http://localhost:5000/posts/1", + "preRequestScript": null, + "tests": null, + "currentHelper": "normal", + "helperAttributes": "{}", + "queryParams": [], + "headerData": [], + "pathVariableData": [], + "responses": [], + "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375" + }, + { + "id": "5f308240-79e3-cf74-7a6b-fe462f0d54f1", + "headers": "Authorization: Bearer {{AccessToken}}\n", + "headerData": [ + { + "key": "Authorization", + "value": "Bearer {{AccessToken}}", + "description": "", + "enabled": true + } + ], + "url": "http://localhost:5000/administration/.well-known/openid-configuration", + "folder": null, + "queryParams": [], + "preRequestScript": null, + "pathVariables": {}, + "pathVariableData": [], + "method": "GET", + "data": null, + "dataMode": "params", + "tests": null, + "currentHelper": "normal", + "helperAttributes": {}, + "time": 1508849923518, + "name": "GET http://localhost:5000/admin/.well-known/openid-configuration", + "description": "", + "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375", + "responses": [] + }, { "folder": null, "id": "a1c95935-ed18-d5dc-bcb8-a3db8ba1934f", @@ -252,120 +252,120 @@ "responses": [], "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375" }, - { - "folder": null, - "id": "c4494401-3985-a5bf-71fb-6e4171384ac6", - "name": "GET http://localhost:5000/posts/1/comments", - "dataMode": "params", - "data": null, - "rawModeData": null, - "descriptionFormat": "html", - "description": "", - "headers": "", - "method": "GET", - "pathVariables": {}, - "url": "http://localhost:5000/posts/1/comments", - "preRequestScript": null, - "tests": null, - "currentHelper": "normal", - "helperAttributes": "{}", - "queryParams": [], - "headerData": [], - "pathVariableData": [], - "responses": [], - "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375" - }, - { - "folder": null, - "id": "c45d30d7-d9c4-fa05-8110-d6e769bb6ff9", - "name": "PATCH http://localhost:5000/posts/1", - "dataMode": "raw", - "data": [], - "rawModeData": "{\n \"title\": \"gfdgsgsdgsdfgsdfgdfg\",\n}", - "descriptionFormat": "html", - "description": "", - "headers": "", - "method": "PATCH", - "pathVariables": {}, - "url": "http://localhost:5000/posts/1", - "preRequestScript": null, - "tests": null, - "currentHelper": "normal", - "helperAttributes": "{}", - "queryParams": [], - "headerData": [], - "pathVariableData": [], - "responses": [], - "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375" - }, - { - "folder": null, - "id": "e8825dc3-4137-99a7-0000-ef5786610dc3", - "name": "POST http://localhost:5000/posts/1", - "dataMode": "raw", - "data": [], - "rawModeData": "{\n \"userId\": 1,\n \"title\": \"test\",\n \"body\": \"test\"\n}", - "descriptionFormat": "html", - "description": "", - "headers": "", - "method": "POST", - "pathVariables": {}, - "url": "http://localhost:5000/posts", - "preRequestScript": null, - "tests": null, - "currentHelper": "normal", - "helperAttributes": "{}", - "queryParams": [], - "headerData": [], - "pathVariableData": [], - "responses": [], - "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375" - }, - { - "folder": null, - "id": "ea0ed57a-2cb9-8acc-47dd-006b8db2f1b2", - "name": "GET http://localhost:5000/posts/1", - "dataMode": "params", - "data": null, - "rawModeData": null, - "descriptionFormat": "html", - "description": "", - "headers": "", - "method": "GET", - "pathVariables": {}, - "url": "http://localhost:5000/posts/1", - "preRequestScript": null, - "tests": null, - "currentHelper": "normal", - "helperAttributes": "{}", - "queryParams": [], - "headerData": [], - "pathVariableData": [], - "responses": [], - "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375" - }, - { - "folder": null, - "id": "fddfc4fa-5114-69e3-4744-203ed71a526b", - "name": "PUT http://localhost:5000/posts/1", - "dataMode": "raw", - "data": [], - "rawModeData": "{\n \"userId\": 1,\n \"title\": \"test\",\n \"body\": \"test\"\n}", - "descriptionFormat": "html", - "description": "", - "headers": "", - "method": "PUT", - "pathVariables": {}, - "url": "http://localhost:5000/posts/1", - "preRequestScript": null, - "tests": null, - "currentHelper": "normal", - "helperAttributes": "{}", - "queryParams": [], - "headerData": [], - "pathVariableData": [], - "responses": [], - "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375" - } - ] -} \ No newline at end of file + { + "folder": null, + "id": "c4494401-3985-a5bf-71fb-6e4171384ac6", + "name": "GET http://localhost:5000/posts/1/comments", + "dataMode": "params", + "data": null, + "rawModeData": null, + "descriptionFormat": "html", + "description": "", + "headers": "", + "method": "GET", + "pathVariables": {}, + "url": "http://localhost:5000/posts/1/comments", + "preRequestScript": null, + "tests": null, + "currentHelper": "normal", + "helperAttributes": "{}", + "queryParams": [], + "headerData": [], + "pathVariableData": [], + "responses": [], + "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375" + }, + { + "folder": null, + "id": "c45d30d7-d9c4-fa05-8110-d6e769bb6ff9", + "name": "PATCH http://localhost:5000/posts/1", + "dataMode": "raw", + "data": [], + "rawModeData": "{\n \"title\": \"gfdgsgsdgsdfgsdfgdfg\",\n}", + "descriptionFormat": "html", + "description": "", + "headers": "", + "method": "PATCH", + "pathVariables": {}, + "url": "http://localhost:5000/posts/1", + "preRequestScript": null, + "tests": null, + "currentHelper": "normal", + "helperAttributes": "{}", + "queryParams": [], + "headerData": [], + "pathVariableData": [], + "responses": [], + "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375" + }, + { + "folder": null, + "id": "e8825dc3-4137-99a7-0000-ef5786610dc3", + "name": "POST http://localhost:5000/posts/1", + "dataMode": "raw", + "data": [], + "rawModeData": "{\n \"userId\": 1,\n \"title\": \"test\",\n \"body\": \"test\"\n}", + "descriptionFormat": "html", + "description": "", + "headers": "", + "method": "POST", + "pathVariables": {}, + "url": "http://localhost:5000/posts", + "preRequestScript": null, + "tests": null, + "currentHelper": "normal", + "helperAttributes": "{}", + "queryParams": [], + "headerData": [], + "pathVariableData": [], + "responses": [], + "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375" + }, + { + "folder": null, + "id": "ea0ed57a-2cb9-8acc-47dd-006b8db2f1b2", + "name": "GET http://localhost:5000/posts/1", + "dataMode": "params", + "data": null, + "rawModeData": null, + "descriptionFormat": "html", + "description": "", + "headers": "", + "method": "GET", + "pathVariables": {}, + "url": "http://localhost:5000/posts/1", + "preRequestScript": null, + "tests": null, + "currentHelper": "normal", + "helperAttributes": "{}", + "queryParams": [], + "headerData": [], + "pathVariableData": [], + "responses": [], + "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375" + }, + { + "folder": null, + "id": "fddfc4fa-5114-69e3-4744-203ed71a526b", + "name": "PUT http://localhost:5000/posts/1", + "dataMode": "raw", + "data": [], + "rawModeData": "{\n \"userId\": 1,\n \"title\": \"test\",\n \"body\": \"test\"\n}", + "descriptionFormat": "html", + "description": "", + "headers": "", + "method": "PUT", + "pathVariables": {}, + "url": "http://localhost:5000/posts/1", + "preRequestScript": null, + "tests": null, + "currentHelper": "normal", + "helperAttributes": "{}", + "queryParams": [], + "headerData": [], + "pathVariableData": [], + "responses": [], + "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375" + } + ] +} diff --git a/test/Ocelot.ManualTest/Program.cs b/test/Ocelot.ManualTest/Program.cs index 43f9bc59..659e250a 100644 --- a/test/Ocelot.ManualTest/Program.cs +++ b/test/Ocelot.ManualTest/Program.cs @@ -1,19 +1,18 @@ -using System.Reflection.Metadata.Ecma335; -using Ocelot.Requester; +using Ocelot.Requester; namespace Ocelot.ManualTest { - using System.IO; using Microsoft.AspNetCore.Hosting; - using Microsoft.Extensions.Logging; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.Logging; using Ocelot.DependencyInjection; using Ocelot.Middleware; using System; + using System.IO; using System.Net.Http; - using System.Threading.Tasks; using System.Threading; + using System.Threading.Tasks; public class Program { @@ -31,27 +30,28 @@ namespace Ocelot.ManualTest .AddJsonFile("ocelot.json", false, false) .AddEnvironmentVariables(); }) - .ConfigureServices(s => { - s.AddAuthentication() - .AddJwtBearer("TestKey", x => - { - x.Authority = "test"; - x.Audience = "test"; - }); + .ConfigureServices(s => + { + s.AddAuthentication() + .AddJwtBearer("TestKey", x => + { + x.Authority = "test"; + x.Audience = "test"; + }); - s.AddSingleton((x, t) => new FakeHandler()); - s.AddOcelot() - .AddDelegatingHandler(true); - // .AddCacheManager(x => - // { - // x.WithDictionaryHandle(); - // }) - // .AddOpenTracing(option => - // { - // option.CollectorUrl = "http://localhost:9618"; - // option.Service = "Ocelot.ManualTest"; - // }) - // .AddAdministration("/administration", "secret"); + s.AddSingleton((x, t) => new FakeHandler()); + s.AddOcelot() + .AddDelegatingHandler(true); + // .AddCacheManager(x => + // { + // x.WithDictionaryHandle(); + // }) + // .AddOpenTracing(option => + // { + // option.CollectorUrl = "http://localhost:9618"; + // option.Service = "Ocelot.ManualTest"; + // }) + // .AddAdministration("/administration", "secret"); }) .ConfigureLogging((hostingContext, logging) => { @@ -64,7 +64,7 @@ namespace Ocelot.ManualTest app.UseOcelot().Wait(); }) .Build() - .Run(); + .Run(); } } diff --git a/test/Ocelot.ManualTest/appsettings.json b/test/Ocelot.ManualTest/appsettings.json index 16fe363b..e2192fcc 100644 --- a/test/Ocelot.ManualTest/appsettings.json +++ b/test/Ocelot.ManualTest/appsettings.json @@ -13,4 +13,4 @@ "shouldRegisterWithEureka": true } } -} +} diff --git a/test/Ocelot.ManualTest/ocelot.json b/test/Ocelot.ManualTest/ocelot.json index 322c607b..7bb8978b 100644 --- a/test/Ocelot.ManualTest/ocelot.json +++ b/test/Ocelot.ManualTest/ocelot.json @@ -1,345 +1,345 @@ { - "ReRoutes": [ - { - "DownstreamPathTemplate": "/profile", - "DownstreamScheme": "http", - "UpstreamPathTemplate": "/profile", - "UpstreamHttpMethod": [ "Get" ], - "DownstreamHostAndPorts": [ - { - "Host": "localhost", - "Port": 5001 - } - ], - "QoSOptions": { - "TimeoutValue": 360000 + "ReRoutes": [ + { + "DownstreamPathTemplate": "/profile", + "DownstreamScheme": "http", + "UpstreamPathTemplate": "/profile", + "UpstreamHttpMethod": [ "Get" ], + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 5001 } - }, - { - "DownstreamPathTemplate": "/api/v1/todo/", - "DownstreamScheme": "http", - "UpstreamPathTemplate": "/api/v1/todo/", - "UpstreamHttpMethod": [ "Get", "Post" ], - "DownstreamHostAndPorts": [ - { - "Host": "lxtodo.azurewebsites.net", - "Port": 80 - } - - ], - "DownstreamHeaderTransform": { - "Location": "{DownstreamBaseUrl}, {BaseUrl}" + ], + "QoSOptions": { + "TimeoutValue": 360000 + } + }, + { + "DownstreamPathTemplate": "/api/v1/todo/", + "DownstreamScheme": "http", + "UpstreamPathTemplate": "/api/v1/todo/", + "UpstreamHttpMethod": [ "Get", "Post" ], + "DownstreamHostAndPorts": [ + { + "Host": "lxtodo.azurewebsites.net", + "Port": 80 } + + ], + "DownstreamHeaderTransform": { + "Location": "{DownstreamBaseUrl}, {BaseUrl}" + } + }, + { + "DownstreamPathTemplate": "/api/values", + "DownstreamScheme": "https", + "UpstreamPathTemplate": "/api/values", + "UpstreamHttpMethod": [ "Get" ], + "DownstreamHostAndPorts": [ + { + "Host": "testapivalues.azurewebsites.net", + "Port": 443 + } + ] + }, + { + "DownstreamPathTemplate": "/", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 52876 + } + ], + "UpstreamPathTemplate": "/identityserverexample", + "UpstreamHttpMethod": [ "Get" ], + "QoSOptions": { + "ExceptionsAllowedBeforeBreaking": 3, + "DurationOfBreak": 10, + "TimeoutValue": 5000 }, - { - "DownstreamPathTemplate": "/api/values", - "DownstreamScheme": "https", - "UpstreamPathTemplate": "/api/values", - "UpstreamHttpMethod": [ "Get" ], - "DownstreamHostAndPorts": [ - { - "Host": "testapivalues.azurewebsites.net", - "Port": 443 - } + "AuthenticationOptions": { + "AuthenticationProviderKey": "TestKey", + "AllowedScopes": [ + "openid", + "offline_access" ] }, - { - "DownstreamPathTemplate": "/", - "DownstreamScheme": "http", - "DownstreamHostAndPorts": [ - { - "Host": "localhost", - "Port": 52876 - } - ], - "UpstreamPathTemplate": "/identityserverexample", - "UpstreamHttpMethod": [ "Get" ], - "QoSOptions": { - "ExceptionsAllowedBeforeBreaking": 3, - "DurationOfBreak": 10, - "TimeoutValue": 5000 - }, - "AuthenticationOptions": { - "AuthenticationProviderKey": "TestKey", - "AllowedScopes": [ - "openid", - "offline_access" - ] - }, - "AddHeadersToRequest": { - "CustomerId": "Claims[CustomerId] > value", - "LocationId": "Claims[LocationId] > value", - "UserType": "Claims[sub] > value[0] > |", - "UserId": "Claims[sub] > value[1] > |" - }, - "AddClaimsToRequest": { - "CustomerId": "Claims[CustomerId] > value", - "LocationId": "Claims[LocationId] > value", - "UserType": "Claims[sub] > value[0] > |", - "UserId": "Claims[sub] > value[1] > |" - }, - "AddQueriesToRequest": { - "CustomerId": "Claims[CustomerId] > value", - "LocationId": "Claims[LocationId] > value", - "UserType": "Claims[sub] > value[0] > |", - "UserId": "Claims[sub] > value[1] > |" - }, - "RouteClaimsRequirement": { - "UserType": "registered" - }, - "RequestIdKey": "OcRequestId" + "AddHeadersToRequest": { + "CustomerId": "Claims[CustomerId] > value", + "LocationId": "Claims[LocationId] > value", + "UserType": "Claims[sub] > value[0] > |", + "UserId": "Claims[sub] > value[1] > |" }, - { - "DownstreamPathTemplate": "/posts", - "DownstreamScheme": "https", - "DownstreamHostAndPorts": [ - { - "Host": "jsonplaceholder.typicode.com", - "Port": 443 - } - ], - "UpstreamPathTemplate": "/posts", - "UpstreamHttpMethod": [ "Get" ], - "HttpHandlerOptions": { - "AllowAutoRedirect": true, - "UseCookieContainer": true - }, - "QoSOptions": { - "ExceptionsAllowedBeforeBreaking": 3, - "DurationOfBreak": 10, - "TimeoutValue": 5000 + "AddClaimsToRequest": { + "CustomerId": "Claims[CustomerId] > value", + "LocationId": "Claims[LocationId] > value", + "UserType": "Claims[sub] > value[0] > |", + "UserId": "Claims[sub] > value[1] > |" + }, + "AddQueriesToRequest": { + "CustomerId": "Claims[CustomerId] > value", + "LocationId": "Claims[LocationId] > value", + "UserType": "Claims[sub] > value[0] > |", + "UserId": "Claims[sub] > value[1] > |" + }, + "RouteClaimsRequirement": { + "UserType": "registered" + }, + "RequestIdKey": "OcRequestId" + }, + { + "DownstreamPathTemplate": "/posts", + "DownstreamScheme": "https", + "DownstreamHostAndPorts": [ + { + "Host": "jsonplaceholder.typicode.com", + "Port": 443 } + ], + "UpstreamPathTemplate": "/posts", + "UpstreamHttpMethod": [ "Get" ], + "HttpHandlerOptions": { + "AllowAutoRedirect": true, + "UseCookieContainer": true }, - { - "DownstreamPathTemplate": "/posts/{postId}", - "DownstreamScheme": "http", - "DownstreamHostAndPorts": [ - { - "Host": "jsonplaceholder.typicode.com", - "Port": 80 - } - ], - "UpstreamPathTemplate": "/posts/{postId}", - "UpstreamHttpMethod": [ "Get" ], - "RequestIdKey": "ReRouteRequestId", - "HttpHandlerOptions": { - "AllowAutoRedirect": true, - "UseCookieContainer": true, - "UseTracing": true, - "UseProxy": true - }, - "QoSOptions": { - "ExceptionsAllowedBeforeBreaking": 3, - "DurationOfBreak": 10, - "TimeoutValue": 5000 - } - }, - { - "DownstreamPathTemplate": "/posts/{postId}/comments", - "DownstreamScheme": "http", - "DownstreamHostAndPorts": [ - { - "Host": "jsonplaceholder.typicode.com", - "Port": 80 - } - ], - "UpstreamPathTemplate": "/posts/{postId}/comments", - "UpstreamHttpMethod": [ "Get" ], - "HttpHandlerOptions": { - "AllowAutoRedirect": true, - "UseCookieContainer": true, - "UseTracing": false - }, - "QoSOptions": { - "ExceptionsAllowedBeforeBreaking": 3, - "DurationOfBreak": 10, - "TimeoutValue": 5000 - } - }, - { - "DownstreamPathTemplate": "/comments", - "DownstreamScheme": "http", - "DownstreamHostAndPorts": [ - { - "Host": "jsonplaceholder.typicode.com", - "Port": 80 - } - ], - "UpstreamPathTemplate": "/comments", - "UpstreamHttpMethod": [ "Get" ], - "QoSOptions": { - "ExceptionsAllowedBeforeBreaking": 3, - "DurationOfBreak": 10, - "TimeoutValue": 5000 - } - }, - { - "DownstreamPathTemplate": "/posts", - "DownstreamScheme": "http", - "DownstreamHostAndPorts": [ - { - "Host": "jsonplaceholder.typicode.com", - "Port": 80 - } - ], - "UpstreamPathTemplate": "/posts", - "UpstreamHttpMethod": [ "Post" ], - "QoSOptions": { - "ExceptionsAllowedBeforeBreaking": 3, - "DurationOfBreak": 10, - "TimeoutValue": 5000 - } - }, - { - "DownstreamPathTemplate": "/posts/{postId}", - "DownstreamScheme": "http", - "DownstreamHostAndPorts": [ - { - "Host": "jsonplaceholder.typicode.com", - "Port": 80 - } - ], - "UpstreamPathTemplate": "/posts/{postId}", - "UpstreamHttpMethod": [ "Put" ], - "QoSOptions": { - "ExceptionsAllowedBeforeBreaking": 3, - "DurationOfBreak": 10, - "TimeoutValue": 5000 - } - }, - { - "DownstreamPathTemplate": "/posts/{postId}", - "DownstreamScheme": "http", - "DownstreamHostAndPorts": [ - { - "Host": "jsonplaceholder.typicode.com", - "Port": 80 - } - ], - "UpstreamPathTemplate": "/posts/{postId}", - "UpstreamHttpMethod": [ "Patch" ], - "QoSOptions": { - "ExceptionsAllowedBeforeBreaking": 3, - "DurationOfBreak": 10, - "TimeoutValue": 5000 - } - }, - { - "DownstreamPathTemplate": "/posts/{postId}", - "DownstreamScheme": "http", - "DownstreamHostAndPorts": [ - { - "Host": "jsonplaceholder.typicode.com", - "Port": 80 - } - ], - "UpstreamPathTemplate": "/posts/{postId}", - "UpstreamHttpMethod": [ "Delete" ], - "QoSOptions": { - "ExceptionsAllowedBeforeBreaking": 3, - "DurationOfBreak": 10, - "TimeoutValue": 5000 - } - }, - { - "DownstreamPathTemplate": "/api/products", - "DownstreamScheme": "http", - "DownstreamHostAndPorts": [ - { - "Host": "jsonplaceholder.typicode.com", - "Port": 80 - } - ], - "UpstreamPathTemplate": "/products", - "UpstreamHttpMethod": [ "Get" ], - "QoSOptions": { - "ExceptionsAllowedBeforeBreaking": 3, - "DurationOfBreak": 10, - "TimeoutValue": 5000 - }, - "FileCacheOptions": { "TtlSeconds": 15 } - }, - { - "DownstreamPathTemplate": "/api/products/{productId}", - "DownstreamScheme": "http", - "DownstreamHostAndPorts": [ - { - "Host": "jsonplaceholder.typicode.com", - "Port": 80 - } - ], - "UpstreamPathTemplate": "/products/{productId}", - "UpstreamHttpMethod": [ "Get" ], - "FileCacheOptions": { "TtlSeconds": 15 } - }, - { - "DownstreamPathTemplate": "/api/products", - "DownstreamScheme": "http", - "DownstreamHostAndPorts": [ - { - "Host": "jsonplaceholder.typicode.com", - "Port": 80 - } - ], - "UpstreamPathTemplate": "/products", - "UpstreamHttpMethod": [ "Post" ], - "QoSOptions": { - "ExceptionsAllowedBeforeBreaking": 3, - "DurationOfBreak": 10, - "TimeoutValue": 5000 - } - }, - { - "DownstreamPathTemplate": "/api/products/{productId}", - "DownstreamScheme": "http", - "DownstreamHostAndPorts": [ - { - "Host": "jsonplaceholder.typicode.com", - "Port": 80 - } - ], - "UpstreamPathTemplate": "/products/{productId}", - "UpstreamHttpMethod": [ "Put" ], - "QoSOptions": { - "ExceptionsAllowedBeforeBreaking": 3, - "DurationOfBreak": 10, - "TimeoutValue": 5000 - }, - "FileCacheOptions": { "TtlSeconds": 15 } - }, - { - "DownstreamPathTemplate": "/posts", - "DownstreamScheme": "http", - "DownstreamHostAndPorts": [ - { - "Host": "jsonplaceholder.typicode.com", - "Port": 80 - } - ], - "UpstreamPathTemplate": "/posts/", - "UpstreamHttpMethod": [ "Get" ], - "QoSOptions": { - "ExceptionsAllowedBeforeBreaking": 3, - "DurationOfBreak": 10, - "TimeoutValue": 5000 - }, - "FileCacheOptions": { "TtlSeconds": 15 } - }, - { - "DownstreamPathTemplate": "/", - "DownstreamScheme": "http", - "DownstreamHostAndPorts": [ - { - "Host": "www.bbc.co.uk", - "Port": 80 - } - ], - "UpstreamPathTemplate": "/bbc/", - "UpstreamHttpMethod": [ "Get" ] + "QoSOptions": { + "ExceptionsAllowedBeforeBreaking": 3, + "DurationOfBreak": 10, + "TimeoutValue": 5000 } - ], - - "GlobalConfiguration": { - "RequestIdKey": "ot-traceid" + }, + { + "DownstreamPathTemplate": "/posts/{postId}", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "jsonplaceholder.typicode.com", + "Port": 80 + } + ], + "UpstreamPathTemplate": "/posts/{postId}", + "UpstreamHttpMethod": [ "Get" ], + "RequestIdKey": "ReRouteRequestId", + "HttpHandlerOptions": { + "AllowAutoRedirect": true, + "UseCookieContainer": true, + "UseTracing": true, + "UseProxy": true + }, + "QoSOptions": { + "ExceptionsAllowedBeforeBreaking": 3, + "DurationOfBreak": 10, + "TimeoutValue": 5000 + } + }, + { + "DownstreamPathTemplate": "/posts/{postId}/comments", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "jsonplaceholder.typicode.com", + "Port": 80 + } + ], + "UpstreamPathTemplate": "/posts/{postId}/comments", + "UpstreamHttpMethod": [ "Get" ], + "HttpHandlerOptions": { + "AllowAutoRedirect": true, + "UseCookieContainer": true, + "UseTracing": false + }, + "QoSOptions": { + "ExceptionsAllowedBeforeBreaking": 3, + "DurationOfBreak": 10, + "TimeoutValue": 5000 + } + }, + { + "DownstreamPathTemplate": "/comments", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "jsonplaceholder.typicode.com", + "Port": 80 + } + ], + "UpstreamPathTemplate": "/comments", + "UpstreamHttpMethod": [ "Get" ], + "QoSOptions": { + "ExceptionsAllowedBeforeBreaking": 3, + "DurationOfBreak": 10, + "TimeoutValue": 5000 + } + }, + { + "DownstreamPathTemplate": "/posts", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "jsonplaceholder.typicode.com", + "Port": 80 + } + ], + "UpstreamPathTemplate": "/posts", + "UpstreamHttpMethod": [ "Post" ], + "QoSOptions": { + "ExceptionsAllowedBeforeBreaking": 3, + "DurationOfBreak": 10, + "TimeoutValue": 5000 + } + }, + { + "DownstreamPathTemplate": "/posts/{postId}", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "jsonplaceholder.typicode.com", + "Port": 80 + } + ], + "UpstreamPathTemplate": "/posts/{postId}", + "UpstreamHttpMethod": [ "Put" ], + "QoSOptions": { + "ExceptionsAllowedBeforeBreaking": 3, + "DurationOfBreak": 10, + "TimeoutValue": 5000 + } + }, + { + "DownstreamPathTemplate": "/posts/{postId}", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "jsonplaceholder.typicode.com", + "Port": 80 + } + ], + "UpstreamPathTemplate": "/posts/{postId}", + "UpstreamHttpMethod": [ "Patch" ], + "QoSOptions": { + "ExceptionsAllowedBeforeBreaking": 3, + "DurationOfBreak": 10, + "TimeoutValue": 5000 + } + }, + { + "DownstreamPathTemplate": "/posts/{postId}", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "jsonplaceholder.typicode.com", + "Port": 80 + } + ], + "UpstreamPathTemplate": "/posts/{postId}", + "UpstreamHttpMethod": [ "Delete" ], + "QoSOptions": { + "ExceptionsAllowedBeforeBreaking": 3, + "DurationOfBreak": 10, + "TimeoutValue": 5000 + } + }, + { + "DownstreamPathTemplate": "/api/products", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "jsonplaceholder.typicode.com", + "Port": 80 + } + ], + "UpstreamPathTemplate": "/products", + "UpstreamHttpMethod": [ "Get" ], + "QoSOptions": { + "ExceptionsAllowedBeforeBreaking": 3, + "DurationOfBreak": 10, + "TimeoutValue": 5000 + }, + "FileCacheOptions": { "TtlSeconds": 15 } + }, + { + "DownstreamPathTemplate": "/api/products/{productId}", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "jsonplaceholder.typicode.com", + "Port": 80 + } + ], + "UpstreamPathTemplate": "/products/{productId}", + "UpstreamHttpMethod": [ "Get" ], + "FileCacheOptions": { "TtlSeconds": 15 } + }, + { + "DownstreamPathTemplate": "/api/products", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "jsonplaceholder.typicode.com", + "Port": 80 + } + ], + "UpstreamPathTemplate": "/products", + "UpstreamHttpMethod": [ "Post" ], + "QoSOptions": { + "ExceptionsAllowedBeforeBreaking": 3, + "DurationOfBreak": 10, + "TimeoutValue": 5000 + } + }, + { + "DownstreamPathTemplate": "/api/products/{productId}", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "jsonplaceholder.typicode.com", + "Port": 80 + } + ], + "UpstreamPathTemplate": "/products/{productId}", + "UpstreamHttpMethod": [ "Put" ], + "QoSOptions": { + "ExceptionsAllowedBeforeBreaking": 3, + "DurationOfBreak": 10, + "TimeoutValue": 5000 + }, + "FileCacheOptions": { "TtlSeconds": 15 } + }, + { + "DownstreamPathTemplate": "/posts", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "jsonplaceholder.typicode.com", + "Port": 80 + } + ], + "UpstreamPathTemplate": "/posts/", + "UpstreamHttpMethod": [ "Get" ], + "QoSOptions": { + "ExceptionsAllowedBeforeBreaking": 3, + "DurationOfBreak": 10, + "TimeoutValue": 5000 + }, + "FileCacheOptions": { "TtlSeconds": 15 } + }, + { + "DownstreamPathTemplate": "/", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "www.bbc.co.uk", + "Port": 80 + } + ], + "UpstreamPathTemplate": "/bbc/", + "UpstreamHttpMethod": [ "Get" ] } + ], + + "GlobalConfiguration": { + "RequestIdKey": "ot-traceid" } +} diff --git a/test/Ocelot.ManualTest/web.config b/test/Ocelot.ManualTest/web.config index 20741057..bf98a93d 100644 --- a/test/Ocelot.ManualTest/web.config +++ b/test/Ocelot.ManualTest/web.config @@ -7,8 +7,8 @@ - + - + - + diff --git a/test/Ocelot.UnitTests/Administration/OcelotAdministrationBuilderTests.cs b/test/Ocelot.UnitTests/Administration/OcelotAdministrationBuilderTests.cs index 72771ed4..1eea1619 100644 --- a/test/Ocelot.UnitTests/Administration/OcelotAdministrationBuilderTests.cs +++ b/test/Ocelot.UnitTests/Administration/OcelotAdministrationBuilderTests.cs @@ -1,7 +1,5 @@ namespace Ocelot.UnitTests.Administration { - using System; - using System.Collections.Generic; using IdentityServer4.AccessTokenValidation; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Internal; @@ -10,6 +8,8 @@ namespace Ocelot.UnitTests.Administration using Ocelot.Administration; using Ocelot.DependencyInjection; using Shouldly; + using System; + using System.Collections.Generic; using TestStack.BDDfy; using Xunit; @@ -33,7 +33,7 @@ namespace Ocelot.UnitTests.Administration [Fact] public void should_set_up_administration_with_identity_server_options() { - Action options = o => {}; + Action options = o => { }; this.Given(x => WhenISetUpOcelotServices()) .When(x => WhenISetUpAdministration(options)) @@ -88,4 +88,3 @@ namespace Ocelot.UnitTests.Administration } } } - diff --git a/test/Ocelot.UnitTests/Authentication/AuthenticationMiddlewareTests.cs b/test/Ocelot.UnitTests/Authentication/AuthenticationMiddlewareTests.cs index c173c82e..467966f9 100644 --- a/test/Ocelot.UnitTests/Authentication/AuthenticationMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Authentication/AuthenticationMiddlewareTests.cs @@ -4,20 +4,20 @@ namespace Ocelot.UnitTests.Authentication { + using Microsoft.AspNetCore.Http; + using Moq; + using Ocelot.Authentication.Middleware; + using Ocelot.Configuration; + using Ocelot.Configuration.Builder; + using Ocelot.Logging; + using Ocelot.Middleware; + using Shouldly; using System.Collections.Generic; using System.IO; using System.Text; using System.Threading.Tasks; - using Microsoft.AspNetCore.Http; - using Moq; - using Ocelot.Authentication.Middleware; - using Ocelot.Configuration.Builder; - using Ocelot.Logging; - using Shouldly; using TestStack.BDDfy; using Xunit; - using Ocelot.Configuration; - using Ocelot.Middleware; public class AuthenticationMiddlewareTests { @@ -62,7 +62,8 @@ namespace Ocelot.UnitTests.Authentication private void WhenICallTheMiddleware() { - _next = (context) => { + _next = (context) => + { byte[] byteArray = Encoding.ASCII.GetBytes("The user is authenticated"); var stream = new MemoryStream(byteArray); context.HttpContext.Response.Body = stream; @@ -74,7 +75,8 @@ namespace Ocelot.UnitTests.Authentication private void GivenTheTestServerPipelineIsConfigured() { - _next = (context) => { + _next = (context) => + { byte[] byteArray = Encoding.ASCII.GetBytes("The user is authenticated"); var stream = new MemoryStream(byteArray); context.HttpContext.Response.Body = stream; diff --git a/test/Ocelot.UnitTests/Authorization/AuthorisationMiddlewareTests.cs b/test/Ocelot.UnitTests/Authorization/AuthorisationMiddlewareTests.cs index eaa2441f..eeb99049 100644 --- a/test/Ocelot.UnitTests/Authorization/AuthorisationMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Authorization/AuthorisationMiddlewareTests.cs @@ -2,21 +2,20 @@ namespace Ocelot.UnitTests.Authorization { - using System.Collections.Generic; - using System.Security.Claims; - using System.Threading.Tasks; + using Microsoft.AspNetCore.Http; using Moq; using Ocelot.Authorisation; using Ocelot.Authorisation.Middleware; + using Ocelot.Configuration; using Ocelot.Configuration.Builder; using Ocelot.DownstreamRouteFinder.UrlMatcher; using Ocelot.Logging; using Ocelot.Responses; + using System.Collections.Generic; + using System.Security.Claims; + using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; - using Microsoft.AspNetCore.Http; - using Ocelot.Configuration; - using Values; public class AuthorisationMiddlewareTests { @@ -43,7 +42,7 @@ namespace Ocelot.UnitTests.Authorization [Fact] public void should_call_authorisation_service() { - this.Given(x => x.GivenTheDownStreamRouteIs(new List(), + this.Given(x => x.GivenTheDownStreamRouteIs(new List(), new DownstreamReRouteBuilder() .WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().Build()) .WithIsAuthorised(true) @@ -86,4 +85,4 @@ namespace Ocelot.UnitTests.Authorization , Times.Once); } } -} +} diff --git a/test/Ocelot.UnitTests/Authorization/ClaimsAuthoriserTests.cs b/test/Ocelot.UnitTests/Authorization/ClaimsAuthoriserTests.cs index 11fb341d..b22e7ffc 100644 --- a/test/Ocelot.UnitTests/Authorization/ClaimsAuthoriserTests.cs +++ b/test/Ocelot.UnitTests/Authorization/ClaimsAuthoriserTests.cs @@ -1,12 +1,9 @@ -using System.Collections.Generic; -using System.Security.Claims; -using Ocelot.Authorisation; -using Ocelot.Configuration; +using Ocelot.Authorisation; using Ocelot.DownstreamRouteFinder.UrlMatcher; using Ocelot.Responses; -using Ocelot.Values; - using Shouldly; +using System.Collections.Generic; +using System.Security.Claims; using TestStack.BDDfy; using Xunit; @@ -143,4 +140,4 @@ namespace Ocelot.UnitTests.Authorization _result.Data.ShouldBe(false); } } -} +} diff --git a/test/Ocelot.UnitTests/Cache/CacheKeyGeneratorTests.cs b/test/Ocelot.UnitTests/Cache/CacheKeyGeneratorTests.cs index 362fcc9a..6dc51319 100644 --- a/test/Ocelot.UnitTests/Cache/CacheKeyGeneratorTests.cs +++ b/test/Ocelot.UnitTests/Cache/CacheKeyGeneratorTests.cs @@ -1,31 +1,37 @@ -using System.Net.Http; -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; using Ocelot.Cache; using Ocelot.Middleware; using Shouldly; +using System.Net.Http; using TestStack.BDDfy; using Xunit; -namespace Ocelot.UnitTests.Cache { - public class CacheKeyGeneratorTests { +namespace Ocelot.UnitTests.Cache +{ + public class CacheKeyGeneratorTests + { private readonly ICacheKeyGenerator _cacheKeyGenerator; private readonly DownstreamContext _downstreamContext; - public CacheKeyGeneratorTests() { + public CacheKeyGeneratorTests() + { _cacheKeyGenerator = new CacheKeyGenerator(); _cacheKeyGenerator = new CacheKeyGenerator(); - _downstreamContext = new DownstreamContext(new DefaultHttpContext()) { + _downstreamContext = new DownstreamContext(new DefaultHttpContext()) + { DownstreamRequest = new Ocelot.Request.Middleware.DownstreamRequest(new HttpRequestMessage(HttpMethod.Get, "https://some.url/blah?abcd=123")) }; } [Fact] - public void should_generate_cache_key_from_context() { + public void should_generate_cache_key_from_context() + { this.Given(x => x.GivenCacheKeyFromContext(_downstreamContext)) .BDDfy(); } - private void GivenCacheKeyFromContext(DownstreamContext context) { + private void GivenCacheKeyFromContext(DownstreamContext context) + { string generatedCacheKey = _cacheKeyGenerator.GenerateRequestCacheKey(context); string cachekey = MD5Helper.GenerateMd5("GET-https://some.url/blah?abcd=123"); generatedCacheKey.ShouldBe(cachekey); diff --git a/test/Ocelot.UnitTests/Cache/InMemoryCacheTests.cs b/test/Ocelot.UnitTests/Cache/InMemoryCacheTests.cs index 9c17ba3c..b9f5b7c0 100644 --- a/test/Ocelot.UnitTests/Cache/InMemoryCacheTests.cs +++ b/test/Ocelot.UnitTests/Cache/InMemoryCacheTests.cs @@ -1,9 +1,9 @@ namespace Ocelot.UnitTests.Cache { - using System; - using System.Threading; using Ocelot.Cache; using Shouldly; + using System; + using System.Threading; using Xunit; public class InMemoryCacheTests @@ -68,7 +68,7 @@ result.ShouldBeNull(); } - class Fake + private class Fake { public Fake(int value) { diff --git a/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareTests.cs b/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareTests.cs index 62d972f9..41fe0aad 100644 --- a/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareTests.cs @@ -1,9 +1,5 @@ namespace Ocelot.UnitTests.Cache { - using System; - using System.Collections.Generic; - using System.Net.Http; - using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Moq; using Ocelot.Cache; @@ -13,15 +9,18 @@ using Ocelot.DownstreamRouteFinder; using Ocelot.DownstreamRouteFinder.UrlMatcher; using Ocelot.Logging; + using Ocelot.Middleware; + using System; + using System.Collections.Generic; + using System.Net; + using System.Net.Http; + using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; - using System.Net; - using Microsoft.Extensions.DependencyInjection; - using Ocelot.Middleware; public class OutputCacheMiddlewareTests { - private readonly Mock> _cache; + private readonly Mock> _cache; private readonly Mock _loggerFactory; private Mock _logger; private OutputCacheMiddleware _middleware; @@ -30,7 +29,6 @@ private readonly ICacheKeyGenerator _cacheKeyGenerator; private CachedResponse _response; - public OutputCacheMiddlewareTests() { _cache = new Mock>(); @@ -119,7 +117,7 @@ .Build()) .WithUpstreamHttpMethod(new List { "Get" }) .Build(); - + var downstreamRoute = new DownstreamRoute(new List(), reRoute); _downstreamContext.TemplatePlaceholderNameAndValues = downstreamRoute.TemplatePlaceholderNameAndValues; diff --git a/test/Ocelot.UnitTests/Cache/RegionCreatorTests.cs b/test/Ocelot.UnitTests/Cache/RegionCreatorTests.cs index 8c3e3b63..ebcd6e25 100644 --- a/test/Ocelot.UnitTests/Cache/RegionCreatorTests.cs +++ b/test/Ocelot.UnitTests/Cache/RegionCreatorTests.cs @@ -1,9 +1,7 @@ -using System.Collections.Generic; using Ocelot.Cache; -using Ocelot.Configuration; -using Ocelot.Configuration.Builder; using Ocelot.Configuration.File; using Shouldly; +using System.Collections.Generic; using TestStack.BDDfy; using Xunit; @@ -44,15 +42,15 @@ namespace Ocelot.UnitTests.Cache .When(_ => WhenICreateTheRegion()) .Then(_ => ThenTheRegionIs("region")) .BDDfy(); - } - + } + private void GivenTheReRoute(FileReRoute reRoute) { _reRoute = reRoute; } private void WhenICreateTheRegion() - { + { RegionCreator regionCreator = new RegionCreator(); _result = regionCreator.Create(_reRoute); } @@ -62,4 +60,4 @@ namespace Ocelot.UnitTests.Cache _result.ShouldBe(expected); } } -} \ No newline at end of file +} diff --git a/test/Ocelot.UnitTests/CacheManager/OcelotBuilderExtensionsTests.cs b/test/Ocelot.UnitTests/CacheManager/OcelotBuilderExtensionsTests.cs index 73eaf495..efa5631c 100644 --- a/test/Ocelot.UnitTests/CacheManager/OcelotBuilderExtensionsTests.cs +++ b/test/Ocelot.UnitTests/CacheManager/OcelotBuilderExtensionsTests.cs @@ -1,8 +1,5 @@ namespace Ocelot.UnitTests.CacheManager { - using System; - using System.Collections.Generic; - using System.Linq; using global::CacheManager.Core; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Internal; @@ -14,6 +11,9 @@ using Ocelot.Configuration.File; using Ocelot.DependencyInjection; using Shouldly; + using System; + using System.Collections.Generic; + using System.Linq; using TestStack.BDDfy; using Xunit; @@ -79,7 +79,8 @@ { try { - _ocelotBuilder.AddCacheManager(x => { + _ocelotBuilder.AddCacheManager(x => + { x.WithMaxRetries(_maxRetries); x.WithDictionaryHandle(); }); diff --git a/test/Ocelot.UnitTests/CacheManager/OcelotCacheManagerCache.cs b/test/Ocelot.UnitTests/CacheManager/OcelotCacheManagerCache.cs index bd746d99..26432b32 100644 --- a/test/Ocelot.UnitTests/CacheManager/OcelotCacheManagerCache.cs +++ b/test/Ocelot.UnitTests/CacheManager/OcelotCacheManagerCache.cs @@ -1,10 +1,10 @@ namespace Ocelot.UnitTests.CacheManager { - using System; using global::CacheManager.Core; using Moq; using Ocelot.Cache.CacheManager; using Shouldly; + using System; using TestStack.BDDfy; using Xunit; diff --git a/test/Ocelot.UnitTests/CacheManager/OutputCacheMiddlewareRealCacheTests.cs b/test/Ocelot.UnitTests/CacheManager/OutputCacheMiddlewareRealCacheTests.cs index 853354ef..aa5d82a8 100644 --- a/test/Ocelot.UnitTests/CacheManager/OutputCacheMiddlewareRealCacheTests.cs +++ b/test/Ocelot.UnitTests/CacheManager/OutputCacheMiddlewareRealCacheTests.cs @@ -1,11 +1,5 @@ namespace Ocelot.UnitTests.CacheManager { - using System.Collections.Generic; - using System.Linq; - using System.Net; - using System.Net.Http; - using System.Net.Http.Headers; - using System.Threading.Tasks; using global::CacheManager.Core; using Microsoft.AspNetCore.Http; using Moq; @@ -17,6 +11,12 @@ using Ocelot.Logging; using Ocelot.Middleware; using Shouldly; + using System.Collections.Generic; + using System.Linq; + using System.Net; + using System.Net.Http; + using System.Net.Http.Headers; + using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; @@ -33,7 +33,7 @@ public OutputCacheMiddlewareRealCacheTests() { _loggerFactory = new Mock(); - _logger = new Mock(); + _logger = new Mock(); _loggerFactory.Setup(x => x.CreateLogger()).Returns(_logger.Object); var cacheManagerOutputCache = CacheFactory.Build("OcelotOutputCache", x => { @@ -52,7 +52,7 @@ { var content = new StringContent("{\"Test\": 1}") { - Headers = { ContentType = new MediaTypeHeaderValue("application/json")} + Headers = { ContentType = new MediaTypeHeaderValue("application/json") } }; var response = new DownstreamResponse(content, HttpStatusCode.OK, new List>>(), "fooreason"); diff --git a/test/Ocelot.UnitTests/Claims/AddClaimsToRequestTests.cs b/test/Ocelot.UnitTests/Claims/AddClaimsToRequestTests.cs index 33ff1e06..cc6428f4 100644 --- a/test/Ocelot.UnitTests/Claims/AddClaimsToRequestTests.cs +++ b/test/Ocelot.UnitTests/Claims/AddClaimsToRequestTests.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Security.Claims; -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; using Moq; using Ocelot.Claims; using Ocelot.Configuration; @@ -8,6 +6,8 @@ using Ocelot.Errors; using Ocelot.Infrastructure.Claims.Parser; using Ocelot.Responses; using Shouldly; +using System.Collections.Generic; +using System.Security.Claims; using TestStack.BDDfy; using Xunit; @@ -131,7 +131,7 @@ namespace Ocelot.UnitTests.Claims _result.IsError.ShouldBe(true); } - class AnyError : Error + private class AnyError : Error { public AnyError() : base("blahh", OcelotErrorCode.UnknownError) @@ -139,4 +139,4 @@ namespace Ocelot.UnitTests.Claims } } } -} +} diff --git a/test/Ocelot.UnitTests/Claims/ClaimsToClaimsMiddlewareTests.cs b/test/Ocelot.UnitTests/Claims/ClaimsToClaimsMiddlewareTests.cs index 5d96884f..7652aeee 100644 --- a/test/Ocelot.UnitTests/Claims/ClaimsToClaimsMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Claims/ClaimsToClaimsMiddlewareTests.cs @@ -2,8 +2,6 @@ namespace Ocelot.UnitTests.Claims { - using System.Collections.Generic; - using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Moq; using Ocelot.Claims; @@ -14,6 +12,8 @@ namespace Ocelot.UnitTests.Claims using Ocelot.DownstreamRouteFinder.UrlMatcher; using Ocelot.Logging; using Ocelot.Responses; + using System.Collections.Generic; + using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; diff --git a/test/Ocelot.UnitTests/Configuration/AggregatesCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/AggregatesCreatorTests.cs index e124fe74..7395e1b3 100644 --- a/test/Ocelot.UnitTests/Configuration/AggregatesCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/AggregatesCreatorTests.cs @@ -1,15 +1,15 @@ namespace Ocelot.UnitTests.Configuration { - using System.Collections.Generic; - using System.Net.Http; using Moq; using Ocelot.Configuration; using Ocelot.Configuration.Builder; using Ocelot.Configuration.Creator; using Ocelot.Configuration.File; - using Values; using Shouldly; + using System.Collections.Generic; + using System.Net.Http; using TestStack.BDDfy; + using Values; using Xunit; public class AggregatesCreatorTests @@ -112,13 +112,13 @@ namespace Ocelot.UnitTests.Configuration _result[1].UpstreamTemplatePattern.ShouldBe(_aggregate2Utp); _result[1].Aggregator.ShouldBe(_fileConfiguration.Aggregates[1].Aggregator); _result[1].DownstreamReRoute.ShouldContain(x => x == _reRoutes[2].DownstreamReRoute[0]); - _result[1].DownstreamReRoute.ShouldContain(x => x == _reRoutes[3].DownstreamReRoute[0]); + _result[1].DownstreamReRoute.ShouldContain(x => x == _reRoutes[3].DownstreamReRoute[0]); } private void ThenTheUtpCreatorIsCalledCorrectly() { _utpCreator.Verify(x => x.Create(_fileConfiguration.Aggregates[0]), Times.Once); - _utpCreator.Verify(x => x.Create(_fileConfiguration.Aggregates[1]), Times.Once); + _utpCreator.Verify(x => x.Create(_fileConfiguration.Aggregates[1]), Times.Once); } private void GivenTheUtpCreatorReturns() diff --git a/test/Ocelot.UnitTests/Configuration/AuthenticationOptionsCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/AuthenticationOptionsCreatorTests.cs index 5ad18137..1056dca5 100644 --- a/test/Ocelot.UnitTests/Configuration/AuthenticationOptionsCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/AuthenticationOptionsCreatorTests.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic; using Ocelot.Configuration; using Ocelot.Configuration.Builder; using Ocelot.Configuration.Creator; using Ocelot.Configuration.File; using Shouldly; +using System.Collections.Generic; using TestStack.BDDfy; using Xunit; @@ -54,9 +54,9 @@ namespace Ocelot.UnitTests.Configuration } private void ThenTheFollowingConfigIsReturned(AuthenticationOptions expected) - { - _result.AllowedScopes.ShouldBe(expected.AllowedScopes); + { + _result.AllowedScopes.ShouldBe(expected.AllowedScopes); _result.AuthenticationProviderKey.ShouldBe(expected.AuthenticationProviderKey); } } -} \ No newline at end of file +} diff --git a/test/Ocelot.UnitTests/Configuration/ClaimToThingConfigurationParserTests.cs b/test/Ocelot.UnitTests/Configuration/ClaimToThingConfigurationParserTests.cs index b8d3769a..db1f881a 100644 --- a/test/Ocelot.UnitTests/Configuration/ClaimToThingConfigurationParserTests.cs +++ b/test/Ocelot.UnitTests/Configuration/ClaimToThingConfigurationParserTests.cs @@ -1,10 +1,10 @@ -using System.Collections.Generic; -using System.Linq; -using Ocelot.Configuration; +using Ocelot.Configuration; using Ocelot.Configuration.Parser; using Ocelot.Errors; using Ocelot.Responses; using Shouldly; +using System.Collections.Generic; +using System.Linq; using TestStack.BDDfy; using Xunit; @@ -114,4 +114,4 @@ namespace Ocelot.UnitTests.Configuration _dictionary = dictionary; } } -} +} diff --git a/test/Ocelot.UnitTests/Configuration/ClaimsToThingCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/ClaimsToThingCreatorTests.cs index cda6d5de..8f2a64f2 100644 --- a/test/Ocelot.UnitTests/Configuration/ClaimsToThingCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/ClaimsToThingCreatorTests.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; -using System.Linq; using Moq; using Ocelot.Configuration; using Ocelot.Configuration.Creator; @@ -8,6 +6,8 @@ using Ocelot.Errors; using Ocelot.Logging; using Ocelot.Responses; using Shouldly; +using System.Collections.Generic; +using System.Linq; using TestStack.BDDfy; using Xunit; @@ -16,7 +16,7 @@ namespace Ocelot.UnitTests.Configuration public class ClaimsToThingCreatorTests { private readonly Mock _configParser; - private Dictionary _claimsToThings; + private Dictionary _claimsToThings; private ClaimsToThingCreator _claimsToThingsCreator; private Mock _loggerFactory; private List _result; @@ -36,13 +36,13 @@ namespace Ocelot.UnitTests.Configuration [Fact] public void should_return_claims_to_things() { - var userInput = new Dictionary() + var userInput = new Dictionary() { {"CustomerId", "Claims[CustomerId] > value"} }; - var claimsToThing = new OkResponse(new ClaimToThing("CustomerId", "CustomerId", "", 0)); - + var claimsToThing = new OkResponse(new ClaimToThing("CustomerId", "CustomerId", "", 0)); + this.Given(x => x.GivenTheFollowingDictionary(userInput)) .And(x => x.GivenTheConfigHeaderExtractorReturns(claimsToThing)) .When(x => x.WhenIGetTheThings()) @@ -53,14 +53,14 @@ namespace Ocelot.UnitTests.Configuration [Fact] public void should_log_error_if_cannot_parse_claim_to_thing() - { - var userInput = new Dictionary() + { + var userInput = new Dictionary() { {"CustomerId", "Claims[CustomerId] > value"} }; - var claimsToThing = new ErrorResponse(It.IsAny()); - + var claimsToThing = new ErrorResponse(It.IsAny()); + this.Given(x => x.GivenTheFollowingDictionary(userInput)) .And(x => x.GivenTheConfigHeaderExtractorReturns(claimsToThing)) .When(x => x.WhenIGetTheThings()) @@ -80,7 +80,7 @@ namespace Ocelot.UnitTests.Configuration _result.Count.ShouldBeGreaterThan(0); } - private void GivenTheFollowingDictionary(Dictionary claimsToThings) + private void GivenTheFollowingDictionary(Dictionary claimsToThings) { _claimsToThings = claimsToThings; } @@ -108,4 +108,4 @@ namespace Ocelot.UnitTests.Configuration .Verify(x => x.Extract(_claimsToThings.First().Key, _claimsToThings.First().Value), Times.Once); } } -} +} diff --git a/test/Ocelot.UnitTests/Configuration/ConfigurationCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/ConfigurationCreatorTests.cs index 1e288265..a51ec161 100644 --- a/test/Ocelot.UnitTests/Configuration/ConfigurationCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/ConfigurationCreatorTests.cs @@ -1,6 +1,5 @@ namespace Ocelot.UnitTests.Configuration { - using System.Collections.Generic; using Microsoft.Extensions.DependencyInjection; using Moq; using Ocelot.Configuration; @@ -8,6 +7,7 @@ namespace Ocelot.UnitTests.Configuration using Ocelot.Configuration.File; using Ocelot.DependencyInjection; using Shouldly; + using System.Collections.Generic; using TestStack.BDDfy; using Xunit; diff --git a/test/Ocelot.UnitTests/Configuration/DiskFileConfigurationRepositoryTests.cs b/test/Ocelot.UnitTests/Configuration/DiskFileConfigurationRepositoryTests.cs index 8f99ef3d..d084c2d6 100644 --- a/test/Ocelot.UnitTests/Configuration/DiskFileConfigurationRepositoryTests.cs +++ b/test/Ocelot.UnitTests/Configuration/DiskFileConfigurationRepositoryTests.cs @@ -1,17 +1,17 @@ namespace Ocelot.UnitTests.Configuration { + using Microsoft.AspNetCore.Hosting; + using Moq; + using Newtonsoft.Json; + using Ocelot.Configuration.File; + using Ocelot.Configuration.Repository; + using Shouldly; using System; using System.Collections.Generic; - using Moq; - using Ocelot.Configuration.File; - using Shouldly; - using TestStack.BDDfy; - using Xunit; - using Newtonsoft.Json; using System.IO; using System.Threading; - using Microsoft.AspNetCore.Hosting; - using Ocelot.Configuration.Repository; + using TestStack.BDDfy; + using Xunit; public class DiskFileConfigurationRepositoryTests : IDisposable { @@ -26,6 +26,7 @@ namespace Ocelot.UnitTests.Configuration // cant pick it up if they run in parralel..and the semaphore stops them running at the same time...sigh // these are not really unit tests but whatever... private string _environmentName = "DEV.DEV"; + private static SemaphoreSlim _semaphore; public DiskFileConfigurationRepositoryTests() @@ -102,7 +103,7 @@ namespace Ocelot.UnitTests.Configuration private void GivenTheUserAddedOcelotJson() { - _ocelotJsonPath = $"{AppContext.BaseDirectory}/ocelot.json"; + _ocelotJsonPath = $"{AppContext.BaseDirectory}/ocelot.json"; if (File.Exists(_ocelotJsonPath)) { @@ -136,7 +137,7 @@ namespace Ocelot.UnitTests.Configuration _result.GlobalConfiguration.ServiceDiscoveryProvider.Host.ShouldBe(expecteds.GlobalConfiguration.ServiceDiscoveryProvider.Host); _result.GlobalConfiguration.ServiceDiscoveryProvider.Port.ShouldBe(expecteds.GlobalConfiguration.ServiceDiscoveryProvider.Port); - for(var i = 0; i < _result.ReRoutes.Count; i++) + for (var i = 0; i < _result.ReRoutes.Count; i++) { for (int j = 0; j < _result.ReRoutes[i].DownstreamHostAndPorts.Count; j++) { @@ -176,7 +177,7 @@ namespace Ocelot.UnitTests.Configuration private void ThenTheConfigurationJsonIsIndented(FileConfiguration expecteds) { var path = !string.IsNullOrEmpty(_environmentSpecificPath) ? _environmentSpecificPath : _environmentSpecificPath = $"{AppContext.BaseDirectory}/ocelot{(string.IsNullOrEmpty(_environmentName) ? string.Empty : ".")}{_environmentName}.json"; - + var resultText = File.ReadAllText(path); var expectedText = JsonConvert.SerializeObject(expecteds, Formatting.Indented); resultText.ShouldBe(expectedText); @@ -193,7 +194,7 @@ namespace Ocelot.UnitTests.Configuration _result.GlobalConfiguration.ServiceDiscoveryProvider.Host.ShouldBe(expecteds.GlobalConfiguration.ServiceDiscoveryProvider.Host); _result.GlobalConfiguration.ServiceDiscoveryProvider.Port.ShouldBe(expecteds.GlobalConfiguration.ServiceDiscoveryProvider.Port); - for(var i = 0; i < _result.ReRoutes.Count; i++) + for (var i = 0; i < _result.ReRoutes.Count; i++) { for (int j = 0; j < _result.ReRoutes[i].DownstreamHostAndPorts.Count; j++) { diff --git a/test/Ocelot.UnitTests/Configuration/DownstreamAddressesCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/DownstreamAddressesCreatorTests.cs index 060398f9..ef6bfede 100644 --- a/test/Ocelot.UnitTests/Configuration/DownstreamAddressesCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/DownstreamAddressesCreatorTests.cs @@ -1,9 +1,8 @@ -using System.Collections.Generic; using Ocelot.Configuration; -using Ocelot.Configuration.Builder; using Ocelot.Configuration.Creator; using Ocelot.Configuration.File; using Shouldly; +using System.Collections.Generic; using TestStack.BDDfy; using Xunit; @@ -47,7 +46,7 @@ namespace Ocelot.UnitTests.Configuration new FileHostAndPort { Host = "test", - Port = 80 + Port = 80 } }, }; @@ -87,8 +86,8 @@ namespace Ocelot.UnitTests.Configuration { new DownstreamHostAndPort("test", 80), new DownstreamHostAndPort("west", 443) - }; - + }; + this.Given(x => GivenTheFollowingReRoute(reRoute)) .When(x => WhenICreate()) .Then(x => TheThenFollowingIsReturned(expected)) @@ -119,4 +118,4 @@ namespace Ocelot.UnitTests.Configuration } } } -} +} diff --git a/test/Ocelot.UnitTests/Configuration/DynamicsCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/DynamicsCreatorTests.cs index 6c6beb9c..8a0601d3 100644 --- a/test/Ocelot.UnitTests/Configuration/DynamicsCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/DynamicsCreatorTests.cs @@ -1,12 +1,12 @@ namespace Ocelot.UnitTests.Configuration { - using System.Collections.Generic; using Moq; using Ocelot.Configuration; using Ocelot.Configuration.Builder; using Ocelot.Configuration.Creator; using Ocelot.Configuration.File; using Shouldly; + using System.Collections.Generic; using TestStack.BDDfy; using Xunit; diff --git a/test/Ocelot.UnitTests/Configuration/FileConfigurationPollerTests.cs b/test/Ocelot.UnitTests/Configuration/FileConfigurationPollerTests.cs index 35294889..3008fc6b 100644 --- a/test/Ocelot.UnitTests/Configuration/FileConfigurationPollerTests.cs +++ b/test/Ocelot.UnitTests/Configuration/FileConfigurationPollerTests.cs @@ -1,19 +1,18 @@ -using System; -using System.Collections.Generic; -using System.Threading; using Moq; +using Ocelot.Configuration; +using Ocelot.Configuration.Creator; using Ocelot.Configuration.File; using Ocelot.Configuration.Repository; -using Ocelot.Configuration.Setter; using Ocelot.Logging; using Ocelot.Responses; using Ocelot.UnitTests.Responder; +using Shouldly; +using System; +using System.Collections.Generic; +using System.Threading; using TestStack.BDDfy; using Xunit; -using Shouldly; using static Ocelot.Infrastructure.Wait; -using Ocelot.Configuration.Creator; -using Ocelot.Configuration; namespace Ocelot.UnitTests.Configuration { @@ -44,20 +43,21 @@ namespace Ocelot.UnitTests.Configuration _poller = new FileConfigurationPoller(_factory.Object, _repo.Object, _config.Object, _internalConfigRepo.Object, _internalConfigCreator.Object); _poller.StartAsync(new CancellationToken()); } - + [Fact] public void should_start() { - this.Given(x => ThenTheSetterIsCalled(_fileConfig, 1)) - .BDDfy(); + this.Given(x => ThenTheSetterIsCalled(_fileConfig, 1)) + .BDDfy(); } [Fact] public void should_call_setter_when_gets_new_config() { - var newConfig = new FileConfiguration { + var newConfig = new FileConfiguration + { ReRoutes = new List - { + { new FileReRoute { DownstreamHostAndPorts = new List @@ -126,8 +126,6 @@ namespace Ocelot.UnitTests.Configuration .BDDfy(); } - - private void WhenProviderErrors() { _repo @@ -145,14 +143,15 @@ namespace Ocelot.UnitTests.Configuration private void ThenTheSetterIsCalled(FileConfiguration fileConfig, int times) { - var result = WaitFor(4000).Until(() => { + var result = WaitFor(4000).Until(() => + { try { _internalConfigRepo.Verify(x => x.AddOrReplace(_internalConfig), Times.Exactly(times)); _internalConfigCreator.Verify(x => x.Create(fileConfig), Times.Exactly(times)); return true; } - catch(Exception) + catch (Exception) { return false; } @@ -162,14 +161,15 @@ namespace Ocelot.UnitTests.Configuration private void ThenTheSetterIsCalledAtLeast(FileConfiguration fileConfig, int times) { - var result = WaitFor(4000).Until(() => { + var result = WaitFor(4000).Until(() => + { try { _internalConfigRepo.Verify(x => x.AddOrReplace(_internalConfig), Times.AtLeast(times)); _internalConfigCreator.Verify(x => x.Create(fileConfig), Times.AtLeast(times)); return true; } - catch(Exception) + catch (Exception) { return false; } diff --git a/test/Ocelot.UnitTests/Configuration/FileConfigurationSetterTests.cs b/test/Ocelot.UnitTests/Configuration/FileConfigurationSetterTests.cs index 57f8c4d7..53289434 100644 --- a/test/Ocelot.UnitTests/Configuration/FileConfigurationSetterTests.cs +++ b/test/Ocelot.UnitTests/Configuration/FileConfigurationSetterTests.cs @@ -1,5 +1,3 @@ -using System; -using System.Collections.Generic; using Moq; using Ocelot.Configuration; using Ocelot.Configuration.Builder; @@ -10,6 +8,7 @@ using Ocelot.Configuration.Setter; using Ocelot.Errors; using Ocelot.Responses; using Shouldly; +using System.Collections.Generic; using TestStack.BDDfy; using Xunit; @@ -22,7 +21,7 @@ namespace Ocelot.UnitTests.Configuration private Mock _configRepo; private Mock _configCreator; private Response _configuration; - private object _result; + private object _result; private Mock _repo; public FileConfigurationSetterTests() @@ -109,4 +108,4 @@ namespace Ocelot.UnitTests.Configuration .Verify(x => x.AddOrReplace(_configuration.Data), Times.Once); } } -} +} diff --git a/test/Ocelot.UnitTests/Configuration/FileInternalConfigurationCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/FileInternalConfigurationCreatorTests.cs index 71d3fd9e..6ccc4448 100644 --- a/test/Ocelot.UnitTests/Configuration/FileInternalConfigurationCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/FileInternalConfigurationCreatorTests.cs @@ -1,20 +1,20 @@ namespace Ocelot.UnitTests.Configuration { - using System.Collections.Generic; using Moq; using Ocelot.Configuration; using Ocelot.Configuration.Builder; using Ocelot.Configuration.Creator; using Ocelot.Configuration.File; using Ocelot.Configuration.Validator; + using Ocelot.Errors; using Ocelot.Responses; + using Ocelot.UnitTests.Responder; using Shouldly; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; - using Ocelot.Errors; - using System.Threading.Tasks; - using Ocelot.UnitTests.Responder; - using System.Linq; public class FileInternalConfigurationCreatorTests { diff --git a/test/Ocelot.UnitTests/Configuration/HashCreationTests.cs b/test/Ocelot.UnitTests/Configuration/HashCreationTests.cs index 5f6c9064..e243dce4 100644 --- a/test/Ocelot.UnitTests/Configuration/HashCreationTests.cs +++ b/test/Ocelot.UnitTests/Configuration/HashCreationTests.cs @@ -1,7 +1,6 @@ +using Microsoft.AspNetCore.Cryptography.KeyDerivation; using System; using System.Security.Cryptography; -using Microsoft.AspNetCore.Cryptography.KeyDerivation; -using Shouldly; using Xunit; namespace Ocelot.UnitTests.Configuration @@ -20,8 +19,8 @@ namespace Ocelot.UnitTests.Configuration rng.GetBytes(salt); } - var storedSalt = Convert.ToBase64String(salt); - + var storedSalt = Convert.ToBase64String(salt); + var storedHash = Convert.ToBase64String(KeyDerivation.Pbkdf2( password: password, salt: salt, @@ -30,4 +29,4 @@ namespace Ocelot.UnitTests.Configuration numBytesRequested: 256 / 8)); } } -} \ No newline at end of file +} diff --git a/test/Ocelot.UnitTests/Configuration/HeaderFindAndReplaceCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/HeaderFindAndReplaceCreatorTests.cs index 6dc292f3..78896bfb 100644 --- a/test/Ocelot.UnitTests/Configuration/HeaderFindAndReplaceCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/HeaderFindAndReplaceCreatorTests.cs @@ -1,16 +1,13 @@ -using System; -using System.Collections.Generic; using Moq; using Ocelot.Configuration; -using Ocelot.Configuration.Builder; using Ocelot.Configuration.Creator; using Ocelot.Configuration.File; using Ocelot.Infrastructure; using Ocelot.Logging; -using Ocelot.Middleware; using Ocelot.Responses; using Ocelot.UnitTests.Responder; using Shouldly; +using System.Collections.Generic; using TestStack.BDDfy; using Xunit; @@ -43,8 +40,8 @@ namespace Ocelot.UnitTests.Configuration { {"Test", "Test, Chicken"}, {"Moop", "o, a"} - }, - DownstreamHeaderTransform = new Dictionary + }, + DownstreamHeaderTransform = new Dictionary { {"Pop", "West, East"}, {"Bop", "e, r"} @@ -96,8 +93,8 @@ namespace Ocelot.UnitTests.Configuration public void should_use_base_url_placeholder() { var reRoute = new FileReRoute - { - DownstreamHeaderTransform = new Dictionary + { + DownstreamHeaderTransform = new Dictionary { {"Location", "http://www.bbc.co.uk/, {BaseUrl}"}, } @@ -153,8 +150,8 @@ namespace Ocelot.UnitTests.Configuration public void should_use_base_url_partial_placeholder() { var reRoute = new FileReRoute - { - DownstreamHeaderTransform = new Dictionary + { + DownstreamHeaderTransform = new Dictionary { {"Location", "http://www.bbc.co.uk/pay, {BaseUrl}pay"}, } @@ -176,8 +173,8 @@ namespace Ocelot.UnitTests.Configuration public void should_add_trace_id_header() { var reRoute = new FileReRoute - { - DownstreamHeaderTransform = new Dictionary + { + DownstreamHeaderTransform = new Dictionary { {"Trace-Id", "{TraceId}"}, } @@ -244,8 +241,8 @@ namespace Ocelot.UnitTests.Configuration { _result.AddHeadersToDownstream[0].Key.ShouldBe(addHeader.Key); _result.AddHeadersToDownstream[0].Value.ShouldBe(addHeader.Value); - } - + } + private void ThenTheFollowingAddHeaderToUpstreamIsReturned(AddHeader addHeader) { _result.AddHeadersToUpstream[0].Key.ShouldBe(addHeader.Key); @@ -254,8 +251,8 @@ namespace Ocelot.UnitTests.Configuration private void ThenTheFollowingDownstreamIsReturned(List downstream) { - _result.Downstream.Count.ShouldBe(downstream.Count); - + _result.Downstream.Count.ShouldBe(downstream.Count); + for (int i = 0; i < _result.Downstream.Count; i++) { var result = _result.Downstream[i]; @@ -264,7 +261,7 @@ namespace Ocelot.UnitTests.Configuration result.Index.ShouldBe(expected.Index); result.Key.ShouldBe(expected.Key); result.Replace.ShouldBe(expected.Replace); - } + } } private void GivenTheReRoute(FileReRoute reRoute) @@ -279,8 +276,8 @@ namespace Ocelot.UnitTests.Configuration private void ThenTheFollowingUpstreamIsReturned(List expecteds) { - _result.Upstream.Count.ShouldBe(expecteds.Count); - + _result.Upstream.Count.ShouldBe(expecteds.Count); + for (int i = 0; i < _result.Upstream.Count; i++) { var result = _result.Upstream[i]; @@ -292,4 +289,4 @@ namespace Ocelot.UnitTests.Configuration } } } -} +} diff --git a/test/Ocelot.UnitTests/Configuration/HttpHandlerOptionsCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/HttpHandlerOptionsCreatorTests.cs index e20aca02..4915dc5d 100644 --- a/test/Ocelot.UnitTests/Configuration/HttpHandlerOptionsCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/HttpHandlerOptionsCreatorTests.cs @@ -1,20 +1,19 @@ -using System; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Ocelot.Configuration; using Ocelot.Configuration.Creator; using Ocelot.Configuration.File; -using Ocelot.Requester; using Shouldly; +using System; using TestStack.BDDfy; using Xunit; namespace Ocelot.UnitTests.Configuration { + using Microsoft.AspNetCore.Http; + using Ocelot.Logging; using System.Net.Http; using System.Threading; using System.Threading.Tasks; - using Microsoft.AspNetCore.Http; - using Ocelot.Logging; public class HttpHandlerOptionsCreatorTests { @@ -34,7 +33,7 @@ namespace Ocelot.UnitTests.Configuration [Fact] public void should_not_use_tracing_if_fake_tracer_registered() { - var fileReRoute = new FileReRoute + var fileReRoute = new FileReRoute { HttpHandlerOptions = new FileHttpHandlerOptions { @@ -53,7 +52,7 @@ namespace Ocelot.UnitTests.Configuration [Fact] public void should_use_tracing_if_real_tracer_registered() { - var fileReRoute = new FileReRoute + var fileReRoute = new FileReRoute { HttpHandlerOptions = new FileHttpHandlerOptions { @@ -165,7 +164,7 @@ namespace Ocelot.UnitTests.Configuration _httpHandlerOptionsCreator = new HttpHandlerOptionsCreator(_serviceProvider); } - class FakeTracer : ITracer + private class FakeTracer : ITracer { public void Event(HttpContext httpContext, string @event) { diff --git a/test/Ocelot.UnitTests/Configuration/InMemoryConfigurationRepositoryTests.cs b/test/Ocelot.UnitTests/Configuration/InMemoryConfigurationRepositoryTests.cs index dfa6362f..30f89916 100644 --- a/test/Ocelot.UnitTests/Configuration/InMemoryConfigurationRepositoryTests.cs +++ b/test/Ocelot.UnitTests/Configuration/InMemoryConfigurationRepositoryTests.cs @@ -1,10 +1,10 @@ -using System; -using System.Collections.Generic; -using Ocelot.Configuration; +using Ocelot.Configuration; using Ocelot.Configuration.Builder; using Ocelot.Configuration.Repository; using Ocelot.Responses; using Shouldly; +using System; +using System.Collections.Generic; using TestStack.BDDfy; using Xunit; @@ -71,7 +71,7 @@ namespace Ocelot.UnitTests.Configuration _result.IsError.ShouldBeFalse(); } - class FakeConfig : IInternalConfiguration + private class FakeConfig : IInternalConfiguration { private readonly string _downstreamTemplatePath; @@ -100,15 +100,15 @@ namespace Ocelot.UnitTests.Configuration } } - public string AdministrationPath {get;} + public string AdministrationPath { get; } public ServiceProviderConfiguration ServiceProviderConfiguration => throw new NotImplementedException(); - public string RequestId {get;} + public string RequestId { get; } public LoadBalancerOptions LoadBalancerOptions { get; } public string DownstreamScheme { get; } public QoSOptions QoSOptions { get; } public HttpHandlerOptions HttpHandlerOptions { get; } } } -} +} diff --git a/test/Ocelot.UnitTests/Configuration/QoSOptionsCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/QoSOptionsCreatorTests.cs index 0a68c238..911f30e3 100644 --- a/test/Ocelot.UnitTests/Configuration/QoSOptionsCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/QoSOptionsCreatorTests.cs @@ -17,8 +17,8 @@ namespace Ocelot.UnitTests.Configuration public QoSOptionsCreatorTests() { _creator = new QoSOptionsCreator(); - } - + } + [Fact] public void should_create_qos_options() { @@ -26,7 +26,7 @@ namespace Ocelot.UnitTests.Configuration { QoSOptions = new FileQoSOptions { - ExceptionsAllowedBeforeBreaking = 1, + ExceptionsAllowedBeforeBreaking = 1, DurationOfBreak = 1, TimeoutValue = 1 } diff --git a/test/Ocelot.UnitTests/Configuration/RateLimitOptionsCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/RateLimitOptionsCreatorTests.cs index e77e3a62..75e9cfca 100644 --- a/test/Ocelot.UnitTests/Configuration/RateLimitOptionsCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/RateLimitOptionsCreatorTests.cs @@ -1,12 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Ocelot.Configuration; +using Ocelot.Configuration; using Ocelot.Configuration.Builder; using Ocelot.Configuration.Creator; using Ocelot.Configuration.File; using Shouldly; +using System; +using System.Collections.Generic; using TestStack.BDDfy; using Xunit; diff --git a/test/Ocelot.UnitTests/Configuration/ReRouteKeyCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/ReRouteKeyCreatorTests.cs index f1bb26d9..662f5adf 100644 --- a/test/Ocelot.UnitTests/Configuration/ReRouteKeyCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/ReRouteKeyCreatorTests.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic; -using System.Linq; using Ocelot.Configuration.Creator; using Ocelot.Configuration.File; using Ocelot.LoadBalancer.LoadBalancers; using Shouldly; +using System.Collections.Generic; +using System.Linq; using TestStack.BDDfy; using Xunit; @@ -44,7 +44,7 @@ namespace Ocelot.UnitTests.Configuration var reRoute = new FileReRoute { UpstreamPathTemplate = "/api/product", - UpstreamHttpMethod = new List {"GET", "POST", "PUT"}, + UpstreamHttpMethod = new List { "GET", "POST", "PUT" }, DownstreamHostAndPorts = new List { new FileHostAndPort @@ -80,6 +80,5 @@ namespace Ocelot.UnitTests.Configuration { _result.ShouldBe(expected); } - } } diff --git a/test/Ocelot.UnitTests/Configuration/ReRouteOptionsCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/ReRouteOptionsCreatorTests.cs index 8230d6f1..f5c97f71 100644 --- a/test/Ocelot.UnitTests/Configuration/ReRouteOptionsCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/ReRouteOptionsCreatorTests.cs @@ -1,11 +1,11 @@ namespace Ocelot.UnitTests.Configuration { - using System.Collections.Generic; using Ocelot.Configuration; using Ocelot.Configuration.Builder; using Ocelot.Configuration.Creator; using Ocelot.Configuration.File; using Shouldly; + using System.Collections.Generic; using TestStack.BDDfy; using Xunit; @@ -19,7 +19,7 @@ namespace Ocelot.UnitTests.Configuration { _creator = new ReRouteOptionsCreator(); } - + [Fact] public void should_create_re_route_options() { diff --git a/test/Ocelot.UnitTests/Configuration/ReRoutesCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/ReRoutesCreatorTests.cs index dbfcc71a..32c235aa 100644 --- a/test/Ocelot.UnitTests/Configuration/ReRoutesCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/ReRoutesCreatorTests.cs @@ -1,8 +1,5 @@ namespace Ocelot.UnitTests.Configuration { - using System; - using System.Collections.Generic; - using System.Linq; using Moq; using Ocelot.Cache; using Ocelot.Configuration; @@ -11,6 +8,8 @@ using Ocelot.Configuration.File; using Ocelot.Values; using Shouldly; + using System.Collections.Generic; + using System.Linq; using TestStack.BDDfy; using Xunit; @@ -31,7 +30,7 @@ private Mock _lboCreator; private Mock _rrkCreator; private Mock _soCreator; - private FileConfiguration _fileConfig; + private FileConfiguration _fileConfig; private ReRouteOptions _rro; private string _requestId; private string _rrk; diff --git a/test/Ocelot.UnitTests/Configuration/RequestIdKeyCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/RequestIdKeyCreatorTests.cs index dabdd55f..bf6ee6dc 100644 --- a/test/Ocelot.UnitTests/Configuration/RequestIdKeyCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/RequestIdKeyCreatorTests.cs @@ -56,7 +56,7 @@ namespace Ocelot.UnitTests.Configuration var reRoute = new FileReRoute { RequestIdKey = "cheese" - }; + }; var globalConfig = new FileGlobalConfiguration { RequestIdKey = "test" @@ -89,4 +89,4 @@ namespace Ocelot.UnitTests.Configuration _result.ShouldBe(expected); } } -} \ No newline at end of file +} diff --git a/test/Ocelot.UnitTests/Configuration/SecurityOptionsCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/SecurityOptionsCreatorTests.cs index 220dadcd..e79871eb 100644 --- a/test/Ocelot.UnitTests/Configuration/SecurityOptionsCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/SecurityOptionsCreatorTests.cs @@ -2,9 +2,7 @@ using Ocelot.Configuration.Creator; using Ocelot.Configuration.File; using Shouldly; -using System; using System.Collections.Generic; -using System.Text; using TestStack.BDDfy; using Xunit; @@ -49,7 +47,6 @@ namespace Ocelot.UnitTests.Configuration _fileReRoute = reRoute; } - private void WhenICreate() { _result = _creator.Create(_fileReRoute.SecurityOptions); @@ -67,6 +64,5 @@ namespace Ocelot.UnitTests.Configuration _result.IPBlockedList[i].ShouldBe(expected.IPBlockedList[i]); } } - } } diff --git a/test/Ocelot.UnitTests/Configuration/ServiceProviderCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/ServiceProviderCreatorTests.cs index 2094a172..1fbf4f79 100644 --- a/test/Ocelot.UnitTests/Configuration/ServiceProviderCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/ServiceProviderCreatorTests.cs @@ -31,7 +31,7 @@ namespace Ocelot.UnitTests.Configuration Type = "ServiceFabric", Token = "testtoken", ConfigurationKey = "woo", - Namespace ="default" + Namespace = "default" } }; @@ -48,7 +48,7 @@ namespace Ocelot.UnitTests.Configuration .When(x => x.WhenICreate()) .Then(x => x.ThenTheConfigIs(expected)) .BDDfy(); - } + } private void GivenTheFollowingGlobalConfig(FileGlobalConfiguration fileGlobalConfig) { diff --git a/test/Ocelot.UnitTests/Configuration/UpstreamTemplatePatternCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/UpstreamTemplatePatternCreatorTests.cs index 1aec3ec8..5d068496 100644 --- a/test/Ocelot.UnitTests/Configuration/UpstreamTemplatePatternCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/UpstreamTemplatePatternCreatorTests.cs @@ -101,11 +101,11 @@ namespace Ocelot.UnitTests.Configuration [Fact] public void should_set_upstream_template_pattern_to_respect_case_sensitivity() { - var fileReRoute = new FileReRoute - { - UpstreamPathTemplate = "/PRODUCTS/{productId}", - ReRouteIsCaseSensitive = true - }; + var fileReRoute = new FileReRoute + { + UpstreamPathTemplate = "/PRODUCTS/{productId}", + ReRouteIsCaseSensitive = true + }; this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute)) .When(x => x.WhenICreateTheTemplatePattern()) .Then(x => x.ThenTheFollowingIsReturned("^/PRODUCTS/.+$")) diff --git a/test/Ocelot.UnitTests/Configuration/Validation/FileConfigurationFluentValidatorTests.cs b/test/Ocelot.UnitTests/Configuration/Validation/FileConfigurationFluentValidatorTests.cs index a77d7c60..943001fc 100644 --- a/test/Ocelot.UnitTests/Configuration/Validation/FileConfigurationFluentValidatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/Validation/FileConfigurationFluentValidatorTests.cs @@ -1,25 +1,25 @@ namespace Ocelot.UnitTests.Configuration.Validation { - using System.Collections.Generic; - using System.Security.Claims; - using System.Text.Encodings.Web; - using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; + using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Moq; using Ocelot.Configuration.File; using Ocelot.Configuration.Validator; - using Ocelot.Responses; - using Shouldly; - using TestStack.BDDfy; - using Xunit; - using Microsoft.Extensions.DependencyInjection; using Ocelot.Requester; - using Requester; + using Ocelot.Responses; + using Ocelot.ServiceDiscovery; using Ocelot.ServiceDiscovery.Providers; using Ocelot.Values; - using Ocelot.ServiceDiscovery; + using Requester; + using Shouldly; + using System.Collections.Generic; + using System.Security.Claims; + using System.Text.Encodings.Web; + using System.Threading.Tasks; + using TestStack.BDDfy; + using Xunit; public class FileConfigurationFluentValidatorTests { @@ -126,7 +126,7 @@ .Then(x => x.ThenTheResultIsValid()) .BDDfy(); } - + [Fact] public void configuration_is_invalid_if_service_discovery_options_specified_but_no_service_discovery_handler() { @@ -300,7 +300,7 @@ .Then(x => x.ThenTheResultIsValid()) .BDDfy(); } - + [Fact] public void configuration_is_invalid_if_qos_options_specified_but_no_qos_handler() { @@ -1382,7 +1382,7 @@ private void GivenAQoSHandler() { var collection = new ServiceCollection(); - QosDelegatingHandlerDelegate del = (a,b) => new FakeDelegatingHandler(); + QosDelegatingHandlerDelegate del = (a, b) => new FakeDelegatingHandler(); collection.AddSingleton(del); var provider = collection.BuildServiceProvider(); _configurationValidator = new FileConfigurationFluentValidator(provider, new ReRouteFluentValidator(_authProvider.Object, new HostAndPortValidator(), new FileQoSOptionsFluentValidator(provider)), new FileGlobalConfigurationFluentValidator(new FileQoSOptionsFluentValidator(provider))); @@ -1391,7 +1391,7 @@ private void GivenAServiceDiscoveryHandler() { var collection = new ServiceCollection(); - ServiceDiscoveryFinderDelegate del = (a,b,c) => new FakeServiceDiscoveryProvider(); + ServiceDiscoveryFinderDelegate del = (a, b, c) => new FakeServiceDiscoveryProvider(); collection.AddSingleton(del); var provider = collection.BuildServiceProvider(); _configurationValidator = new FileConfigurationFluentValidator(provider, new ReRouteFluentValidator(_authProvider.Object, new HostAndPortValidator(), new FileQoSOptionsFluentValidator(provider)), new FileGlobalConfigurationFluentValidator(new FileQoSOptionsFluentValidator(provider))); diff --git a/test/Ocelot.UnitTests/Configuration/Validation/FileQoSOptionsFluentValidatorTests.cs b/test/Ocelot.UnitTests/Configuration/Validation/FileQoSOptionsFluentValidatorTests.cs index 234d37ba..64178767 100644 --- a/test/Ocelot.UnitTests/Configuration/Validation/FileQoSOptionsFluentValidatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/Validation/FileQoSOptionsFluentValidatorTests.cs @@ -1,7 +1,5 @@ -using System; using FluentValidation.Results; using Microsoft.Extensions.DependencyInjection; -using Moq; using Ocelot.Configuration.File; using Ocelot.Configuration.Validator; using Ocelot.Requester; @@ -64,7 +62,6 @@ namespace Ocelot.UnitTests.Configuration.Validation .Then(_ => ThenTheResultIsInValid()) .And(_ => ThenTheErrorIs()) .BDDfy(); - } private void ThenTheErrorIs() diff --git a/test/Ocelot.UnitTests/Configuration/Validation/HostAndPortValidatorTests.cs b/test/Ocelot.UnitTests/Configuration/Validation/HostAndPortValidatorTests.cs index 4d1c4731..6052c24f 100644 --- a/test/Ocelot.UnitTests/Configuration/Validation/HostAndPortValidatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/Validation/HostAndPortValidatorTests.cs @@ -1,4 +1,3 @@ -using System; using FluentValidation.Results; using Ocelot.Configuration.File; using Ocelot.Configuration.Validator; diff --git a/test/Ocelot.UnitTests/Configuration/Validation/ReRouteFluentValidatorTests.cs b/test/Ocelot.UnitTests/Configuration/Validation/ReRouteFluentValidatorTests.cs index 1b847d93..9433bb89 100644 --- a/test/Ocelot.UnitTests/Configuration/Validation/ReRouteFluentValidatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/Validation/ReRouteFluentValidatorTests.cs @@ -1,8 +1,5 @@ namespace Ocelot.UnitTests.Configuration.Validation { - using System; - using System.Collections.Generic; - using System.Threading.Tasks; using FluentValidation.Results; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Http; @@ -11,6 +8,9 @@ using Ocelot.Configuration.Validator; using Ocelot.Requester; using Shouldly; + using System; + using System.Collections.Generic; + using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; @@ -342,7 +342,7 @@ _result.Errors.ShouldContain(x => x.ErrorMessage == expected); } - class FakeAutheHandler : IAuthenticationHandler + private class FakeAutheHandler : IAuthenticationHandler { public Task InitializeAsync(AuthenticationScheme scheme, HttpContext context) { diff --git a/test/Ocelot.UnitTests/Consul/ConsulFileConfigurationRepositoryTests.cs b/test/Ocelot.UnitTests/Consul/ConsulFileConfigurationRepositoryTests.cs index 5b99742d..8a011026 100644 --- a/test/Ocelot.UnitTests/Consul/ConsulFileConfigurationRepositoryTests.cs +++ b/test/Ocelot.UnitTests/Consul/ConsulFileConfigurationRepositoryTests.cs @@ -1,10 +1,5 @@ namespace Ocelot.UnitTests.Consul { - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading; - using System.Threading.Tasks; using global::Consul; using Moq; using Newtonsoft.Json; @@ -17,6 +12,11 @@ using Provider.Consul; using Responses; using Shouldly; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using System.Threading; + using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; diff --git a/test/Ocelot.UnitTests/Consul/ConsulServiceDiscoveryProviderTests.cs b/test/Ocelot.UnitTests/Consul/ConsulServiceDiscoveryProviderTests.cs index 954b6fb1..8bc44b1f 100644 --- a/test/Ocelot.UnitTests/Consul/ConsulServiceDiscoveryProviderTests.cs +++ b/test/Ocelot.UnitTests/Consul/ConsulServiceDiscoveryProviderTests.cs @@ -1,9 +1,5 @@ namespace Ocelot.UnitTests.Consul { - using System; - using System.Collections.Generic; - using System.IO; - using System.Linq; using global::Consul; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; @@ -13,6 +9,10 @@ using Ocelot.Logging; using Provider.Consul; using Shouldly; + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; using TestStack.BDDfy; using Values; using Xunit; diff --git a/test/Ocelot.UnitTests/Consul/OcelotBuilderExtensionsTests.cs b/test/Ocelot.UnitTests/Consul/OcelotBuilderExtensionsTests.cs index 90a8d793..58a4f8a9 100644 --- a/test/Ocelot.UnitTests/Consul/OcelotBuilderExtensionsTests.cs +++ b/test/Ocelot.UnitTests/Consul/OcelotBuilderExtensionsTests.cs @@ -1,7 +1,5 @@ namespace Ocelot.UnitTests.Consul { - using System; - using System.Collections.Generic; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.Extensions.Configuration; @@ -9,6 +7,8 @@ using Ocelot.DependencyInjection; using Provider.Consul; using Shouldly; + using System; + using System.Collections.Generic; using TestStack.BDDfy; using Xunit; diff --git a/test/Ocelot.UnitTests/Consul/PollingConsulServiceDiscoveryProviderTests.cs b/test/Ocelot.UnitTests/Consul/PollingConsulServiceDiscoveryProviderTests.cs index 32b325ec..ab77d7d0 100644 --- a/test/Ocelot.UnitTests/Consul/PollingConsulServiceDiscoveryProviderTests.cs +++ b/test/Ocelot.UnitTests/Consul/PollingConsulServiceDiscoveryProviderTests.cs @@ -1,13 +1,13 @@ namespace Ocelot.UnitTests.Consul { - using System; - using System.Collections.Generic; using Moq; using Ocelot.Infrastructure; using Ocelot.Logging; using Ocelot.ServiceDiscovery.Providers; using Provider.Consul; using Shouldly; + using System; + using System.Collections.Generic; using TestStack.BDDfy; using Values; using Xunit; @@ -58,7 +58,8 @@ { _provider = new PollConsul(_delay, _factory.Object, _consulServiceDiscoveryProvider.Object); - var result = Wait.WaitFor(3000).Until(() => { + var result = Wait.WaitFor(3000).Until(() => + { try { _result = _provider.Get().GetAwaiter().GetResult(); diff --git a/test/Ocelot.UnitTests/Consul/ProviderFactoryTests.cs b/test/Ocelot.UnitTests/Consul/ProviderFactoryTests.cs index 995eb638..3aeb0751 100644 --- a/test/Ocelot.UnitTests/Consul/ProviderFactoryTests.cs +++ b/test/Ocelot.UnitTests/Consul/ProviderFactoryTests.cs @@ -1,12 +1,12 @@ namespace Ocelot.UnitTests.Consul { - using System; using Microsoft.Extensions.DependencyInjection; using Moq; using Ocelot.Configuration; using Ocelot.Logging; using Provider.Consul; using Shouldly; + using System; using Xunit; public class ProviderFactoryTests diff --git a/test/Ocelot.UnitTests/Controllers/FileConfigurationControllerTests.cs b/test/Ocelot.UnitTests/Controllers/FileConfigurationControllerTests.cs index 9a42dba9..fbf1cae2 100644 --- a/test/Ocelot.UnitTests/Controllers/FileConfigurationControllerTests.cs +++ b/test/Ocelot.UnitTests/Controllers/FileConfigurationControllerTests.cs @@ -1,14 +1,14 @@ -using System; using Microsoft.AspNetCore.Mvc; using Moq; +using Ocelot.Configuration; using Ocelot.Configuration.File; using Ocelot.Configuration.Setter; using Ocelot.Errors; using Ocelot.Responses; +using Shouldly; +using System; using TestStack.BDDfy; using Xunit; -using Shouldly; -using Ocelot.Configuration; namespace Ocelot.UnitTests.Controllers { @@ -29,8 +29,8 @@ namespace Ocelot.UnitTests.Controllers _repo = new Mock(); _setter = new Mock(); _controller = new FileConfigurationController(_repo.Object, _setter.Object, _provider.Object); - } - + } + [Fact] public void should_get_file_configuration() { @@ -45,15 +45,15 @@ namespace Ocelot.UnitTests.Controllers [Fact] public void should_return_error_when_cannot_get_config() { - var expected = new Responses.ErrorResponse(It.IsAny()); - - this.Given(x => x.GivenTheGetConfigurationReturns(expected)) - .When(x => x.WhenIGetTheFileConfiguration()) - .Then(x => x.TheTheGetFileConfigurationIsCalledCorrectly()) - .And(x => x.ThenTheResponseIs()) - .BDDfy(); - } - + var expected = new Responses.ErrorResponse(It.IsAny()); + + this.Given(x => x.GivenTheGetConfigurationReturns(expected)) + .When(x => x.WhenIGetTheFileConfiguration()) + .Then(x => x.TheTheGetFileConfigurationIsCalledCorrectly()) + .And(x => x.ThenTheResponseIs()) + .BDDfy(); + } + [Fact] public void should_post_file_configuration() { @@ -103,8 +103,8 @@ namespace Ocelot.UnitTests.Controllers } private void ThenTheResponseIs() - { - _result.ShouldBeOfType(); + { + _result.ShouldBeOfType(); } private void GivenTheGetConfigurationReturns(Ocelot.Responses.Response fileConfiguration) @@ -120,16 +120,16 @@ namespace Ocelot.UnitTests.Controllers } private void TheTheGetFileConfigurationIsCalledCorrectly() - { - _repo - .Verify(x => x.Get(), Times.Once); + { + _repo + .Verify(x => x.Get(), Times.Once); } - class FakeError : Error + private class FakeError : Error { public FakeError() : base(string.Empty, OcelotErrorCode.CannotAddDataError) { } } } -} +} diff --git a/test/Ocelot.UnitTests/Controllers/OutputCacheControllerTests.cs b/test/Ocelot.UnitTests/Controllers/OutputCacheControllerTests.cs index 7b4da861..5f44797f 100644 --- a/test/Ocelot.UnitTests/Controllers/OutputCacheControllerTests.cs +++ b/test/Ocelot.UnitTests/Controllers/OutputCacheControllerTests.cs @@ -1,12 +1,9 @@ -using Xunit; +using Microsoft.AspNetCore.Mvc; +using Moq; +using Ocelot.Cache; using Shouldly; using TestStack.BDDfy; -using Ocelot.Cache; -using System; -using Moq; -using System.Net.Http; -using System.Collections.Generic; -using Microsoft.AspNetCore.Mvc; +using Xunit; namespace Ocelot.UnitTests.Controllers { @@ -24,10 +21,10 @@ namespace Ocelot.UnitTests.Controllers [Fact] public void should_delete_key() - { - this.When(_ => WhenIDeleteTheKey("a")) - .Then(_ => ThenTheKeyIsDeleted("a")) - .BDDfy(); + { + this.When(_ => WhenIDeleteTheKey("a")) + .Then(_ => ThenTheKeyIsDeleted("a")) + .BDDfy(); } private void ThenTheKeyIsDeleted(string key) @@ -42,4 +39,4 @@ namespace Ocelot.UnitTests.Controllers _result = _controller.Delete(key); } } -} \ No newline at end of file +} diff --git a/test/Ocelot.UnitTests/DependencyInjection/ConfigurationBuilderExtensionsTests.cs b/test/Ocelot.UnitTests/DependencyInjection/ConfigurationBuilderExtensionsTests.cs index 465c9173..efb8ff9a 100644 --- a/test/Ocelot.UnitTests/DependencyInjection/ConfigurationBuilderExtensionsTests.cs +++ b/test/Ocelot.UnitTests/DependencyInjection/ConfigurationBuilderExtensionsTests.cs @@ -1,16 +1,16 @@ namespace Ocelot.UnitTests.DependencyInjection { - using System.Collections.Generic; - using System.IO; + using Microsoft.AspNetCore.Hosting; + using Microsoft.Extensions.Configuration; + using Moq; using Newtonsoft.Json; using Ocelot.Configuration.File; - using Microsoft.Extensions.Configuration; using Ocelot.DependencyInjection; using Shouldly; + using System.Collections.Generic; + using System.IO; using TestStack.BDDfy; using Xunit; - using Moq; - using Microsoft.AspNetCore.Hosting; public class ConfigurationBuilderExtensionsTests { @@ -24,14 +24,13 @@ private FileConfiguration _envSpecific; private Mock _hostingEnvironment; - public ConfigurationBuilderExtensionsTests() { _hostingEnvironment = new Mock(); // Clean up config files before each test var subConfigFiles = new DirectoryInfo(".").GetFiles("ocelot.*.json"); - foreach(var config in subConfigFiles) + foreach (var config in subConfigFiles) { config.Delete(); } @@ -313,10 +312,10 @@ private void GivenTheBaseUrl(string baseUrl) { - #pragma warning disable CS0618 +#pragma warning disable CS0618 var builder = new ConfigurationBuilder() .AddOcelotBaseUrl(baseUrl); - #pragma warning restore CS0618 +#pragma warning restore CS0618 _configuration = builder.Build(); } diff --git a/test/Ocelot.UnitTests/DependencyInjection/OcelotBuilderTests.cs b/test/Ocelot.UnitTests/DependencyInjection/OcelotBuilderTests.cs index 6459daf9..e9f39cec 100644 --- a/test/Ocelot.UnitTests/DependencyInjection/OcelotBuilderTests.cs +++ b/test/Ocelot.UnitTests/DependencyInjection/OcelotBuilderTests.cs @@ -1,22 +1,22 @@ namespace Ocelot.UnitTests.DependencyInjection { - using System; - using System.Collections.Generic; - using System.Linq; - using System.Net.Http; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Ocelot.Configuration.Setter; using Ocelot.DependencyInjection; + using Ocelot.Middleware.Multiplexer; using Ocelot.Requester; using Ocelot.UnitTests.Requester; using Shouldly; + using System; + using System.Collections.Generic; + using System.Linq; + using System.Net.Http; using TestStack.BDDfy; using Xunit; using static Ocelot.UnitTests.Middleware.UserDefinedResponseAggregatorTests; - using Ocelot.Middleware.Multiplexer; public class OcelotBuilderTests { diff --git a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteCreatorTests.cs b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteCreatorTests.cs index 25667638..a3348627 100644 --- a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteCreatorTests.cs +++ b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteCreatorTests.cs @@ -1,19 +1,18 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder { - using System; using Moq; + using Ocelot.Configuration; using Ocelot.Configuration.Builder; using Ocelot.Configuration.Creator; using Ocelot.DownstreamRouteFinder; + using Ocelot.DownstreamRouteFinder.Finder; using Ocelot.LoadBalancer.LoadBalancers; using Responses; - using TestStack.BDDfy; - using Ocelot.DownstreamRouteFinder.Finder; - using Xunit; using Shouldly; - using Ocelot.Configuration; - using System.Net.Http; using System.Collections.Generic; + using System.Net.Http; + using TestStack.BDDfy; + using Xunit; public class DownstreamRouteCreatorTests { @@ -71,7 +70,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder .Build(); var reRoutes = new List { reRoute }; - + var configuration = new InternalConfiguration(reRoutes, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions); this.Given(_ => GivenTheConfiguration(configuration)) @@ -224,7 +223,6 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder _result.Data.ReRoute.DownstreamReRoute[0].QosOptions.ShouldBe(_qoSOptions); _result.Data.ReRoute.UpstreamTemplatePattern.ShouldNotBeNull(); _result.Data.ReRoute.DownstreamReRoute[0].UpstreamPathTemplate.ShouldNotBeNull(); - } private void ThenTheDownstreamPathIsForwardSlash() diff --git a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderMiddlewareTests.cs b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderMiddlewareTests.cs index 0dbdbc37..3b333258 100644 --- a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderMiddlewareTests.cs @@ -1,7 +1,5 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder { - using System.Collections.Generic; - using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Moq; using Ocelot.Configuration; @@ -11,13 +9,14 @@ using Ocelot.DownstreamRouteFinder.Middleware; using Ocelot.DownstreamRouteFinder.UrlMatcher; using Ocelot.Logging; - using Ocelot.Responses; - using Shouldly; - using TestStack.BDDfy; - using Xunit; - using Ocelot.Configuration.Repository; using Ocelot.Middleware; using Ocelot.Middleware.Multiplexer; + using Ocelot.Responses; + using Shouldly; + using System.Collections.Generic; + using System.Threading.Tasks; + using TestStack.BDDfy; + using Xunit; public class DownstreamRouteFinderMiddlewareTests { @@ -53,12 +52,12 @@ var downstreamReRoute = new DownstreamReRouteBuilder() .WithDownstreamPathTemplate("any old string") - .WithUpstreamHttpMethod(new List {"Get"}) + .WithUpstreamHttpMethod(new List { "Get" }) .Build(); this.Given(x => x.GivenTheDownStreamRouteFinderReturns( new DownstreamRoute( - new List(), + new List(), new ReRouteBuilder() .WithDownstreamReRoute(downstreamReRoute) .WithUpstreamHttpMethod(new List { "Get" }) diff --git a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs index 7a27833a..7419fe55 100644 --- a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs +++ b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using Moq; +using Moq; using Ocelot.Configuration; using Ocelot.Configuration.Builder; using Ocelot.DownstreamRouteFinder; @@ -8,6 +7,7 @@ using Ocelot.DownstreamRouteFinder.UrlMatcher; using Ocelot.Responses; using Ocelot.Values; using Shouldly; +using System.Collections.Generic; using TestStack.BDDfy; using Xunit; @@ -132,7 +132,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder var serviceProviderConfig = new ServiceProviderConfigurationBuilder().Build(); this.Given(x => x.GivenThereIsAnUpstreamUrlPath("matchInUrlMatcher/")) - .And(x =>x.GivenTheTemplateVariableAndNameFinderReturns( + .And(x => x.GivenTheTemplateVariableAndNameFinderReturns( new OkResponse>( new List()))) .And(x => x.GivenTheConfigurationIs(new List @@ -174,7 +174,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder var serviceProviderConfig = new ServiceProviderConfigurationBuilder().Build(); this.Given(x => x.GivenThereIsAnUpstreamUrlPath("matchInUrlMatcher")) - .And(x =>x.GivenTheTemplateVariableAndNameFinderReturns( + .And(x => x.GivenTheTemplateVariableAndNameFinderReturns( new OkResponse>( new List()))) .And(x => x.GivenTheConfigurationIs(new List @@ -303,7 +303,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder [Fact] public void should_not_return_route() - { + { var serviceProviderConfig = new ServiceProviderConfigurationBuilder().Build(); this.Given(x => x.GivenThereIsAnUpstreamUrlPath("dontMatchPath/")) @@ -317,7 +317,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder .Build()) .WithUpstreamHttpMethod(new List { "Get" }) .WithUpstreamPathTemplate(new UpstreamPathTemplate("somePath", 1, false, "someUpstreamPath")) - .Build(), + .Build(), }, string.Empty, serviceProviderConfig )) .And(x => x.GivenTheUrlMatcherReturns(new OkResponse(new UrlMatch(false)))) @@ -762,7 +762,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder _result.Data.TemplatePlaceholderNameAndValues[i].Name.ShouldBe(expected.TemplatePlaceholderNameAndValues[i].Name); _result.Data.TemplatePlaceholderNameAndValues[i].Value.ShouldBe(expected.TemplatePlaceholderNameAndValues[i].Value); } - + _result.IsError.ShouldBeFalse(); } } diff --git a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteProviderFactoryTests.cs b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteProviderFactoryTests.cs index 6b00c280..437033f7 100644 --- a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteProviderFactoryTests.cs +++ b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteProviderFactoryTests.cs @@ -1,17 +1,17 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder { - using System.Collections.Generic; using Microsoft.Extensions.DependencyInjection; using Moq; using Ocelot.Configuration; using Ocelot.Configuration.Builder; + using Ocelot.Configuration.Creator; using Ocelot.DownstreamRouteFinder.Finder; using Ocelot.DownstreamRouteFinder.UrlMatcher; + using Ocelot.Logging; using Shouldly; + using System.Collections.Generic; using TestStack.BDDfy; using Xunit; - using Ocelot.Configuration.Creator; - using Ocelot.Logging; public class DownstreamRouteProviderFactoryTests { diff --git a/test/Ocelot.UnitTests/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinderTests.cs b/test/Ocelot.UnitTests/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinderTests.cs index 46d6e503..ac911baf 100644 --- a/test/Ocelot.UnitTests/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinderTests.cs +++ b/test/Ocelot.UnitTests/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinderTests.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; -using System.Linq; using Ocelot.DownstreamRouteFinder.UrlMatcher; using Ocelot.Responses; using Shouldly; +using System.Collections.Generic; +using System.Linq; using TestStack.BDDfy; using Xunit; namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher { - public class UrlPathPlaceholderNameAndValueFinderTests + public class UrlPathPlaceholderNameAndValueFinderTests { private readonly IPlaceholderNameAndValueFinder _finder; private string _downstreamUrlPath; @@ -34,7 +34,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher [Fact] public void can_match_down_stream_url_with_nothing_then_placeholder_no_value_is_blank() { - var expectedTemplates = new List + var expectedTemplates = new List { new PlaceholderNameAndValue("{url}", "") }; @@ -49,7 +49,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher [Fact] public void can_match_down_stream_url_with_nothing_then_placeholder_value_is_test() { - var expectedTemplates = new List + var expectedTemplates = new List { new PlaceholderNameAndValue("{url}", "test") }; @@ -64,7 +64,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher [Fact] public void should_match_everything_in_path_with_query() { - var expectedTemplates = new List + var expectedTemplates = new List { new PlaceholderNameAndValue("{everything}", "test/toot") }; @@ -80,7 +80,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher [Fact] public void should_match_everything_in_path() { - var expectedTemplates = new List + var expectedTemplates = new List { new PlaceholderNameAndValue("{everything}", "test/toot") }; @@ -95,7 +95,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher [Fact] public void can_match_down_stream_url_with_forward_slash_then_placeholder_no_value_is_blank() { - var expectedTemplates = new List + var expectedTemplates = new List { new PlaceholderNameAndValue("{url}", "") }; @@ -110,7 +110,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher [Fact] public void can_match_down_stream_url_with_forward_slash() { - var expectedTemplates = new List + var expectedTemplates = new List { }; @@ -124,7 +124,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher [Fact] public void can_match_down_stream_url_with_forward_slash_then_placeholder_then_another_value() { - var expectedTemplates = new List + var expectedTemplates = new List { new PlaceholderNameAndValue("{url}", "1") }; @@ -264,7 +264,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher [Fact] public void can_match_down_stream_url_with_downstream_template_with_one_place_holder() { - var expectedTemplates = new List + var expectedTemplates = new List { new PlaceholderNameAndValue("{productId}", "1") }; @@ -279,7 +279,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher [Fact] public void can_match_down_stream_url_with_downstream_template_with_two_place_holders() { - var expectedTemplates = new List + var expectedTemplates = new List { new PlaceholderNameAndValue("{productId}", "1"), new PlaceholderNameAndValue("{categoryId}", "2") @@ -295,7 +295,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher [Fact] public void can_match_down_stream_url_with_downstream_template_with_two_place_holders_seperated_by_something() { - var expectedTemplates = new List + var expectedTemplates = new List { new PlaceholderNameAndValue("{productId}", "1"), new PlaceholderNameAndValue("{categoryId}", "2") @@ -311,7 +311,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher [Fact] public void can_match_down_stream_url_with_downstream_template_with_three_place_holders_seperated_by_something() { - var expectedTemplates = new List + var expectedTemplates = new List { new PlaceholderNameAndValue("{productId}", "1"), new PlaceholderNameAndValue("{categoryId}", "2"), @@ -328,7 +328,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher [Fact] public void can_match_down_stream_url_with_downstream_template_with_three_place_holders() { - var expectedTemplates = new List + var expectedTemplates = new List { new PlaceholderNameAndValue("{productId}", "1"), new PlaceholderNameAndValue("{categoryId}", "2") @@ -385,4 +385,4 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher _query = query; } } -} +} diff --git a/test/Ocelot.UnitTests/DownstreamUrlCreator/DownstreamUrlCreatorMiddlewareTests.cs b/test/Ocelot.UnitTests/DownstreamUrlCreator/DownstreamUrlCreatorMiddlewareTests.cs index 612ee534..ffd52b08 100644 --- a/test/Ocelot.UnitTests/DownstreamUrlCreator/DownstreamUrlCreatorMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/DownstreamUrlCreator/DownstreamUrlCreatorMiddlewareTests.cs @@ -1,25 +1,25 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator { - using System; - using System.Collections.Generic; - using System.Net.Http; - using System.Threading.Tasks; + using Microsoft.AspNetCore.Http; using Moq; + using Ocelot.Configuration; using Ocelot.Configuration.Builder; using Ocelot.DownstreamRouteFinder; using Ocelot.DownstreamRouteFinder.UrlMatcher; using Ocelot.DownstreamUrlCreator.Middleware; using Ocelot.DownstreamUrlCreator.UrlTemplateReplacer; using Ocelot.Logging; + using Ocelot.Middleware; + using Ocelot.Request.Middleware; using Ocelot.Responses; using Ocelot.Values; + using Shouldly; + using System; + using System.Collections.Generic; + using System.Net.Http; + using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; - using Shouldly; - using Microsoft.AspNetCore.Http; - using Ocelot.Request.Middleware; - using Ocelot.Configuration; - using Ocelot.Middleware; public class DownstreamUrlCreatorMiddlewareTests { @@ -49,7 +49,7 @@ { var downstreamReRoute = new DownstreamReRouteBuilder() .WithDownstreamPathTemplate("any old string") - .WithUpstreamHttpMethod(new List {"Get"}) + .WithUpstreamHttpMethod(new List { "Get" }) .WithDownstreamScheme("https") .Build(); @@ -58,7 +58,7 @@ this.Given(x => x.GivenTheDownStreamRouteIs( new DownstreamRoute( - new List(), + new List(), new ReRouteBuilder() .WithDownstreamReRoute(downstreamReRoute) .WithUpstreamHttpMethod(new List { "Get" }) @@ -307,7 +307,7 @@ .WithHost("localhost") .WithPort(19081) .Build(); - + this.Given(x => x.GivenTheDownStreamRouteIs(downstreamRoute)) .And(x => GivenTheServiceProviderConfigIs(config)) .And(x => x.GivenTheDownstreamRequestUriIs("http://localhost:19081?PartitionKind=test&PartitionKey=1")) @@ -350,8 +350,6 @@ .BDDfy(); } - - private void GivenTheServiceProviderConfigIs(ServiceProviderConfiguration config) { var configuration = new InternalConfiguration(null, null, config, null, null, null, null, null); @@ -386,6 +384,7 @@ setup.Returns(response); } } + private void GivenTheUrlReplacerWillReturn(string path) { _downstreamPath = new OkResponse(new DownstreamPath(path)); diff --git a/test/Ocelot.UnitTests/DownstreamUrlCreator/UrlTemplateReplacer/UpstreamUrlPathTemplateVariableReplacerTests.cs b/test/Ocelot.UnitTests/DownstreamUrlCreator/UrlTemplateReplacer/UpstreamUrlPathTemplateVariableReplacerTests.cs index a82f2c53..1c27898a 100644 --- a/test/Ocelot.UnitTests/DownstreamUrlCreator/UrlTemplateReplacer/UpstreamUrlPathTemplateVariableReplacerTests.cs +++ b/test/Ocelot.UnitTests/DownstreamUrlCreator/UrlTemplateReplacer/UpstreamUrlPathTemplateVariableReplacerTests.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using Ocelot.Configuration.Builder; using Ocelot.DownstreamRouteFinder; using Ocelot.DownstreamRouteFinder.UrlMatcher; @@ -6,6 +5,7 @@ using Ocelot.DownstreamUrlCreator.UrlTemplateReplacer; using Ocelot.Responses; using Ocelot.Values; using Shouldly; +using System.Collections.Generic; using TestStack.BDDfy; using Xunit; @@ -27,7 +27,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer { this.Given(x => x.GivenThereIsAUrlMatch( new DownstreamRoute( - new List(), + new List(), new ReRouteBuilder() .WithDownstreamReRoute(new DownstreamReRouteBuilder() .WithUpstreamHttpMethod(new List { "Get" }) @@ -44,7 +44,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer { this.Given(x => x.GivenThereIsAUrlMatch( new DownstreamRoute( - new List(), + new List(), new ReRouteBuilder() .WithDownstreamReRoute(new DownstreamReRouteBuilder() .WithDownstreamPathTemplate("/") @@ -60,7 +60,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer [Fact] public void can_replace_url_no_slash() { - this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(new List(), + this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(new List(), new ReRouteBuilder() .WithDownstreamReRoute(new DownstreamReRouteBuilder() .WithDownstreamPathTemplate("api") @@ -76,7 +76,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer [Fact] public void can_replace_url_one_slash() { - this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(new List(), + this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(new List(), new ReRouteBuilder() .WithDownstreamReRoute(new DownstreamReRouteBuilder() .WithDownstreamPathTemplate("api/") @@ -92,7 +92,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer [Fact] public void can_replace_url_multiple_slash() { - this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(new List(), + this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(new List(), new ReRouteBuilder() .WithDownstreamReRoute(new DownstreamReRouteBuilder() .WithDownstreamPathTemplate("api/product/products/") @@ -113,7 +113,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer new PlaceholderNameAndValue("{productId}", "1") }; - this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(templateVariables, + this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(templateVariables, new ReRouteBuilder() .WithDownstreamReRoute(new DownstreamReRouteBuilder() .WithDownstreamPathTemplate("productservice/products/{productId}/") @@ -134,7 +134,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer new PlaceholderNameAndValue("{productId}", "1") }; - this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(templateVariables, + this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(templateVariables, new ReRouteBuilder() .WithDownstreamReRoute(new DownstreamReRouteBuilder() .WithDownstreamPathTemplate("productservice/products/{productId}/variants") @@ -156,7 +156,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer new PlaceholderNameAndValue("{variantId}", "12") }; - this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(templateVariables, + this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(templateVariables, new ReRouteBuilder() .WithDownstreamReRoute(new DownstreamReRouteBuilder() .WithDownstreamPathTemplate("productservice/products/{productId}/variants/{variantId}") @@ -167,9 +167,9 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer .When(x => x.WhenIReplaceTheTemplateVariables()) .Then(x => x.ThenTheDownstreamUrlPathIsReturned("productservice/products/1/variants/12")) .BDDfy(); - } - - [Fact] + } + + [Fact] public void can_replace_url_three_template_variable() { var templateVariables = new List() @@ -179,7 +179,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer new PlaceholderNameAndValue("{categoryId}", "34") }; - this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(templateVariables, + this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(templateVariables, new ReRouteBuilder() .WithDownstreamReRoute(new DownstreamReRouteBuilder() .WithDownstreamPathTemplate("productservice/category/{categoryId}/products/{productId}/variants/{variantId}") @@ -207,4 +207,4 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer _result.Data.Value.ShouldBe(expected); } } -} +} diff --git a/test/Ocelot.UnitTests/Errors/ErrorTests.cs b/test/Ocelot.UnitTests/Errors/ErrorTests.cs index 010ffd26..c1b92f8f 100644 --- a/test/Ocelot.UnitTests/Errors/ErrorTests.cs +++ b/test/Ocelot.UnitTests/Errors/ErrorTests.cs @@ -1,4 +1,3 @@ -using Ocelot.Errors; using Ocelot.Infrastructure.RequestData; using Shouldly; using Xunit; @@ -15,4 +14,4 @@ namespace Ocelot.UnitTests.Errors result.ShouldBe("message"); } } -} \ No newline at end of file +} diff --git a/test/Ocelot.UnitTests/Errors/ExceptionHandlerMiddlewareTests.cs b/test/Ocelot.UnitTests/Errors/ExceptionHandlerMiddlewareTests.cs index 0ca0b659..3d86505e 100644 --- a/test/Ocelot.UnitTests/Errors/ExceptionHandlerMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Errors/ExceptionHandlerMiddlewareTests.cs @@ -1,24 +1,24 @@ namespace Ocelot.UnitTests.Errors { - using System; - using System.Net; - using System.Threading.Tasks; - using Ocelot.Errors.Middleware; - using Ocelot.Logging; - using Shouldly; - using TestStack.BDDfy; - using Xunit; using Microsoft.AspNetCore.Http; using Moq; using Ocelot.Configuration; - using Ocelot.Errors; - using Ocelot.Infrastructure.RequestData; - using Ocelot.Middleware; using Ocelot.Configuration.Repository; + using Ocelot.Errors; + using Ocelot.Errors.Middleware; + using Ocelot.Infrastructure.RequestData; + using Ocelot.Logging; + using Ocelot.Middleware; + using Shouldly; + using System; + using System.Net; + using System.Threading.Tasks; + using TestStack.BDDfy; + using Xunit; public class ExceptionHandlerMiddlewareTests { - bool _shouldThrowAnException; + private bool _shouldThrowAnException; private readonly Mock _configRepo; private readonly Mock _repo; private Mock _loggerFactory; @@ -35,7 +35,8 @@ namespace Ocelot.UnitTests.Errors _loggerFactory = new Mock(); _logger = new Mock(); _loggerFactory.Setup(x => x.CreateLogger()).Returns(_logger.Object); - _next = async context => { + _next = async context => + { await Task.CompletedTask; if (_shouldThrowAnException) @@ -47,7 +48,7 @@ namespace Ocelot.UnitTests.Errors }; _middleware = new ExceptionHandlerMiddleware(_next, _loggerFactory.Object, _configRepo.Object, _repo.Object); } - + [Fact] public void NoDownstreamException() { @@ -102,21 +103,21 @@ namespace Ocelot.UnitTests.Errors [Fact] public void should_throw_exception_if_config_provider_returns_error() { - this.Given(_ => GivenAnExceptionWillNotBeThrownDownstream()) - .And(_ => GivenTheConfigReturnsError()) - .When(_ => WhenICallTheMiddlewareWithTheRequestIdKey("requestidkey", "1234")) - .Then(_ => ThenAnExceptionIsThrown()) - .BDDfy(); + this.Given(_ => GivenAnExceptionWillNotBeThrownDownstream()) + .And(_ => GivenTheConfigReturnsError()) + .When(_ => WhenICallTheMiddlewareWithTheRequestIdKey("requestidkey", "1234")) + .Then(_ => ThenAnExceptionIsThrown()) + .BDDfy(); } [Fact] public void should_throw_exception_if_config_provider_throws() { - this.Given(_ => GivenAnExceptionWillNotBeThrownDownstream()) - .And(_ => GivenTheConfigThrows()) - .When(_ => WhenICallTheMiddlewareWithTheRequestIdKey("requestidkey", "1234")) - .Then(_ => ThenAnExceptionIsThrown()) - .BDDfy(); + this.Given(_ => GivenAnExceptionWillNotBeThrownDownstream()) + .And(_ => GivenTheConfigThrows()) + .When(_ => WhenICallTheMiddlewareWithTheRequestIdKey("requestidkey", "1234")) + .Then(_ => ThenAnExceptionIsThrown()) + .BDDfy(); } private void WhenICallTheMiddlewareWithTheRequestIdKey(string key, string value) @@ -133,8 +134,8 @@ namespace Ocelot.UnitTests.Errors private void GivenTheConfigThrows() { var ex = new Exception("outer", new Exception("inner")); - _configRepo - .Setup(x => x.Get()).Throws(ex); + _configRepo + .Setup(x => x.Get()).Throws(ex); } private void ThenAnExceptionIsThrown() @@ -186,7 +187,7 @@ namespace Ocelot.UnitTests.Errors _repo.Verify(x => x.Add(It.IsAny(), It.IsAny()), Times.Once); } - class FakeError : Error + private class FakeError : Error { internal FakeError() : base("meh", OcelotErrorCode.CannotAddDataError) diff --git a/test/Ocelot.UnitTests/Eureka/EurekaMiddlewareConfigurationProviderTests.cs b/test/Ocelot.UnitTests/Eureka/EurekaMiddlewareConfigurationProviderTests.cs index 3fb6bb7c..3f1a6da0 100644 --- a/test/Ocelot.UnitTests/Eureka/EurekaMiddlewareConfigurationProviderTests.cs +++ b/test/Ocelot.UnitTests/Eureka/EurekaMiddlewareConfigurationProviderTests.cs @@ -1,6 +1,5 @@ namespace Ocelot.UnitTests.Eureka { - using System.Threading.Tasks; using Microsoft.AspNetCore.Builder.Internal; using Microsoft.Extensions.DependencyInjection; using Moq; @@ -11,6 +10,7 @@ using Responses; using Shouldly; using Steeltoe.Common.Discovery; + using System.Threading.Tasks; using Xunit; public class EurekaMiddlewareConfigurationProviderTests diff --git a/test/Ocelot.UnitTests/Eureka/EurekaServiceDiscoveryProviderTests.cs b/test/Ocelot.UnitTests/Eureka/EurekaServiceDiscoveryProviderTests.cs index ea5c77f8..ec332605 100644 --- a/test/Ocelot.UnitTests/Eureka/EurekaServiceDiscoveryProviderTests.cs +++ b/test/Ocelot.UnitTests/Eureka/EurekaServiceDiscoveryProviderTests.cs @@ -1,12 +1,12 @@ namespace Ocelot.UnitTests.Eureka { - using System; - using System.Collections.Generic; - using System.Threading.Tasks; using Moq; using Provider.Eureka; using Shouldly; using Steeltoe.Common.Discovery; + using System; + using System.Collections.Generic; + using System.Threading.Tasks; using TestStack.BDDfy; using Values; using Xunit; diff --git a/test/Ocelot.UnitTests/Headers/AddHeadersToRequestClaimToThingTests.cs b/test/Ocelot.UnitTests/Headers/AddHeadersToRequestClaimToThingTests.cs index 05e6ab2c..392712c3 100644 --- a/test/Ocelot.UnitTests/Headers/AddHeadersToRequestClaimToThingTests.cs +++ b/test/Ocelot.UnitTests/Headers/AddHeadersToRequestClaimToThingTests.cs @@ -1,17 +1,17 @@ -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using Moq; +using Moq; using Ocelot.Configuration; using Ocelot.Errors; using Ocelot.Headers; using Ocelot.Infrastructure.Claims.Parser; +using Ocelot.Request.Middleware; using Ocelot.Responses; using Shouldly; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Security.Claims; using TestStack.BDDfy; using Xunit; -using System.Net.Http; -using Ocelot.Request.Middleware; namespace Ocelot.UnitTests.Headers { @@ -97,7 +97,7 @@ namespace Ocelot.UnitTests.Headers .Then(x => x.ThenTheResultIsError()) .BDDfy(); } - + private void GivenClaims(List claims) { _claims = claims; @@ -119,8 +119,8 @@ namespace Ocelot.UnitTests.Headers _parser .Setup( x => - x.GetValue(It.IsAny>(), - It.IsAny(), + x.GetValue(It.IsAny>(), + It.IsAny(), It.IsAny(), It.IsAny())) .Returns(_claimValue); @@ -147,9 +147,9 @@ namespace Ocelot.UnitTests.Headers header.Value.First().ShouldBe(_claimValue.Data); } - class AnyError : Error + private class AnyError : Error { - public AnyError() + public AnyError() : base("blahh", OcelotErrorCode.UnknownError) { } diff --git a/test/Ocelot.UnitTests/Headers/AddHeadersToRequestPlainTests.cs b/test/Ocelot.UnitTests/Headers/AddHeadersToRequestPlainTests.cs index c2b4189d..cc2916a2 100644 --- a/test/Ocelot.UnitTests/Headers/AddHeadersToRequestPlainTests.cs +++ b/test/Ocelot.UnitTests/Headers/AddHeadersToRequestPlainTests.cs @@ -1,12 +1,12 @@ namespace Ocelot.UnitTests.Headers { - using Ocelot.Infrastructure; - using Ocelot.Logging; using Microsoft.AspNetCore.Http; using Moq; using Ocelot.Configuration.Creator; using Ocelot.Headers; + using Ocelot.Infrastructure; using Ocelot.Infrastructure.Claims.Parser; + using Ocelot.Logging; using Responder; using Responses; using Shouldly; @@ -76,7 +76,6 @@ _logger.Verify(x => x.LogWarning($"Unable to add header to response {key}: {value}"), Times.Once); } - private void GivenHttpRequestWithoutHeaders() { _context = new DefaultHttpContext @@ -109,7 +108,7 @@ _addedHeader = new AddHeader(headerKey, headerValue); _addHeadersToRequest.SetHeadersOnDownstreamRequest(new[] { _addedHeader }, _context); } - + private void ThenTheHeaderGetsTakenOverToTheRequestHeaders() { var requestHeaders = _context.Request.Headers; diff --git a/test/Ocelot.UnitTests/Headers/AddHeadersToResponseTests.cs b/test/Ocelot.UnitTests/Headers/AddHeadersToResponseTests.cs index 9c668dd1..d9c6bfa4 100644 --- a/test/Ocelot.UnitTests/Headers/AddHeadersToResponseTests.cs +++ b/test/Ocelot.UnitTests/Headers/AddHeadersToResponseTests.cs @@ -1,18 +1,17 @@ -using Xunit; -using TestStack.BDDfy; -using Ocelot.Headers; -using System.Net.Http; -using System.Collections.Generic; -using System.Linq; -using Ocelot.Configuration.Creator; using Moq; -using Ocelot.Responses; +using Ocelot.Configuration.Creator; +using Ocelot.Headers; using Ocelot.Infrastructure; -using Ocelot.UnitTests.Responder; using Ocelot.Logging; using Ocelot.Middleware; -using Ocelot.Middleware.Multiplexer; +using Ocelot.Responses; +using Ocelot.UnitTests.Responder; using Shouldly; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using TestStack.BDDfy; +using Xunit; namespace Ocelot.UnitTests.Headers { @@ -56,9 +55,9 @@ namespace Ocelot.UnitTests.Headers { new AddHeader("Trace-Id", "{TraceId}") }; - - var traceId = "123"; - + + var traceId = "123"; + this.Given(_ => GivenAResponseMessage()) .And(_ => GivenTheTraceIdIs(traceId)) .And(_ => GivenTheAddHeaders(addHeaders)) @@ -94,7 +93,7 @@ namespace Ocelot.UnitTests.Headers { new AddHeader("Trace-Id", "{TraceId}") }; - + this.Given(_ => GivenAResponseMessage()) .And(_ => GivenTheTraceIdErrors()) .And(_ => GivenTheAddHeaders(addHeaders)) diff --git a/test/Ocelot.UnitTests/Headers/ClaimsToHeadersMiddlewareTests.cs b/test/Ocelot.UnitTests/Headers/ClaimsToHeadersMiddlewareTests.cs index 6931f15d..20ec9b70 100644 --- a/test/Ocelot.UnitTests/Headers/ClaimsToHeadersMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Headers/ClaimsToHeadersMiddlewareTests.cs @@ -2,9 +2,6 @@ namespace Ocelot.UnitTests.Headers { - using System.Collections.Generic; - using System.Net.Http; - using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Moq; using Ocelot.Configuration; @@ -16,6 +13,9 @@ namespace Ocelot.UnitTests.Headers using Ocelot.Logging; using Ocelot.Request.Middleware; using Ocelot.Responses; + using System.Collections.Generic; + using System.Net.Http; + using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; @@ -91,7 +91,7 @@ namespace Ocelot.UnitTests.Headers _addHeaders .Verify(x => x.SetHeadersOnDownstreamRequest( It.IsAny>(), - It.IsAny>(), + It.IsAny>(), _downstreamContext.DownstreamRequest), Times.Once); } } diff --git a/test/Ocelot.UnitTests/Headers/HttpContextRequestHeaderReplacerTests.cs b/test/Ocelot.UnitTests/Headers/HttpContextRequestHeaderReplacerTests.cs index 25367816..e3ff5050 100644 --- a/test/Ocelot.UnitTests/Headers/HttpContextRequestHeaderReplacerTests.cs +++ b/test/Ocelot.UnitTests/Headers/HttpContextRequestHeaderReplacerTests.cs @@ -1,12 +1,11 @@ -using Xunit; -using Shouldly; -using Ocelot.Headers.Middleware; -using TestStack.BDDfy; using Microsoft.AspNetCore.Http; -using System.Collections.Generic; -using Ocelot.Responses; using Ocelot.Configuration; using Ocelot.Headers; +using Ocelot.Responses; +using Shouldly; +using System.Collections.Generic; +using TestStack.BDDfy; +using Xunit; namespace Ocelot.UnitTests.Headers { @@ -54,8 +53,8 @@ namespace Ocelot.UnitTests.Headers } private void ThenTheHeadersAreNotReplaced() - { - _result.ShouldBeOfType(); + { + _result.ShouldBeOfType(); foreach (var f in _fAndRs) { _context.Request.Headers.TryGetValue(f.Key, out var values); @@ -88,4 +87,4 @@ namespace Ocelot.UnitTests.Headers } } } -} \ No newline at end of file +} diff --git a/test/Ocelot.UnitTests/Headers/HttpHeadersTransformationMiddlewareTests.cs b/test/Ocelot.UnitTests/Headers/HttpHeadersTransformationMiddlewareTests.cs index 8cba2297..aa00cc34 100644 --- a/test/Ocelot.UnitTests/Headers/HttpHeadersTransformationMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Headers/HttpHeadersTransformationMiddlewareTests.cs @@ -1,22 +1,21 @@ namespace Ocelot.UnitTests.Headers { - using Xunit; - using Ocelot.Logging; - using Ocelot.Headers.Middleware; - using TestStack.BDDfy; using Microsoft.AspNetCore.Http; - using System.Collections.Generic; using Moq; - using Ocelot.Configuration; - using Ocelot.DownstreamRouteFinder; - using Ocelot.Configuration.Builder; - using Ocelot.Headers; - using System.Net.Http; using Ocelot.Authorisation.Middleware; + using Ocelot.Configuration; + using Ocelot.Configuration.Builder; + using Ocelot.DownstreamRouteFinder; + using Ocelot.Headers; + using Ocelot.Headers.Middleware; + using Ocelot.Logging; using Ocelot.Middleware; - using Ocelot.Middleware.Multiplexer; - using System.Threading.Tasks; using Ocelot.Request.Middleware; + using System.Collections.Generic; + using System.Net.Http; + using System.Threading.Tasks; + using TestStack.BDDfy; + using Xunit; public class HttpHeadersTransformationMiddlewareTests { @@ -117,4 +116,4 @@ namespace Ocelot.UnitTests.Headers _downstreamContext.HttpContext.Request.Headers.Add("test", "test"); } } -} +} diff --git a/test/Ocelot.UnitTests/Headers/HttpResponseHeaderReplacerTests.cs b/test/Ocelot.UnitTests/Headers/HttpResponseHeaderReplacerTests.cs index 4726c7ae..f21e9c23 100644 --- a/test/Ocelot.UnitTests/Headers/HttpResponseHeaderReplacerTests.cs +++ b/test/Ocelot.UnitTests/Headers/HttpResponseHeaderReplacerTests.cs @@ -1,21 +1,21 @@ namespace Ocelot.UnitTests.Headers { using Microsoft.AspNetCore.Http; - using Ocelot.Infrastructure; - using Ocelot.Middleware; - using Ocelot.Infrastructure.RequestData; - using Ocelot.Request.Middleware; - using Xunit; - using Shouldly; - using TestStack.BDDfy; - using System.Net.Http; - using Ocelot.Headers; + using Moq; using Ocelot.Configuration; - using System.Collections.Generic; + using Ocelot.Headers; + using Ocelot.Infrastructure; + using Ocelot.Infrastructure.RequestData; + using Ocelot.Middleware; + using Ocelot.Request.Middleware; using Ocelot.Responses; + using Shouldly; + using System.Collections.Generic; using System.Linq; using System.Net; - using Moq; + using System.Net.Http; + using TestStack.BDDfy; + using Xunit; public class HttpResponseHeaderReplacerTests { @@ -47,7 +47,7 @@ namespace Ocelot.UnitTests.Headers new KeyValuePair>("test", new List {"test"}) }, ""); - var fAndRs = new List {new HeaderFindAndReplace("test", "test", "chiken", 0)}; + var fAndRs = new List { new HeaderFindAndReplace("test", "test", "chiken", 0) }; this.Given(x => GivenTheHttpResponse(response)) .And(x => GivenTheFollowingHeaderReplacements(fAndRs)) @@ -80,7 +80,7 @@ namespace Ocelot.UnitTests.Headers const string downstreamUrl = "http://downstream.com/"; var request = - new HttpRequestMessage(HttpMethod.Get, "http://test.com") {RequestUri = new System.Uri(downstreamUrl)}; + new HttpRequestMessage(HttpMethod.Get, "http://test.com") { RequestUri = new System.Uri(downstreamUrl) }; var response = new DownstreamResponse(new StringContent(string.Empty), HttpStatusCode.Accepted, new List>>() @@ -107,7 +107,7 @@ namespace Ocelot.UnitTests.Headers const string downstreamUrl = "http://downstream.com/"; var request = - new HttpRequestMessage(HttpMethod.Get, "http://test.com") {RequestUri = new System.Uri(downstreamUrl)}; + new HttpRequestMessage(HttpMethod.Get, "http://test.com") { RequestUri = new System.Uri(downstreamUrl) }; var response = new DownstreamResponse(new StringContent(string.Empty), HttpStatusCode.Accepted, new List>>() @@ -134,7 +134,7 @@ namespace Ocelot.UnitTests.Headers const string downstreamUrl = "http://downstream.com/test/product"; var request = - new HttpRequestMessage(HttpMethod.Get, "http://test.com") {RequestUri = new System.Uri(downstreamUrl)}; + new HttpRequestMessage(HttpMethod.Get, "http://test.com") { RequestUri = new System.Uri(downstreamUrl) }; var response = new DownstreamResponse(new StringContent(string.Empty), HttpStatusCode.Accepted, new List>>() @@ -161,7 +161,7 @@ namespace Ocelot.UnitTests.Headers const string downstreamUrl = "http://downstream.com/test/product"; var request = - new HttpRequestMessage(HttpMethod.Get, "http://test.com") {RequestUri = new System.Uri(downstreamUrl)}; + new HttpRequestMessage(HttpMethod.Get, "http://test.com") { RequestUri = new System.Uri(downstreamUrl) }; var response = new DownstreamResponse(new StringContent(string.Empty), HttpStatusCode.Accepted, new List>>() @@ -188,7 +188,7 @@ namespace Ocelot.UnitTests.Headers const string downstreamUrl = "http://downstream.com:123/test/product"; var request = - new HttpRequestMessage(HttpMethod.Get, "http://test.com") {RequestUri = new System.Uri(downstreamUrl)}; + new HttpRequestMessage(HttpMethod.Get, "http://test.com") { RequestUri = new System.Uri(downstreamUrl) }; var response = new DownstreamResponse(new StringContent(string.Empty), HttpStatusCode.Accepted, new List>>() @@ -215,7 +215,7 @@ namespace Ocelot.UnitTests.Headers const string downstreamUrl = "http://downstream.com:123/test/product"; var request = - new HttpRequestMessage(HttpMethod.Get, "http://test.com") {RequestUri = new System.Uri(downstreamUrl)}; + new HttpRequestMessage(HttpMethod.Get, "http://test.com") { RequestUri = new System.Uri(downstreamUrl) }; var response = new DownstreamResponse(new StringContent(string.Empty), HttpStatusCode.Accepted, new List>>() @@ -243,7 +243,7 @@ namespace Ocelot.UnitTests.Headers private void ThenTheHeadersAreNotReplaced() { - _result.ShouldBeOfType(); + _result.ShouldBeOfType(); foreach (var f in _headerFindAndReplaces) { var values = _response.Headers.First(x => x.Key == f.Key); @@ -263,7 +263,7 @@ namespace Ocelot.UnitTests.Headers private void WhenICallTheReplacer() { - var context = new DownstreamContext(new DefaultHttpContext()) {DownstreamResponse = _response, DownstreamRequest = _request}; + var context = new DownstreamContext(new DefaultHttpContext()) { DownstreamResponse = _response, DownstreamRequest = _request }; _result = _replacer.Replace(context, _headerFindAndReplaces); } diff --git a/test/Ocelot.UnitTests/Headers/RemoveHeadersTests.cs b/test/Ocelot.UnitTests/Headers/RemoveHeadersTests.cs index 9818c944..e0aa4806 100644 --- a/test/Ocelot.UnitTests/Headers/RemoveHeadersTests.cs +++ b/test/Ocelot.UnitTests/Headers/RemoveHeadersTests.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; -using Ocelot.Middleware; +using Ocelot.Middleware; using Ocelot.Responses; using Shouldly; +using System.Collections.Generic; using TestStack.BDDfy; using Xunit; @@ -49,4 +49,4 @@ namespace Ocelot.UnitTests.Headers _headers.ShouldNotContain(x => x.Key == "transfer-encoding"); } } -} +} diff --git a/test/Ocelot.UnitTests/Infrastructure/ClaimParserTests.cs b/test/Ocelot.UnitTests/Infrastructure/ClaimParserTests.cs index 19570554..321e0a07 100644 --- a/test/Ocelot.UnitTests/Infrastructure/ClaimParserTests.cs +++ b/test/Ocelot.UnitTests/Infrastructure/ClaimParserTests.cs @@ -2,11 +2,11 @@ namespace Ocelot.UnitTests.Infrastructure { - using System.Collections.Generic; - using System.Security.Claims; using Ocelot.Infrastructure.Claims.Parser; using Responses; using Shouldly; + using System.Collections.Generic; + using System.Security.Claims; using TestStack.BDDfy; using Xunit; @@ -119,6 +119,6 @@ namespace Ocelot.UnitTests.Infrastructure { _result.Data.ShouldBe(expected.Data); _result.IsError.ShouldBe(expected.IsError); - } + } } -} +} diff --git a/test/Ocelot.UnitTests/Infrastructure/HttpDataRepositoryTests.cs b/test/Ocelot.UnitTests/Infrastructure/HttpDataRepositoryTests.cs index 555cfe32..0effbed5 100644 --- a/test/Ocelot.UnitTests/Infrastructure/HttpDataRepositoryTests.cs +++ b/test/Ocelot.UnitTests/Infrastructure/HttpDataRepositoryTests.cs @@ -17,12 +17,12 @@ namespace Ocelot.UnitTests.Infrastructure public HttpDataRepositoryTests() { _httpContext = new DefaultHttpContext(); - _httpContextAccessor = new HttpContextAccessor{HttpContext = _httpContext}; + _httpContextAccessor = new HttpContextAccessor { HttpContext = _httpContext }; _httpDataRepository = new HttpDataRepository(_httpContextAccessor); } /* - TODO - Additional tests -> Type mistmatch aka Add string, request int + TODO - Additional tests -> Type mistmatch aka Add string, request int TODO - Additional tests -> HttpContent null. This should never happen */ @@ -72,9 +72,9 @@ namespace Ocelot.UnitTests.Infrastructure private void ThenTheResultIsAnErrorReposnse(object resultValue) { _result.ShouldBeOfType>(); - ((ErrorResponse) _result).Data.ShouldBeNull(); + ((ErrorResponse)_result).Data.ShouldBeNull(); ((ErrorResponse)_result).IsError.ShouldBe(true); - ((ErrorResponse) _result).Errors.ShouldHaveSingleItem() + ((ErrorResponse)_result).Errors.ShouldHaveSingleItem() .ShouldBeOfType() .Message.ShouldStartWith("Unable to find data for key: "); } @@ -85,4 +85,4 @@ namespace Ocelot.UnitTests.Infrastructure ((OkResponse)_result).Data.ShouldBe(resultValue); } } -} +} diff --git a/test/Ocelot.UnitTests/Infrastructure/InMemoryBusTests.cs b/test/Ocelot.UnitTests/Infrastructure/InMemoryBusTests.cs index ed8f3e00..a46cbe10 100644 --- a/test/Ocelot.UnitTests/Infrastructure/InMemoryBusTests.cs +++ b/test/Ocelot.UnitTests/Infrastructure/InMemoryBusTests.cs @@ -1,6 +1,6 @@ -using System.Threading.Tasks; using Ocelot.Infrastructure; using Shouldly; +using System.Threading.Tasks; using Xunit; namespace Ocelot.UnitTests.Infrastructure @@ -18,7 +18,8 @@ namespace Ocelot.UnitTests.Infrastructure public async Task should_publish_with_delay() { var called = false; - _bus.Subscribe(x => { + _bus.Subscribe(x => + { called = true; }); _bus.Publish(new object(), 1); @@ -30,7 +31,8 @@ namespace Ocelot.UnitTests.Infrastructure public void should_not_be_publish_yet_as_no_delay_in_caller() { var called = false; - _bus.Subscribe(x => { + _bus.Subscribe(x => + { called = true; }); _bus.Publish(new object(), 1); diff --git a/test/Ocelot.UnitTests/Infrastructure/PlaceholdersTests.cs b/test/Ocelot.UnitTests/Infrastructure/PlaceholdersTests.cs index d2ac7401..ccd48902 100644 --- a/test/Ocelot.UnitTests/Infrastructure/PlaceholdersTests.cs +++ b/test/Ocelot.UnitTests/Infrastructure/PlaceholdersTests.cs @@ -1,9 +1,6 @@ namespace Ocelot.UnitTests.Infrastructure { using Microsoft.AspNetCore.Http; - using System; - using System.Net; - using System.Net.Http; using Moq; using Ocelot.Infrastructure; using Ocelot.Infrastructure.RequestData; @@ -11,6 +8,9 @@ namespace Ocelot.UnitTests.Infrastructure using Ocelot.Request.Middleware; using Ocelot.Responses; using Shouldly; + using System; + using System.Net; + using System.Net.Http; using Xunit; public class PlaceholdersTests @@ -40,7 +40,7 @@ namespace Ocelot.UnitTests.Infrastructure [Fact] public void should_return_remote_ip_address() { - var httpContext = new DefaultHttpContext(){Connection = { RemoteIpAddress = IPAddress.Any}}; + var httpContext = new DefaultHttpContext() { Connection = { RemoteIpAddress = IPAddress.Any } }; _accessor.Setup(x => x.HttpContext).Returns(httpContext); var result = _placeholders.Get("{RemoteIpAddress}"); result.Data.ShouldBe(httpContext.Connection.RemoteIpAddress.ToString()); diff --git a/test/Ocelot.UnitTests/Infrastructure/ScopesAuthoriserTests.cs b/test/Ocelot.UnitTests/Infrastructure/ScopesAuthoriserTests.cs index 08f6a46d..76901f23 100644 --- a/test/Ocelot.UnitTests/Infrastructure/ScopesAuthoriserTests.cs +++ b/test/Ocelot.UnitTests/Infrastructure/ScopesAuthoriserTests.cs @@ -1,13 +1,13 @@ -using Xunit; -using Shouldly; -using Ocelot.Authorisation; -using Ocelot.Infrastructure.Claims.Parser; using Moq; +using Ocelot.Authorisation; +using Ocelot.Errors; +using Ocelot.Infrastructure.Claims.Parser; +using Ocelot.Responses; +using Shouldly; using System.Collections.Generic; using System.Security.Claims; -using Ocelot.Responses; using TestStack.BDDfy; -using Ocelot.Errors; +using Xunit; namespace Ocelot.UnitTests.Infrastructure { @@ -51,7 +51,7 @@ namespace Ocelot.UnitTests.Infrastructure var fakeError = new FakeError(); this.Given(_ => GivenTheFollowing(new ClaimsPrincipal())) .And(_ => GivenTheParserReturns(new ErrorResponse>(fakeError))) - .And(_ => GivenTheFollowing(new List(){"doesntmatter"})) + .And(_ => GivenTheFollowing(new List() { "doesntmatter" })) .When(_ => WhenIAuthorise()) .Then(_ => ThenTheFollowingIsReturned(new ErrorResponse(fakeError))) .BDDfy(); @@ -61,7 +61,7 @@ namespace Ocelot.UnitTests.Infrastructure public void should_match_scopes_and_return_ok_result() { var claimsPrincipal = new ClaimsPrincipal(); - var allowedScopes = new List(){"someScope"}; + var allowedScopes = new List() { "someScope" }; this.Given(_ => GivenTheFollowing(claimsPrincipal)) .And(_ => GivenTheParserReturns(new OkResponse>(allowedScopes))) @@ -76,8 +76,8 @@ namespace Ocelot.UnitTests.Infrastructure { var fakeError = new FakeError(); var claimsPrincipal = new ClaimsPrincipal(); - var allowedScopes = new List(){"someScope"}; - var userScopes = new List(){"anotherScope"}; + var allowedScopes = new List() { "someScope" }; + var userScopes = new List() { "anotherScope" }; this.Given(_ => GivenTheFollowing(claimsPrincipal)) .And(_ => GivenTheParserReturns(new OkResponse>(userScopes))) @@ -112,12 +112,12 @@ namespace Ocelot.UnitTests.Infrastructure _result.Data.ShouldBe(expected.Data); _result.IsError.ShouldBe(expected.IsError); } + } + + public class FakeError : Error + { + public FakeError() : base("fake error", OcelotErrorCode.CannotAddDataError) + { + } } - - public class FakeError : Error - { - public FakeError() : base("fake error", OcelotErrorCode.CannotAddDataError) - { - } - } -} +} diff --git a/test/Ocelot.UnitTests/Infrastructure/StringExtensionsTests.cs b/test/Ocelot.UnitTests/Infrastructure/StringExtensionsTests.cs index 88632675..06d81a6f 100644 --- a/test/Ocelot.UnitTests/Infrastructure/StringExtensionsTests.cs +++ b/test/Ocelot.UnitTests/Infrastructure/StringExtensionsTests.cs @@ -1,6 +1,6 @@ -using Xunit; -using Ocelot.Infrastructure.Extensions; +using Ocelot.Infrastructure.Extensions; using Shouldly; +using Xunit; namespace Ocelot.UnitTests.Infrastructure { diff --git a/test/Ocelot.UnitTests/Kubernetes/KubeServiceDiscoveryProviderTests.cs b/test/Ocelot.UnitTests/Kubernetes/KubeServiceDiscoveryProviderTests.cs index d2abded6..8534194d 100644 --- a/test/Ocelot.UnitTests/Kubernetes/KubeServiceDiscoveryProviderTests.cs +++ b/test/Ocelot.UnitTests/Kubernetes/KubeServiceDiscoveryProviderTests.cs @@ -76,10 +76,11 @@ namespace Ocelot.UnitTests.Kubernetes Namespace = "dev" }, Spec = new ServiceSpecV1() - { - ClusterIP = "localhost" + { + ClusterIP = "localhost" }, - Status = new ServiceStatusV1() { + Status = new ServiceStatusV1() + { LoadBalancer = new LoadBalancerStatusV1() } }; @@ -91,7 +92,7 @@ namespace Ocelot.UnitTests.Kubernetes } ); - this.Given(x => GivenThereIsAFakeKubeServiceDiscoveryProvider(_fakekubeServiceDiscoveryUrl, _serviceName, _namespaces)) + this.Given(x => GivenThereIsAFakeKubeServiceDiscoveryProvider(_fakekubeServiceDiscoveryUrl, _serviceName, _namespaces)) .And(x => GivenTheServicesAreRegisteredWithKube(serviceEntryOne)) .When(x => WhenIGetTheServices()) .Then(x => ThenTheCountIs(1)) @@ -114,7 +115,6 @@ namespace Ocelot.UnitTests.Kubernetes _serviceEntries = serviceEntries; } - private void GivenThereIsAFakeKubeServiceDiscoveryProvider(string url, string serviceName, string namespaces) { _fakeKubeBuilder = new WebHostBuilder() diff --git a/test/Ocelot.UnitTests/Kubernetes/OcelotBuilderExtensionsTests.cs b/test/Ocelot.UnitTests/Kubernetes/OcelotBuilderExtensionsTests.cs index 103f94aa..a2cb9e94 100644 --- a/test/Ocelot.UnitTests/Kubernetes/OcelotBuilderExtensionsTests.cs +++ b/test/Ocelot.UnitTests/Kubernetes/OcelotBuilderExtensionsTests.cs @@ -7,7 +7,6 @@ using Ocelot.Provider.Kubernetes; using Shouldly; using System; using System.Collections.Generic; -using System.Text; using TestStack.BDDfy; using Xunit; diff --git a/test/Ocelot.UnitTests/Kubernetes/PollingKubeServiceDiscoveryProviderTests.cs b/test/Ocelot.UnitTests/Kubernetes/PollingKubeServiceDiscoveryProviderTests.cs index 49f63afe..0009ec02 100644 --- a/test/Ocelot.UnitTests/Kubernetes/PollingKubeServiceDiscoveryProviderTests.cs +++ b/test/Ocelot.UnitTests/Kubernetes/PollingKubeServiceDiscoveryProviderTests.cs @@ -7,7 +7,6 @@ using Ocelot.Values; using Shouldly; using System; using System.Collections.Generic; -using System.Text; using TestStack.BDDfy; using Xunit; @@ -59,7 +58,8 @@ namespace Ocelot.UnitTests.Kubernetes { _provider = new PollKube(_delay, _factory.Object, _kubeServiceDiscoveryProvider.Object); - var result = Wait.WaitFor(3000).Until(() => { + var result = Wait.WaitFor(3000).Until(() => + { try { _result = _provider.Get().GetAwaiter().GetResult(); diff --git a/test/Ocelot.UnitTests/LoadBalancer/CookieStickySessionsTests.cs b/test/Ocelot.UnitTests/LoadBalancer/CookieStickySessionsTests.cs index 08dfb124..401c2db1 100644 --- a/test/Ocelot.UnitTests/LoadBalancer/CookieStickySessionsTests.cs +++ b/test/Ocelot.UnitTests/LoadBalancer/CookieStickySessionsTests.cs @@ -1,20 +1,20 @@ namespace Ocelot.UnitTests.LoadBalancer { - using System; - using System.Threading.Tasks; + using Microsoft.AspNetCore.Http; + using Moq; + using Ocelot.Infrastructure; using Ocelot.LoadBalancer.LoadBalancers; + using Ocelot.Middleware; using Ocelot.Responses; + using Ocelot.UnitTests.Responder; using Ocelot.Values; using Shouldly; - using Xunit; - using Moq; - using Microsoft.AspNetCore.Http; - using System.Collections.Generic; + using System; using System.Collections; - using Ocelot.Middleware; - using Ocelot.UnitTests.Responder; + using System.Collections.Generic; + using System.Threading.Tasks; using TestStack.BDDfy; - using Ocelot.Infrastructure; + using Xunit; public class CookieStickySessionsTests { diff --git a/test/Ocelot.UnitTests/LoadBalancer/LeastConnectionTests.cs b/test/Ocelot.UnitTests/LoadBalancer/LeastConnectionTests.cs index a995a004..1f610dd1 100644 --- a/test/Ocelot.UnitTests/LoadBalancer/LeastConnectionTests.cs +++ b/test/Ocelot.UnitTests/LoadBalancer/LeastConnectionTests.cs @@ -1,12 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Ocelot.LoadBalancer.LoadBalancers; using Ocelot.Middleware; using Ocelot.Responses; using Ocelot.Values; using Shouldly; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; @@ -42,8 +42,8 @@ namespace Ocelot.UnitTests.LoadBalancer _leastConnection = new LeastConnection(() => Task.FromResult(_services), serviceName); var tasks = new Task[100]; - - for(var i = 0; i < tasks.Length; i++) + + for (var i = 0; i < tasks.Length; i++) { tasks[i] = LeaseDelayAndRelease(); } @@ -154,7 +154,7 @@ namespace Ocelot.UnitTests.LoadBalancer [Fact] public void should_build_connections_per_service() { - var serviceName = "products"; + var serviceName = "products"; var availableServices = new List { @@ -185,7 +185,7 @@ namespace Ocelot.UnitTests.LoadBalancer [Fact] public void should_release_connection() { - var serviceName = "products"; + var serviceName = "products"; var availableServices = new List { @@ -226,11 +226,11 @@ namespace Ocelot.UnitTests.LoadBalancer var serviceName = "products"; var hostAndPort = new ServiceHostAndPort("localhost", 80); - this.Given(x => x.GivenAHostAndPort(hostAndPort)) - .And(x => x.GivenTheLoadBalancerStarts(null, serviceName)) - .When(x => x.WhenIGetTheNextHostAndPort()) - .Then(x => x.ThenServiceAreNullErrorIsReturned()) - .BDDfy(); + this.Given(x => x.GivenAHostAndPort(hostAndPort)) + .And(x => x.GivenTheLoadBalancerStarts(null, serviceName)) + .When(x => x.WhenIGetTheNextHostAndPort()) + .Then(x => x.ThenServiceAreNullErrorIsReturned()) + .BDDfy(); } [Fact] @@ -239,11 +239,11 @@ namespace Ocelot.UnitTests.LoadBalancer var serviceName = "products"; var hostAndPort = new ServiceHostAndPort("localhost", 80); - this.Given(x => x.GivenAHostAndPort(hostAndPort)) - .And(x => x.GivenTheLoadBalancerStarts(new List(), serviceName)) - .When(x => x.WhenIGetTheNextHostAndPort()) - .Then(x => x.ThenServiceAreEmptyErrorIsReturned()) - .BDDfy(); + this.Given(x => x.GivenAHostAndPort(hostAndPort)) + .And(x => x.GivenTheLoadBalancerStarts(new List(), serviceName)) + .When(x => x.WhenIGetTheNextHostAndPort()) + .Then(x => x.ThenServiceAreEmptyErrorIsReturned()) + .BDDfy(); } private void ThenServiceAreNullErrorIsReturned() diff --git a/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerFactoryTests.cs b/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerFactoryTests.cs index 652193ca..8df47cea 100644 --- a/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerFactoryTests.cs +++ b/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerFactoryTests.cs @@ -2,13 +2,13 @@ using Moq; using Ocelot.Configuration; using Ocelot.Configuration.Builder; using Ocelot.LoadBalancer.LoadBalancers; +using Ocelot.Responses; using Ocelot.ServiceDiscovery; +using Ocelot.ServiceDiscovery.Providers; using Shouldly; using System.Collections.Generic; -using Ocelot.ServiceDiscovery.Providers; using TestStack.BDDfy; using Xunit; -using Ocelot.Responses; namespace Ocelot.UnitTests.LoadBalancer { @@ -48,7 +48,7 @@ namespace Ocelot.UnitTests.LoadBalancer { var reRoute = new DownstreamReRouteBuilder() .WithLoadBalancerOptions(new LoadBalancerOptions("RoundRobin", "", 0)) - .WithUpstreamHttpMethod(new List {"Get"}) + .WithUpstreamHttpMethod(new List { "Get" }) .Build(); this.Given(x => x.GivenAReRoute(reRoute)) @@ -64,7 +64,7 @@ namespace Ocelot.UnitTests.LoadBalancer { var reRoute = new DownstreamReRouteBuilder() .WithLoadBalancerOptions(new LoadBalancerOptions("LeastConnection", "", 0)) - .WithUpstreamHttpMethod(new List {"Get"}) + .WithUpstreamHttpMethod(new List { "Get" }) .Build(); this.Given(x => x.GivenAReRoute(reRoute)) @@ -80,7 +80,7 @@ namespace Ocelot.UnitTests.LoadBalancer { var reRoute = new DownstreamReRouteBuilder() .WithLoadBalancerOptions(new LoadBalancerOptions("RoundRobin", "", 0)) - .WithUpstreamHttpMethod(new List {"Get"}) + .WithUpstreamHttpMethod(new List { "Get" }) .Build(); this.Given(x => x.GivenAReRoute(reRoute)) @@ -96,7 +96,7 @@ namespace Ocelot.UnitTests.LoadBalancer { var reRoute = new DownstreamReRouteBuilder() .WithLoadBalancerOptions(new LoadBalancerOptions("CookieStickySessions", "", 0)) - .WithUpstreamHttpMethod(new List {"Get"}) + .WithUpstreamHttpMethod(new List { "Get" }) .Build(); this.Given(x => x.GivenAReRoute(reRoute)) diff --git a/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerHouseTests.cs b/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerHouseTests.cs index e74f5728..57252b2b 100644 --- a/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerHouseTests.cs +++ b/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerHouseTests.cs @@ -1,6 +1,4 @@ -using System; -using System.Threading.Tasks; -using Moq; +using Moq; using Ocelot.Configuration; using Ocelot.Configuration.Builder; using Ocelot.LoadBalancer.LoadBalancers; @@ -8,6 +6,8 @@ using Ocelot.Middleware; using Ocelot.Responses; using Ocelot.Values; using Shouldly; +using System; +using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; @@ -26,7 +26,7 @@ namespace Ocelot.UnitTests.LoadBalancer { _factory = new Mock(); _loadBalancerHouse = new LoadBalancerHouse(_factory.Object); - _serviceProviderConfig = new ServiceProviderConfiguration("myType","myHost",123, string.Empty, "configKey", 0); + _serviceProviderConfig = new ServiceProviderConfiguration("myType", "myHost", 123, string.Empty, "configKey", 0); } [Fact] @@ -62,7 +62,7 @@ namespace Ocelot.UnitTests.LoadBalancer .WithLoadBalancerOptions(new LoadBalancerOptions("FakeLoadBalancer", "", 0)) .WithLoadBalancerKey("test") .Build(); - + var reRouteTwo = new DownstreamReRouteBuilder() .WithLoadBalancerOptions(new LoadBalancerOptions("FakeRoundRobinLoadBalancer", "", 0)) .WithLoadBalancerKey("testtwo") @@ -115,7 +115,7 @@ namespace Ocelot.UnitTests.LoadBalancer _getResult = _loadBalancerHouse.Get(_reRoute, _serviceProviderConfig).Result; } - private void ThenAnErrorIsReturned() + private void ThenAnErrorIsReturned() { _getResult.IsError.ShouldBeTrue(); _getResult.Errors[0].ShouldBeOfType(); @@ -153,7 +153,7 @@ namespace Ocelot.UnitTests.LoadBalancer _factory.Verify(x => x.Get(_reRoute, _serviceProviderConfig), Times.Once); } - class FakeLoadBalancer : ILoadBalancer + private class FakeLoadBalancer : ILoadBalancer { public Task> Lease(DownstreamContext context) { @@ -166,7 +166,7 @@ namespace Ocelot.UnitTests.LoadBalancer } } - class FakeRoundRobinLoadBalancer : ILoadBalancer + private class FakeRoundRobinLoadBalancer : ILoadBalancer { public Task> Lease(DownstreamContext context) { diff --git a/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerMiddlewareTests.cs b/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerMiddlewareTests.cs index 3bf97341..8d31572a 100644 --- a/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerMiddlewareTests.cs @@ -2,9 +2,6 @@ using Ocelot.Middleware; namespace Ocelot.UnitTests.LoadBalancer { - using System.Collections.Generic; - using System.Net.Http; - using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Moq; using Ocelot.Configuration; @@ -17,6 +14,9 @@ namespace Ocelot.UnitTests.LoadBalancer using Ocelot.Responses; using Ocelot.Values; using Shouldly; + using System.Collections.Generic; + using System.Net.Http; + using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; @@ -71,7 +71,7 @@ namespace Ocelot.UnitTests.LoadBalancer [Fact] public void should_set_pipeline_error_if_cannot_get_load_balancer() - { + { var downstreamRoute = new DownstreamReRouteBuilder() .WithUpstreamHttpMethod(new List { "Get" }) .Build(); @@ -94,9 +94,9 @@ namespace Ocelot.UnitTests.LoadBalancer var downstreamRoute = new DownstreamReRouteBuilder() .WithUpstreamHttpMethod(new List { "Get" }) .Build(); - - var serviceProviderConfig = new ServiceProviderConfigurationBuilder() - .Build(); + + var serviceProviderConfig = new ServiceProviderConfigurationBuilder() + .Build(); this.Given(x => x.GivenTheDownStreamUrlIs("http://my.url/abc?q=123")) .And(x => GivenTheConfigurationIs(serviceProviderConfig)) @@ -130,9 +130,9 @@ namespace Ocelot.UnitTests.LoadBalancer private void GivenTheLoadBalancerReturnsAnError() { _getHostAndPortError = new ErrorResponse(new List() { new ServicesAreNullError($"services were null for bah") }); - _loadBalancer - .Setup(x => x.Lease(It.IsAny())) - .ReturnsAsync(_getHostAndPortError); + _loadBalancer + .Setup(x => x.Lease(It.IsAny())) + .ReturnsAsync(_getHostAndPortError); } private void GivenTheLoadBalancerReturns() diff --git a/test/Ocelot.UnitTests/LoadBalancer/NoLoadBalancerTests.cs b/test/Ocelot.UnitTests/LoadBalancer/NoLoadBalancerTests.cs index 6cb3a197..5f10c3bc 100644 --- a/test/Ocelot.UnitTests/LoadBalancer/NoLoadBalancerTests.cs +++ b/test/Ocelot.UnitTests/LoadBalancer/NoLoadBalancerTests.cs @@ -1,12 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Ocelot.LoadBalancer.LoadBalancers; using Ocelot.Middleware; using Ocelot.Responses; using Ocelot.Values; using Shouldly; +using System.Collections.Generic; +using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; diff --git a/test/Ocelot.UnitTests/LoadBalancer/RoundRobinTests.cs b/test/Ocelot.UnitTests/LoadBalancer/RoundRobinTests.cs index 9af14055..ed5fc3bc 100644 --- a/test/Ocelot.UnitTests/LoadBalancer/RoundRobinTests.cs +++ b/test/Ocelot.UnitTests/LoadBalancer/RoundRobinTests.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; -using System.Diagnostics; +using Microsoft.AspNetCore.Http; using Ocelot.LoadBalancer.LoadBalancers; +using Ocelot.Middleware; using Ocelot.Responses; using Ocelot.Values; using Shouldly; +using System.Collections.Generic; +using System.Diagnostics; +using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; -using System.Threading.Tasks; -using Ocelot.Middleware; -using Microsoft.AspNetCore.Http; namespace Ocelot.UnitTests.LoadBalancer { diff --git a/test/Ocelot.UnitTests/Logging/AspDotNetLoggerTests.cs b/test/Ocelot.UnitTests/Logging/AspDotNetLoggerTests.cs index 8a1fa891..13d9f874 100644 --- a/test/Ocelot.UnitTests/Logging/AspDotNetLoggerTests.cs +++ b/test/Ocelot.UnitTests/Logging/AspDotNetLoggerTests.cs @@ -1,16 +1,16 @@ namespace Ocelot.UnitTests.Logging { - using Moq; - using Xunit; - using Ocelot.Logging; using Microsoft.Extensions.Logging; + using Moq; using Ocelot.Infrastructure.RequestData; + using Ocelot.Logging; using System; + using Xunit; public class AspDotNetLoggerTests { private readonly Mock> _coreLogger; - private readonly AspDotNetLogger _logger; + private readonly AspDotNetLogger _logger; private Mock _repo; private readonly string _b; private readonly string _a; @@ -72,7 +72,7 @@ namespace Ocelot.UnitTests.Logging x => x.Log( expectedLogLevel, It.IsAny(), - It.Is(o => o.ToString() == expected), + It.Is(o => o.ToString() == expected), It.IsAny(), It.IsAny>()), Times.Once); } diff --git a/test/Ocelot.UnitTests/Logging/OcelotDiagnosticListenerTests.cs b/test/Ocelot.UnitTests/Logging/OcelotDiagnosticListenerTests.cs index 1a463cfa..41507e11 100644 --- a/test/Ocelot.UnitTests/Logging/OcelotDiagnosticListenerTests.cs +++ b/test/Ocelot.UnitTests/Logging/OcelotDiagnosticListenerTests.cs @@ -1,13 +1,11 @@ -using Ocelot.Logging; -using Moq; -using TestStack.BDDfy; -using Butterfly.Client.Tracing; -using Ocelot.Requester; -using Xunit; -using Ocelot.Middleware; using Microsoft.AspNetCore.Http; -using System; using Microsoft.Extensions.DependencyInjection; +using Moq; +using Ocelot.Logging; +using Ocelot.Middleware; +using System; +using TestStack.BDDfy; +using Xunit; namespace Ocelot.UnitTests.Logging { @@ -63,7 +61,7 @@ namespace Ocelot.UnitTests.Logging .BDDfy(); } - [Fact] + [Fact] public void should_trace_middleware_started() { this.Given(_ => GivenAMiddlewareName()) diff --git a/test/Ocelot.UnitTests/Middleware/BaseUrlFinderTests.cs b/test/Ocelot.UnitTests/Middleware/BaseUrlFinderTests.cs index 47e00ab9..7a8e4d8f 100644 --- a/test/Ocelot.UnitTests/Middleware/BaseUrlFinderTests.cs +++ b/test/Ocelot.UnitTests/Middleware/BaseUrlFinderTests.cs @@ -1,13 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration.Memory; -using Moq; using Ocelot.Middleware; using Shouldly; +using System.Collections.Generic; using TestStack.BDDfy; using Xunit; @@ -22,7 +17,7 @@ namespace Ocelot.UnitTests.Middleware public BaseUrlFinderTests() { - _data = new List>(); + _data = new List>(); } [Fact] @@ -79,4 +74,4 @@ namespace Ocelot.UnitTests.Middleware _result.ShouldBe(expected); } } -} +} diff --git a/test/Ocelot.UnitTests/Middleware/MultiplexerTests.cs b/test/Ocelot.UnitTests/Middleware/MultiplexerTests.cs index 787bfefa..7615dbfb 100644 --- a/test/Ocelot.UnitTests/Middleware/MultiplexerTests.cs +++ b/test/Ocelot.UnitTests/Middleware/MultiplexerTests.cs @@ -1,11 +1,11 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; using Moq; using Ocelot.Configuration; using Ocelot.Configuration.Builder; using Ocelot.Middleware; using Ocelot.Middleware.Multiplexer; using Shouldly; +using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; @@ -26,7 +26,7 @@ namespace Ocelot.UnitTests.Middleware _factory = new Mock(); _aggregator = new Mock(); _context = new DownstreamContext(new DefaultHttpContext()); - _pipeline = context => Task.FromResult(_count++); + _pipeline = context => Task.FromResult(_count++); _factory.Setup(x => x.Get(It.IsAny())).Returns(_aggregator.Object); _multiplexer = new Multiplexer(_factory.Object); } diff --git a/test/Ocelot.UnitTests/Middleware/OcelotMiddlewareTests.cs b/test/Ocelot.UnitTests/Middleware/OcelotMiddlewareTests.cs index 9e13ed1a..ca5c34ef 100644 --- a/test/Ocelot.UnitTests/Middleware/OcelotMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Middleware/OcelotMiddlewareTests.cs @@ -1,11 +1,10 @@ -using System; -using System.Collections.Generic; using Microsoft.AspNetCore.Http; using Moq; using Ocelot.Errors; using Ocelot.Logging; using Ocelot.Middleware; using Ocelot.UnitTests.Responder; +using System.Collections.Generic; using TestStack.BDDfy; using Xunit; @@ -66,7 +65,7 @@ namespace Ocelot.UnitTests.Middleware public class FakeMiddleware : OcelotMiddleware { - public FakeMiddleware(IOcelotLogger logger) + public FakeMiddleware(IOcelotLogger logger) : base(logger) { } diff --git a/test/Ocelot.UnitTests/Middleware/OcelotPipelineExtensionsTests.cs b/test/Ocelot.UnitTests/Middleware/OcelotPipelineExtensionsTests.cs index e14dddb5..2e097b08 100644 --- a/test/Ocelot.UnitTests/Middleware/OcelotPipelineExtensionsTests.cs +++ b/test/Ocelot.UnitTests/Middleware/OcelotPipelineExtensionsTests.cs @@ -22,10 +22,10 @@ namespace Ocelot.UnitTests.Middleware [Fact] public void should_set_up_pipeline() { - this.Given(_ => GivenTheDepedenciesAreSetUp()) - .When(_ => WhenIBuild()) - .Then(_ => ThenThePipelineIsBuilt()) - .BDDfy(); + this.Given(_ => GivenTheDepedenciesAreSetUp()) + .When(_ => WhenIBuild()) + .Then(_ => ThenThePipelineIsBuilt()) + .BDDfy(); } [Fact] diff --git a/test/Ocelot.UnitTests/Middleware/OcelotPiplineBuilderTests.cs b/test/Ocelot.UnitTests/Middleware/OcelotPiplineBuilderTests.cs index a798ae44..bafc3532 100644 --- a/test/Ocelot.UnitTests/Middleware/OcelotPiplineBuilderTests.cs +++ b/test/Ocelot.UnitTests/Middleware/OcelotPiplineBuilderTests.cs @@ -3,7 +3,6 @@ using System.Threading.Tasks; namespace Ocelot.UnitTests.Middleware { - using System.Collections.Generic; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.AspNetCore.Http; @@ -14,6 +13,7 @@ namespace Ocelot.UnitTests.Middleware using Ocelot.Middleware; using Ocelot.Middleware.Pipeline; using Shouldly; + using System.Collections.Generic; using TestStack.BDDfy; using Xunit; @@ -79,8 +79,6 @@ namespace Ocelot.UnitTests.Middleware del.Invoke(_downstreamContext); } - - private void ThenTheFuncIsInThePipeline() { _counter.ShouldBe(1); @@ -103,7 +101,7 @@ namespace Ocelot.UnitTests.Middleware private readonly OcelotRequestDelegate _next; public MultiParametersInvokeMiddleware(OcelotRequestDelegate next) - :base(new FakeLogger()) + : base(new FakeLogger()) { _next = next; } @@ -115,7 +113,7 @@ namespace Ocelot.UnitTests.Middleware } } - class FakeLogger : IOcelotLogger + internal class FakeLogger : IOcelotLogger { public void LogCritical(string message, Exception exception) { diff --git a/test/Ocelot.UnitTests/Middleware/ResponseAggregatorFactoryTests.cs b/test/Ocelot.UnitTests/Middleware/ResponseAggregatorFactoryTests.cs index 16a682ce..73f80f6f 100644 --- a/test/Ocelot.UnitTests/Middleware/ResponseAggregatorFactoryTests.cs +++ b/test/Ocelot.UnitTests/Middleware/ResponseAggregatorFactoryTests.cs @@ -1,12 +1,12 @@ namespace Ocelot.UnitTests.Middleware { using Moq; + using Ocelot.Configuration; using Ocelot.Configuration.Builder; using Ocelot.Middleware.Multiplexer; using Shouldly; - using Xunit; - using Ocelot.Configuration; using TestStack.BDDfy; + using Xunit; public class ResponseAggregatorFactoryTests { @@ -21,7 +21,7 @@ namespace Ocelot.UnitTests.Middleware _aggregator = new SimpleJsonResponseAggregator(); _factory = new InMemoryResponseAggregatorFactory(_provider.Object, _aggregator); } - + [Fact] public void should_return_simple_json_aggregator() { diff --git a/test/Ocelot.UnitTests/Middleware/SimpleJsonResponseAggregatorTests.cs b/test/Ocelot.UnitTests/Middleware/SimpleJsonResponseAggregatorTests.cs index a391ce59..8d17d792 100644 --- a/test/Ocelot.UnitTests/Middleware/SimpleJsonResponseAggregatorTests.cs +++ b/test/Ocelot.UnitTests/Middleware/SimpleJsonResponseAggregatorTests.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Http; -using System.Text; -using Castle.Components.DictionaryAdapter; +using Castle.Components.DictionaryAdapter; using Microsoft.AspNetCore.Http; using Ocelot.Configuration; using Ocelot.Configuration.Builder; @@ -13,6 +8,10 @@ using Ocelot.Middleware.Multiplexer; using Ocelot.UnitTests.Responder; using Ocelot.Values; using Shouldly; +using System.Collections.Generic; +using System.Net; +using System.Net.Http; +using System.Text; using TestStack.BDDfy; using Xunit; @@ -81,7 +80,6 @@ namespace Ocelot.UnitTests.Middleware .BDDfy(); } - [Fact] public void should_aggregate_n_responses_and_set_response_content_on_upstream_context() { diff --git a/test/Ocelot.UnitTests/Middleware/UserDefinedResponseAggregatorTests.cs b/test/Ocelot.UnitTests/Middleware/UserDefinedResponseAggregatorTests.cs index 4ebb592c..78d53878 100644 --- a/test/Ocelot.UnitTests/Middleware/UserDefinedResponseAggregatorTests.cs +++ b/test/Ocelot.UnitTests/Middleware/UserDefinedResponseAggregatorTests.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Moq; using Ocelot.Configuration; @@ -13,6 +7,11 @@ using Ocelot.Middleware.Multiplexer; using Ocelot.Responses; using Ocelot.UnitTests.Responder; using Shouldly; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; @@ -71,7 +70,7 @@ namespace Ocelot.UnitTests.Middleware var contexts = new List { new DownstreamContext(new DefaultHttpContext()) - { + { DownstreamResponse = new DownstreamResponse(new StringContent("Tom"), HttpStatusCode.OK, new List>>(), "some reason") }, new DownstreamContext(new DefaultHttpContext()) diff --git a/test/Ocelot.UnitTests/Polly/OcelotBuilderExtensionsTests.cs b/test/Ocelot.UnitTests/Polly/OcelotBuilderExtensionsTests.cs index bb9e45ed..44854649 100644 --- a/test/Ocelot.UnitTests/Polly/OcelotBuilderExtensionsTests.cs +++ b/test/Ocelot.UnitTests/Polly/OcelotBuilderExtensionsTests.cs @@ -1,6 +1,5 @@ namespace Ocelot.UnitTests.Polly { - using System.IO; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Moq; @@ -10,6 +9,7 @@ using Ocelot.Requester; using Provider.Polly; using Shouldly; + using System.IO; using Xunit; public class OcelotBuilderExtensionsTests diff --git a/test/Ocelot.UnitTests/Properties/AssemblyInfo.cs b/test/Ocelot.UnitTests/Properties/AssemblyInfo.cs index b6ccccf5..0b6a721e 100644 --- a/test/Ocelot.UnitTests/Properties/AssemblyInfo.cs +++ b/test/Ocelot.UnitTests/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following @@ -16,4 +15,4 @@ using System.Runtime.InteropServices; [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("54e84f1a-e525-4443-96ec-039cbd50c263")] +[assembly: Guid("54e84f1a-e525-4443-96ec-039cbd50c263")] diff --git a/test/Ocelot.UnitTests/QueryStrings/AddQueriesToRequestTests.cs b/test/Ocelot.UnitTests/QueryStrings/AddQueriesToRequestTests.cs index 8672ebf5..d82fbc5b 100644 --- a/test/Ocelot.UnitTests/QueryStrings/AddQueriesToRequestTests.cs +++ b/test/Ocelot.UnitTests/QueryStrings/AddQueriesToRequestTests.cs @@ -1,18 +1,18 @@ -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using Moq; +using Moq; using Ocelot.Configuration; using Ocelot.Errors; using Ocelot.Infrastructure.Claims.Parser; using Ocelot.QueryStrings; +using Ocelot.Request.Middleware; using Ocelot.Responses; using Shouldly; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Security.Claims; using TestStack.BDDfy; using Xunit; -using System.Net.Http; -using System; -using Ocelot.Request.Middleware; namespace Ocelot.UnitTests.QueryStrings { @@ -161,8 +161,8 @@ namespace Ocelot.UnitTests.QueryStrings _parser .Setup( x => - x.GetValue(It.IsAny>(), - It.IsAny(), + x.GetValue(It.IsAny>(), + It.IsAny(), It.IsAny(), It.IsAny())) .Returns(_claimValue); @@ -183,12 +183,12 @@ namespace Ocelot.UnitTests.QueryStrings _result.IsError.ShouldBe(true); } - class AnyError : Error + private class AnyError : Error { - public AnyError() + public AnyError() : base("blahh", OcelotErrorCode.UnknownError) { } } } -} +} diff --git a/test/Ocelot.UnitTests/QueryStrings/ClaimsToQueryStringMiddlewareTests.cs b/test/Ocelot.UnitTests/QueryStrings/ClaimsToQueryStringMiddlewareTests.cs index 2710c866..d2716fae 100644 --- a/test/Ocelot.UnitTests/QueryStrings/ClaimsToQueryStringMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/QueryStrings/ClaimsToQueryStringMiddlewareTests.cs @@ -2,8 +2,7 @@ namespace Ocelot.UnitTests.QueryStrings { - using System.Collections.Generic; - using System.Net.Http; + using Microsoft.AspNetCore.Http; using Moq; using Ocelot.Configuration; using Ocelot.Configuration.Builder; @@ -12,13 +11,14 @@ namespace Ocelot.UnitTests.QueryStrings using Ocelot.Logging; using Ocelot.QueryStrings; using Ocelot.QueryStrings.Middleware; + using Ocelot.Request.Middleware; using Ocelot.Responses; + using System.Collections.Generic; + using System.Net.Http; + using System.Security.Claims; + using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; - using System.Security.Claims; - using Microsoft.AspNetCore.Http; - using System.Threading.Tasks; - using Ocelot.Request.Middleware; public class ClaimsToQueryStringMiddlewareTests { diff --git a/test/Ocelot.UnitTests/Rafty/OcelotAdministrationBuilderExtensionsTests.cs b/test/Ocelot.UnitTests/Rafty/OcelotAdministrationBuilderExtensionsTests.cs index c34def7b..feb8603c 100644 --- a/test/Ocelot.UnitTests/Rafty/OcelotAdministrationBuilderExtensionsTests.cs +++ b/test/Ocelot.UnitTests/Rafty/OcelotAdministrationBuilderExtensionsTests.cs @@ -1,7 +1,5 @@ namespace Ocelot.UnitTests.Rafty { - using System; - using System.Collections.Generic; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.Extensions.Configuration; @@ -10,6 +8,8 @@ using Ocelot.DependencyInjection; using Provider.Rafty; using Shouldly; + using System; + using System.Collections.Generic; using TestStack.BDDfy; using Xunit; diff --git a/test/Ocelot.UnitTests/Rafty/RaftyFileConfigurationSetterTests.cs b/test/Ocelot.UnitTests/Rafty/RaftyFileConfigurationSetterTests.cs index 4307db02..fac7d2fa 100644 --- a/test/Ocelot.UnitTests/Rafty/RaftyFileConfigurationSetterTests.cs +++ b/test/Ocelot.UnitTests/Rafty/RaftyFileConfigurationSetterTests.cs @@ -1,12 +1,12 @@ namespace Ocelot.UnitTests.Rafty { - using System.Threading.Tasks; using global::Rafty.Concensus.Node; using global::Rafty.Infrastructure; using Moq; using Ocelot.Configuration.File; using Provider.Rafty; using Shouldly; + using System.Threading.Tasks; using Xunit; public class RaftyFileConfigurationSetterTests diff --git a/test/Ocelot.UnitTests/RateLimit/ClientRateLimitMiddlewareTests.cs b/test/Ocelot.UnitTests/RateLimit/ClientRateLimitMiddlewareTests.cs index dd2d3c91..1f928ff5 100644 --- a/test/Ocelot.UnitTests/RateLimit/ClientRateLimitMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/RateLimit/ClientRateLimitMiddlewareTests.cs @@ -2,9 +2,8 @@ namespace Ocelot.UnitTests.RateLimit { - using System.Collections.Generic; - using System.Net.Http; using Microsoft.AspNetCore.Http; + using Microsoft.Extensions.Caching.Memory; using Moq; using Ocelot.Configuration; using Ocelot.Configuration.Builder; @@ -12,13 +11,14 @@ namespace Ocelot.UnitTests.RateLimit using Ocelot.Logging; using Ocelot.RateLimit; using Ocelot.RateLimit.Middleware; + using Ocelot.Request.Middleware; using Shouldly; + using System.Collections.Generic; + using System.IO; + using System.Net.Http; + using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; - using Microsoft.Extensions.Caching.Memory; - using System.IO; - using System.Threading.Tasks; - using Ocelot.Request.Middleware; public class ClientRateLimitMiddlewareTests { @@ -55,13 +55,13 @@ namespace Ocelot.UnitTests.RateLimit var downstreamReRoute = new DownstreamReRouteBuilder() .WithEnableRateLimiting(true) .WithRateLimitOptions(new RateLimitOptions(true, "ClientId", new List(), false, "", "", new RateLimitRule("1s", 100, 3), 429)) - .WithUpstreamHttpMethod(new List {"Get"}) + .WithUpstreamHttpMethod(new List { "Get" }) .WithUpstreamPathTemplate(upstreamTemplate) .Build(); var reRoute = new ReRouteBuilder() .WithDownstreamReRoute(downstreamReRoute) - .WithUpstreamHttpMethod(new List {"Get"}) + .WithUpstreamHttpMethod(new List { "Get" }) .Build(); var downstreamRoute = new DownstreamRoute(new List(), reRoute); @@ -102,8 +102,8 @@ namespace Ocelot.UnitTests.RateLimit private void WhenICallTheMiddlewareMultipleTime(int times) { - var clientId = "ocelotclient1"; - + var clientId = "ocelotclient1"; + for (int i = 0; i < times; i++) { var request = new HttpRequestMessage(new HttpMethod("GET"), _url); @@ -117,8 +117,8 @@ namespace Ocelot.UnitTests.RateLimit private void WhenICallTheMiddlewareWithWhiteClient() { - var clientId = "ocelotclient2"; - + var clientId = "ocelotclient2"; + for (int i = 0; i < 10; i++) { var request = new HttpRequestMessage(new HttpMethod("GET"), _url); @@ -127,10 +127,10 @@ namespace Ocelot.UnitTests.RateLimit _downstreamContext.HttpContext.Request.Headers.TryAdd("ClientId", clientId); _middleware.Invoke(_downstreamContext).GetAwaiter().GetResult(); - _responseStatusCode = (int)_downstreamContext.HttpContext.Response.StatusCode; - } - } - + _responseStatusCode = (int)_downstreamContext.HttpContext.Response.StatusCode; + } + } + private void ThenresponseStatusCodeIs429() { _responseStatusCode.ShouldBe(429); @@ -142,7 +142,7 @@ namespace Ocelot.UnitTests.RateLimit } } - class FakeStream : Stream + internal class FakeStream : Stream { public override void Flush() { @@ -175,4 +175,4 @@ namespace Ocelot.UnitTests.RateLimit public override long Length { get; } public override long Position { get; set; } } -} +} diff --git a/test/Ocelot.UnitTests/Repository/ScopedRequestDataRepositoryTests.cs b/test/Ocelot.UnitTests/Repository/ScopedRequestDataRepositoryTests.cs index 2ecfb217..5b295074 100644 --- a/test/Ocelot.UnitTests/Repository/ScopedRequestDataRepositoryTests.cs +++ b/test/Ocelot.UnitTests/Repository/ScopedRequestDataRepositoryTests.cs @@ -25,7 +25,7 @@ namespace Ocelot.UnitTests.Repository [Fact] public void should_add_item() { - this.Given(x => x.GivenIHaveAnItemToAdd("blahh", new [] {1,2,3,4})) + this.Given(x => x.GivenIHaveAnItemToAdd("blahh", new[] { 1, 2, 3, 4 })) .When(x => x.WhenIAddTheItem()) .Then(x => x.ThenTheItemIsAdded()) .BDDfy(); @@ -54,7 +54,7 @@ namespace Ocelot.UnitTests.Repository private void GivenThereIsAnItemInTheContext(string key) { _key = key; - var data = new[] {5435345}; + var data = new[] { 5435345 }; _httpContextAccesor.HttpContext.Items.Add(key, data); } @@ -75,4 +75,4 @@ namespace Ocelot.UnitTests.Repository _httpContextAccesor.HttpContext.Items.TryGetValue(_key, out obj).ShouldBeTrue(); } } -} +} diff --git a/test/Ocelot.UnitTests/Request/Creator/DownstreamRequestCreatorTests.cs b/test/Ocelot.UnitTests/Request/Creator/DownstreamRequestCreatorTests.cs index f30f4cd8..32afcae9 100644 --- a/test/Ocelot.UnitTests/Request/Creator/DownstreamRequestCreatorTests.cs +++ b/test/Ocelot.UnitTests/Request/Creator/DownstreamRequestCreatorTests.cs @@ -1,12 +1,11 @@ -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Threading.Tasks; using Moq; using Ocelot.Infrastructure; using Ocelot.Request.Creator; using Ocelot.Request.Middleware; using Shouldly; +using System.Collections.Generic; +using System.Net.Http; +using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; @@ -47,7 +46,8 @@ namespace Ocelot.UnitTests.Request.Creator var content = new StringContent("test"); request.Content = content; - methods.ForEach(m => { + methods.ForEach(m => + { this.Given(_ => GivenTheFrameworkIs(".NET Framework")) .And(_ => GivenTheRequestIs(request)) .When(_ => WhenICreate()) diff --git a/test/Ocelot.UnitTests/Request/DownstreamRequestInitialiserMiddlewareTests.cs b/test/Ocelot.UnitTests/Request/DownstreamRequestInitialiserMiddlewareTests.cs index d571a8b7..93d963b6 100644 --- a/test/Ocelot.UnitTests/Request/DownstreamRequestInitialiserMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Request/DownstreamRequestInitialiserMiddlewareTests.cs @@ -2,38 +2,36 @@ namespace Ocelot.UnitTests.Request { - using System.Net.Http; using Microsoft.AspNetCore.Http; using Moq; + using Ocelot.Infrastructure; using Ocelot.Logging; + using Ocelot.Request.Creator; using Ocelot.Request.Mapper; using Ocelot.Request.Middleware; - using Ocelot.Infrastructure.RequestData; + using Ocelot.Responses; + using Shouldly; + using System.Net.Http; using TestStack.BDDfy; using Xunit; - using Ocelot.Responses; - using Ocelot.DownstreamRouteFinder.Middleware; - using Shouldly; - using Ocelot.Request.Creator; - using Ocelot.Infrastructure; public class DownstreamRequestInitialiserMiddlewareTests { - readonly DownstreamRequestInitialiserMiddleware _middleware; + private readonly DownstreamRequestInitialiserMiddleware _middleware; - readonly Mock _httpContext; + private readonly Mock _httpContext; - readonly Mock _httpRequest; + private readonly Mock _httpRequest; - readonly Mock _next; + private readonly Mock _next; - readonly Mock _requestMapper; + private readonly Mock _requestMapper; - readonly Mock _loggerFactory; + private readonly Mock _loggerFactory; - readonly Mock _logger; + private readonly Mock _logger; - Response _mappedRequest; + private Response _mappedRequest; private DownstreamContext _downstreamContext; public DownstreamRequestInitialiserMiddlewareTests() @@ -50,8 +48,8 @@ namespace Ocelot.UnitTests.Request .Returns(_logger.Object); _middleware = new DownstreamRequestInitialiserMiddleware( - _next.Object, - _loggerFactory.Object, + _next.Object, + _loggerFactory.Object, _requestMapper.Object, new DownstreamRequestCreator(new FrameworkDescription())); @@ -109,7 +107,7 @@ namespace Ocelot.UnitTests.Request private void WhenTheMiddlewareIsInvoked() { - _middleware.Invoke(_downstreamContext).GetAwaiter().GetResult(); + _middleware.Invoke(_downstreamContext).GetAwaiter().GetResult(); } private void ThenTheContexRequestIsMappedToADownstreamRequest() diff --git a/test/Ocelot.UnitTests/Request/DownstreamRequestTests.cs b/test/Ocelot.UnitTests/Request/DownstreamRequestTests.cs index eee88460..d5882951 100644 --- a/test/Ocelot.UnitTests/Request/DownstreamRequestTests.cs +++ b/test/Ocelot.UnitTests/Request/DownstreamRequestTests.cs @@ -1,7 +1,7 @@ -using System; -using System.Net.Http; using Ocelot.Request.Middleware; using Shouldly; +using System; +using System.Net.Http; using Xunit; namespace Ocelot.UnitTests.Request diff --git a/test/Ocelot.UnitTests/Request/Mapper/RequestMapperTests.cs b/test/Ocelot.UnitTests/Request/Mapper/RequestMapperTests.cs index 9be76e3f..1727d503 100644 --- a/test/Ocelot.UnitTests/Request/Mapper/RequestMapperTests.cs +++ b/test/Ocelot.UnitTests/Request/Mapper/RequestMapperTests.cs @@ -1,32 +1,31 @@ namespace Ocelot.UnitTests.Request.Mapper { - using System.Collections.Generic; - using System.Linq; - using System.Net.Http; - using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Internal; using Microsoft.Extensions.Primitives; using Ocelot.Request.Mapper; using Ocelot.Responses; - using TestStack.BDDfy; - using Xunit; using Shouldly; using System; + using System.Collections.Generic; using System.IO; - using System.Text; + using System.Linq; + using System.Net.Http; using System.Security.Cryptography; + using System.Text; using System.Threading.Tasks; + using TestStack.BDDfy; + using Xunit; public class RequestMapperTests { - readonly HttpRequest _inputRequest; + private readonly HttpRequest _inputRequest; - readonly RequestMapper _requestMapper; + private readonly RequestMapper _requestMapper; - Response _mappedRequest; + private Response _mappedRequest; - List> _inputHeaders = null; + private List> _inputHeaders = null; public RequestMapperTests() { @@ -210,9 +209,9 @@ .And(_ => ThenTheMappedRequestHasContentTypeHeader("application/json")) .And(_ => ThenTheMappedRequestHasContentSize("This is my content".Length)) .And(_ => ThenTheOtherContentTypeHeadersAreNotMapped()) - .BDDfy(); + .BDDfy(); } - + private void ThenTheContentHeadersAreNotAddedToNonContentHeaders() { _mappedRequest.Data.Headers.ShouldNotContain(x => x.Key == "Content-Disposition"); @@ -407,12 +406,12 @@ private void ThenTheMappedRequestHasEachHeader() { _mappedRequest.Data.Headers.Count().ShouldBe(_inputHeaders.Count); - foreach(var header in _mappedRequest.Data.Headers) + foreach (var header in _mappedRequest.Data.Headers) { var inputHeader = _inputHeaders.First(h => h.Key == header.Key); inputHeader.ShouldNotBeNull(); inputHeader.Value.Count().ShouldBe(header.Value.Count()); - foreach(var inputHeaderValue in inputHeader.Value) + foreach (var inputHeaderValue in inputHeader.Value) { header.Value.Any(v => v == inputHeaderValue); } diff --git a/test/Ocelot.UnitTests/RequestId/ReRouteRequestIdMiddlewareTests.cs b/test/Ocelot.UnitTests/RequestId/ReRouteRequestIdMiddlewareTests.cs index 44d9c405..5aebd7e5 100644 --- a/test/Ocelot.UnitTests/RequestId/ReRouteRequestIdMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/RequestId/ReRouteRequestIdMiddlewareTests.cs @@ -1,24 +1,24 @@ namespace Ocelot.UnitTests.RequestId { using Microsoft.AspNetCore.Http; + using Moq; + using Ocelot.Configuration.Builder; + using Ocelot.DownstreamRouteFinder; + using Ocelot.DownstreamRouteFinder.UrlMatcher; using Ocelot.Infrastructure.RequestData; + using Ocelot.Logging; + using Ocelot.Middleware; + using Ocelot.Request.Middleware; + using Ocelot.RequestId.Middleware; + using Ocelot.Responses; + using Shouldly; using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Threading.Tasks; - using Moq; - using Ocelot.Configuration.Builder; - using Ocelot.DownstreamRouteFinder; - using Ocelot.DownstreamRouteFinder.UrlMatcher; - using Ocelot.Logging; - using Ocelot.RequestId.Middleware; - using Ocelot.Responses; - using Shouldly; using TestStack.BDDfy; using Xunit; - using Ocelot.Request.Middleware; - using Ocelot.Middleware; public class ReRouteRequestIdMiddlewareTests { @@ -80,9 +80,9 @@ .WithDownstreamReRoute(new DownstreamReRouteBuilder() .WithDownstreamPathTemplate("any old string") .WithRequestIdKey("LSRequestId") - .WithUpstreamHttpMethod(new List {"Get"}) + .WithUpstreamHttpMethod(new List { "Get" }) .Build()) - .WithUpstreamHttpMethod(new List {"Get"}) + .WithUpstreamHttpMethod(new List { "Get" }) .Build()); this.Given(x => x.GivenTheDownStreamRouteIs(downstreamRoute)) @@ -100,9 +100,9 @@ .WithDownstreamReRoute(new DownstreamReRouteBuilder() .WithDownstreamPathTemplate("any old string") .WithRequestIdKey("LSRequestId") - .WithUpstreamHttpMethod(new List {"Get"}) + .WithUpstreamHttpMethod(new List { "Get" }) .Build()) - .WithUpstreamHttpMethod(new List {"Get"}) + .WithUpstreamHttpMethod(new List { "Get" }) .Build()); var requestId = Guid.NewGuid().ToString(); @@ -124,9 +124,9 @@ .WithDownstreamReRoute(new DownstreamReRouteBuilder() .WithDownstreamPathTemplate("any old string") .WithRequestIdKey("LSRequestId") - .WithUpstreamHttpMethod(new List {"Get"}) + .WithUpstreamHttpMethod(new List { "Get" }) .Build()) - .WithUpstreamHttpMethod(new List {"Get"}) + .WithUpstreamHttpMethod(new List { "Get" }) .Build()); var requestId = Guid.NewGuid().ToString(); @@ -219,4 +219,4 @@ value.First().ShouldBe(expected); } } -} +} diff --git a/test/Ocelot.UnitTests/Requester/DelegatingHandlerHandlerProviderFactoryTests.cs b/test/Ocelot.UnitTests/Requester/DelegatingHandlerHandlerProviderFactoryTests.cs index b1d0ff7b..2b2340ef 100644 --- a/test/Ocelot.UnitTests/Requester/DelegatingHandlerHandlerProviderFactoryTests.cs +++ b/test/Ocelot.UnitTests/Requester/DelegatingHandlerHandlerProviderFactoryTests.cs @@ -1,21 +1,20 @@ namespace Ocelot.UnitTests.Requester { - using System; - using System.Collections.Generic; - using System.Net.Http; using Microsoft.Extensions.DependencyInjection; using Moq; using Ocelot.Configuration; using Ocelot.Configuration.Builder; - using Ocelot.Errors; using Ocelot.Logging; using Ocelot.Requester; using Ocelot.Requester.QoS; using Ocelot.Responses; + using Responder; using Shouldly; + using System; + using System.Collections.Generic; + using System.Net.Http; using TestStack.BDDfy; using Xunit; - using Responder; public class DelegatingHandlerHandlerProviderFactoryTests { @@ -32,7 +31,7 @@ namespace Ocelot.UnitTests.Requester public DelegatingHandlerHandlerProviderFactoryTests() { - _qosDelegate = (a, b) => new FakeQoSHandler(); + _qosDelegate = (a, b) => new FakeQoSHandler(); _tracingFactory = new Mock(); _qosFactory = new Mock(); _loggerFactory = new Mock(); @@ -259,7 +258,7 @@ namespace Ocelot.UnitTests.Requester .Then(x => ThenThereIsDelegatesInProvider(3)) .And(x => ThenTheDelegatesAreAddedCorrectly()) .And(x => ThenItIsQosHandler(2)) - .BDDfy(); + .BDDfy(); } [Fact] @@ -401,17 +400,19 @@ namespace Ocelot.UnitTests.Requester .Returns(new FakeTracingHandler()); } - private void GivenTheServiceProviderReturnsGlobalDelegatingHandlers() + private void GivenTheServiceProviderReturnsGlobalDelegatingHandlers() where TOne : DelegatingHandler where TTwo : DelegatingHandler { _services.AddTransient(); - _services.AddTransient(s => { + _services.AddTransient(s => + { var service = s.GetService(); return new GlobalDelegatingHandler(service); }); _services.AddTransient(); - _services.AddTransient(s => { + _services.AddTransient(s => + { var service = s.GetService(); return new GlobalDelegatingHandler(service); }); @@ -440,11 +441,11 @@ namespace Ocelot.UnitTests.Requester var delegates = _result.Data; var del = delegates[0].Invoke(); - var handler = (FakeDelegatingHandler) del; + var handler = (FakeDelegatingHandler)del; handler.Order.ShouldBe(1); del = delegates[1].Invoke(); - var handlerTwo = (FakeDelegatingHandlerTwo) del; + var handlerTwo = (FakeDelegatingHandlerTwo)del; handlerTwo.Order.ShouldBe(2); } diff --git a/test/Ocelot.UnitTests/Requester/FakeDelegatingHandler.cs b/test/Ocelot.UnitTests/Requester/FakeDelegatingHandler.cs index c300c92c..e78fac8c 100644 --- a/test/Ocelot.UnitTests/Requester/FakeDelegatingHandler.cs +++ b/test/Ocelot.UnitTests/Requester/FakeDelegatingHandler.cs @@ -17,9 +17,9 @@ namespace Ocelot.UnitTests.Requester Order = order; } - public int Order {get;private set;} + public int Order { get; private set; } - public DateTime TimeCalled {get;private set;} + public DateTime TimeCalled { get; private set; } protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { @@ -71,9 +71,9 @@ namespace Ocelot.UnitTests.Requester Order = 2; } - public int Order {get;private set;} + public int Order { get; private set; } - public DateTime TimeCalled {get;private set;} + public DateTime TimeCalled { get; private set; } protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { diff --git a/test/Ocelot.UnitTests/Requester/HttpClientBuilderTests.cs b/test/Ocelot.UnitTests/Requester/HttpClientBuilderTests.cs index fc666144..34bf11c1 100644 --- a/test/Ocelot.UnitTests/Requester/HttpClientBuilderTests.cs +++ b/test/Ocelot.UnitTests/Requester/HttpClientBuilderTests.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Net; -using System.Net.Http; -using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; @@ -16,6 +10,12 @@ using Ocelot.Request.Middleware; using Ocelot.Requester; using Ocelot.Responses; using Shouldly; +using System; +using System.Collections.Generic; +using System.IO; +using System.Net; +using System.Net.Http; +using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; @@ -194,7 +194,7 @@ namespace Ocelot.UnitTests.Requester var fakeTwo = new FakeDelegatingHandler(); var handlers = new List>() - { + { () => fakeOne, () => fakeTwo }; @@ -396,7 +396,7 @@ namespace Ocelot.UnitTests.Requester private void GivenTheFactoryReturns() { - var handlers = new List>(){ () => new FakeDelegatingHandler()}; + var handlers = new List>() { () => new FakeDelegatingHandler() }; _factory .Setup(x => x.Get(It.IsAny())) @@ -414,9 +414,9 @@ namespace Ocelot.UnitTests.Requester private void GivenTheFactoryReturns(List> handlers) { - _factory - .Setup(x => x.Get(It.IsAny())) - .Returns(new OkResponse>>(handlers)); + _factory + .Setup(x => x.Get(It.IsAny())) + .Returns(new OkResponse>>(handlers)); } private void WhenIBuild() diff --git a/test/Ocelot.UnitTests/Requester/HttpClientHttpRequesterTest.cs b/test/Ocelot.UnitTests/Requester/HttpClientHttpRequesterTest.cs index 17b7f93a..53106d93 100644 --- a/test/Ocelot.UnitTests/Requester/HttpClientHttpRequesterTest.cs +++ b/test/Ocelot.UnitTests/Requester/HttpClientHttpRequesterTest.cs @@ -1,20 +1,20 @@ -using Moq; +using Microsoft.AspNetCore.Http; +using Moq; +using Ocelot.Configuration; +using Ocelot.Configuration.Builder; using Ocelot.Logging; +using Ocelot.Middleware; +using Ocelot.Request.Middleware; using Ocelot.Requester; using Ocelot.Responses; +using Shouldly; using System; using System.Collections.Generic; using System.Net.Http; -using Microsoft.AspNetCore.Http; -using Ocelot.Configuration; -using Ocelot.Configuration.Builder; -using Ocelot.Middleware; +using System.Threading; +using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; -using Shouldly; -using Ocelot.Request.Middleware; -using System.Threading.Tasks; -using System.Threading; namespace Ocelot.UnitTests.Requester { @@ -41,10 +41,10 @@ namespace Ocelot.UnitTests.Requester _cacheHandlers = new Mock(); _mapper = new Mock(); _httpClientRequester = new HttpClientHttpRequester( - _loggerFactory.Object, - _cacheHandlers.Object, + _loggerFactory.Object, + _cacheHandlers.Object, _factory.Object, - _mapper.Object); + _mapper.Object); } [Fact] @@ -69,9 +69,9 @@ namespace Ocelot.UnitTests.Requester DownstreamRequest = new DownstreamRequest(new HttpRequestMessage() { RequestUri = new Uri("http://www.bbc.co.uk") }), }; - this.Given(x=>x.GivenTheRequestIs(context)) + this.Given(x => x.GivenTheRequestIs(context)) .And(x => GivenTheHouseReturnsOkHandler()) - .When(x=>x.WhenIGetResponse()) + .When(x => x.WhenIGetResponse()) .Then(x => x.ThenTheResponseIsCalledCorrectly()) .BDDfy(); } @@ -136,7 +136,7 @@ namespace Ocelot.UnitTests.Requester private void GivenTheRequestIs(DownstreamContext request) { - _request = request; + _request = request; } private void WhenIGetResponse() @@ -182,7 +182,7 @@ namespace Ocelot.UnitTests.Requester _mapper.Setup(x => x.Map(It.IsAny())).Returns(new UnableToCompleteRequestError(new Exception())); } - class OkDelegatingHandler : DelegatingHandler + private class OkDelegatingHandler : DelegatingHandler { protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { @@ -190,7 +190,7 @@ namespace Ocelot.UnitTests.Requester } } - class TimeoutDelegatingHandler : DelegatingHandler + private class TimeoutDelegatingHandler : DelegatingHandler { protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { @@ -198,5 +198,5 @@ namespace Ocelot.UnitTests.Requester return new HttpResponseMessage(); } } - } + } } diff --git a/test/Ocelot.UnitTests/Requester/HttpExeptionToErrorMapperTests.cs b/test/Ocelot.UnitTests/Requester/HttpExeptionToErrorMapperTests.cs index 9f6358ea..bad8668e 100644 --- a/test/Ocelot.UnitTests/Requester/HttpExeptionToErrorMapperTests.cs +++ b/test/Ocelot.UnitTests/Requester/HttpExeptionToErrorMapperTests.cs @@ -1,13 +1,13 @@ namespace Ocelot.UnitTests.Requester { - using System; - using System.Collections.Generic; - using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Ocelot.Errors; using Ocelot.Requester; using Responder; using Shouldly; + using System; + using System.Collections.Generic; + using System.Threading.Tasks; using Xunit; public class HttpExeptionToErrorMapperTests diff --git a/test/Ocelot.UnitTests/Requester/HttpRequesterMiddlewareTests.cs b/test/Ocelot.UnitTests/Requester/HttpRequesterMiddlewareTests.cs index 910b3be8..a597df6b 100644 --- a/test/Ocelot.UnitTests/Requester/HttpRequesterMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Requester/HttpRequesterMiddlewareTests.cs @@ -1,21 +1,21 @@ namespace Ocelot.UnitTests.Requester { using Microsoft.AspNetCore.Http; - using System.Net.Http; using Moq; + using Ocelot.Configuration.Builder; using Ocelot.Logging; + using Ocelot.Middleware; using Ocelot.Requester; using Ocelot.Requester.Middleware; using Ocelot.Responses; - using TestStack.BDDfy; - using Xunit; + using Ocelot.UnitTests.Responder; using Shouldly; - using System.Threading.Tasks; - using Ocelot.Configuration.Builder; - using Ocelot.Middleware; using System; using System.Linq; - using Ocelot.UnitTests.Responder; + using System.Net.Http; + using System.Threading.Tasks; + using TestStack.BDDfy; + using Xunit; public class HttpRequesterMiddlewareTests { diff --git a/test/Ocelot.UnitTests/Requester/QoSFactoryTests.cs b/test/Ocelot.UnitTests/Requester/QoSFactoryTests.cs index 4caedc53..93c1c58e 100644 --- a/test/Ocelot.UnitTests/Requester/QoSFactoryTests.cs +++ b/test/Ocelot.UnitTests/Requester/QoSFactoryTests.cs @@ -1,6 +1,5 @@ namespace Ocelot.UnitTests.Requester { - using System.Net.Http; using Microsoft.Extensions.DependencyInjection; using Moq; using Ocelot.Configuration; @@ -9,6 +8,7 @@ using Ocelot.Requester; using Ocelot.Requester.QoS; using Shouldly; + using System.Net.Http; using Xunit; public class QoSFactoryTests @@ -48,7 +48,7 @@ handler.Data.ShouldBeOfType(); } - class FakeDelegatingHandler : DelegatingHandler + private class FakeDelegatingHandler : DelegatingHandler { } } diff --git a/test/Ocelot.UnitTests/Requester/TracingHandlerFactoryTests.cs b/test/Ocelot.UnitTests/Requester/TracingHandlerFactoryTests.cs index 146af701..6e40a895 100644 --- a/test/Ocelot.UnitTests/Requester/TracingHandlerFactoryTests.cs +++ b/test/Ocelot.UnitTests/Requester/TracingHandlerFactoryTests.cs @@ -1,13 +1,13 @@ namespace Ocelot.UnitTests.Requester { - using System; using Microsoft.Extensions.DependencyInjection; using Moq; using Ocelot.Infrastructure.RequestData; + using Ocelot.Logging; using Ocelot.Requester; using Shouldly; + using System; using Xunit; - using Ocelot.Logging; public class TracingHandlerFactoryTests { diff --git a/test/Ocelot.UnitTests/Responder/AnyError.cs b/test/Ocelot.UnitTests/Responder/AnyError.cs index 1dd466a4..9d7b2cd4 100644 --- a/test/Ocelot.UnitTests/Responder/AnyError.cs +++ b/test/Ocelot.UnitTests/Responder/AnyError.cs @@ -2,7 +2,7 @@ namespace Ocelot.UnitTests.Responder { - class AnyError : Error + internal class AnyError : Error { public AnyError() : base("blahh", OcelotErrorCode.UnknownError) { @@ -12,4 +12,4 @@ namespace Ocelot.UnitTests.Responder { } } -} +} diff --git a/test/Ocelot.UnitTests/Responder/HttpContextResponderTests.cs b/test/Ocelot.UnitTests/Responder/HttpContextResponderTests.cs index 89e8a045..bd485c03 100644 --- a/test/Ocelot.UnitTests/Responder/HttpContextResponderTests.cs +++ b/test/Ocelot.UnitTests/Responder/HttpContextResponderTests.cs @@ -1,14 +1,13 @@ -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Net.Http; -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Ocelot.Headers; using Ocelot.Middleware; -using Ocelot.Middleware.Multiplexer; using Ocelot.Responder; using Shouldly; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; using Xunit; namespace Ocelot.UnitTests.Responder @@ -83,7 +82,6 @@ namespace Ocelot.UnitTests.Responder header.First().ShouldBe("test"); } - [Fact] public void should_add_reason_phrase() { diff --git a/test/Ocelot.UnitTests/Responder/ResponderMiddlewareTests.cs b/test/Ocelot.UnitTests/Responder/ResponderMiddlewareTests.cs index 79262997..de7ab9d3 100644 --- a/test/Ocelot.UnitTests/Responder/ResponderMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Responder/ResponderMiddlewareTests.cs @@ -1,18 +1,16 @@ -using System.Collections.Generic; -using Ocelot.Middleware; -using Ocelot.Middleware.Multiplexer; +using Ocelot.Middleware; namespace Ocelot.UnitTests.Responder { using Microsoft.AspNetCore.Http; - using System.Net.Http; - using System.Threading.Tasks; using Moq; using Ocelot.DownstreamRouteFinder.Finder; using Ocelot.Errors; using Ocelot.Logging; using Ocelot.Responder; using Ocelot.Responder.Middleware; + using System.Net.Http; + using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; @@ -75,6 +73,6 @@ namespace Ocelot.UnitTests.Responder private void GivenThereArePipelineErrors(Error error) { _downstreamContext.Errors.Add(error); - } + } } -} +} diff --git a/test/Ocelot.UnitTests/Security/IPSecurityPolicyTests.cs b/test/Ocelot.UnitTests/Security/IPSecurityPolicyTests.cs index 5e4062ae..637048f5 100644 --- a/test/Ocelot.UnitTests/Security/IPSecurityPolicyTests.cs +++ b/test/Ocelot.UnitTests/Security/IPSecurityPolicyTests.cs @@ -5,11 +5,9 @@ using Ocelot.Middleware; using Ocelot.Request.Middleware; using Ocelot.Responses; using Ocelot.Security.IPSecurity; -using System; using System.Collections.Generic; using System.Net; using System.Net.Http; -using System.Text; using TestStack.BDDfy; using Xunit; @@ -21,6 +19,7 @@ namespace Ocelot.UnitTests.Security private readonly DownstreamReRouteBuilder _downstreamReRouteBuilder; private readonly IPSecurityPolicy _ipSecurityPolicy; private Response response; + public IPSecurityPolicyTests() { _downstreamContext = new DownstreamContext(new DefaultHttpContext()); @@ -61,7 +60,6 @@ namespace Ocelot.UnitTests.Security .BDDfy(); } - [Fact] private void should_allowedIp_clientIp_block() { diff --git a/test/Ocelot.UnitTests/Security/SecurityMiddlewareTests.cs b/test/Ocelot.UnitTests/Security/SecurityMiddlewareTests.cs index d7d38140..7d2b3d89 100644 --- a/test/Ocelot.UnitTests/Security/SecurityMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Security/SecurityMiddlewareTests.cs @@ -6,13 +6,10 @@ using Ocelot.Middleware; using Ocelot.Request.Middleware; using Ocelot.Responses; using Ocelot.Security; -using Ocelot.Security.IPSecurity; using Ocelot.Security.Middleware; -using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; -using System.Text; using System.Threading.Tasks; using TestStack.BDDfy; using Xunit; @@ -44,6 +41,7 @@ namespace Ocelot.UnitTests.Security _downstreamContext = new DownstreamContext(new DefaultHttpContext()); _downstreamContext.DownstreamRequest = new DownstreamRequest(new HttpRequestMessage(HttpMethod.Get, "http://test.com")); } + [Fact] public void should_legal_request() { diff --git a/test/Ocelot.UnitTests/ServiceDiscovery/ConfigurationServiceProviderTests.cs b/test/Ocelot.UnitTests/ServiceDiscovery/ConfigurationServiceProviderTests.cs index 60555435..1faed24a 100644 --- a/test/Ocelot.UnitTests/ServiceDiscovery/ConfigurationServiceProviderTests.cs +++ b/test/Ocelot.UnitTests/ServiceDiscovery/ConfigurationServiceProviderTests.cs @@ -1,8 +1,7 @@ -using System.Collections.Generic; -using Ocelot.ServiceDiscovery; using Ocelot.ServiceDiscovery.Providers; using Ocelot.Values; using Shouldly; +using System.Collections.Generic; using TestStack.BDDfy; using Xunit; @@ -50,4 +49,4 @@ namespace Ocelot.UnitTests.ServiceDiscovery _result[0].Name.ShouldBe(services[0].Name); } } -} +} diff --git a/test/Ocelot.UnitTests/ServiceDiscovery/ServiceDiscoveryProviderFactoryTests.cs b/test/Ocelot.UnitTests/ServiceDiscovery/ServiceDiscoveryProviderFactoryTests.cs index 46cec86e..0b5362ed 100644 --- a/test/Ocelot.UnitTests/ServiceDiscovery/ServiceDiscoveryProviderFactoryTests.cs +++ b/test/Ocelot.UnitTests/ServiceDiscovery/ServiceDiscoveryProviderFactoryTests.cs @@ -1,20 +1,20 @@ namespace Ocelot.UnitTests.ServiceDiscovery { - using System; - using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; - using Values; - using System.Collections.Generic; using Moq; using Ocelot.Configuration; using Ocelot.Configuration.Builder; using Ocelot.Logging; + using Ocelot.Responses; using Ocelot.ServiceDiscovery; using Ocelot.ServiceDiscovery.Providers; using Shouldly; + using System; + using System.Collections.Generic; + using System.Threading.Tasks; using TestStack.BDDfy; + using Values; using Xunit; - using Ocelot.Responses; public class ServiceDiscoveryProviderFactoryTests { @@ -35,7 +35,7 @@ namespace Ocelot.UnitTests.ServiceDiscovery _provider = _collection.BuildServiceProvider(); _factory = new ServiceDiscoveryProviderFactory(_loggerFactory.Object, _provider); } - + [Fact] public void should_return_no_service_provider() { @@ -135,7 +135,7 @@ namespace Ocelot.UnitTests.ServiceDiscovery _factory = new ServiceDiscoveryProviderFactory(_loggerFactory.Object, _provider); } - class Fake : IServiceDiscoveryProvider + private class Fake : IServiceDiscoveryProvider { public Task> Get() { @@ -157,7 +157,7 @@ namespace Ocelot.UnitTests.ServiceDiscovery { var result = (ConfigurationServiceProvider)_result.Data; var services = result.Get().Result; - + for (int i = 0; i < services.Count; i++) { var service = services[i]; diff --git a/test/Ocelot.UnitTests/ServiceDiscovery/ServiceFabricServiceDiscoveryProviderTests.cs b/test/Ocelot.UnitTests/ServiceDiscovery/ServiceFabricServiceDiscoveryProviderTests.cs index a9020e3e..7056556e 100644 --- a/test/Ocelot.UnitTests/ServiceDiscovery/ServiceFabricServiceDiscoveryProviderTests.cs +++ b/test/Ocelot.UnitTests/ServiceDiscovery/ServiceFabricServiceDiscoveryProviderTests.cs @@ -1,12 +1,12 @@ namespace Ocelot.UnitTests.ServiceDiscovery { - using System.Collections.Generic; - using Ocelot.Values; - using Xunit; - using TestStack.BDDfy; - using Shouldly; using Ocelot.ServiceDiscovery.Configuration; using Ocelot.ServiceDiscovery.Providers; + using Ocelot.Values; + using Shouldly; + using System.Collections.Generic; + using TestStack.BDDfy; + using Xunit; public class ServiceFabricServiceDiscoveryProviderTests { diff --git a/test/Ocelot.UnitTests/ServiceDiscovery/ServiceRegistryTests.cs b/test/Ocelot.UnitTests/ServiceDiscovery/ServiceRegistryTests.cs index 1079f201..e27d5e78 100644 --- a/test/Ocelot.UnitTests/ServiceDiscovery/ServiceRegistryTests.cs +++ b/test/Ocelot.UnitTests/ServiceDiscovery/ServiceRegistryTests.cs @@ -1,6 +1,6 @@ -using System.Collections.Generic; using Ocelot.Values; using Shouldly; +using System.Collections.Generic; using TestStack.BDDfy; using Xunit; @@ -78,17 +78,19 @@ namespace Ocelot.UnitTests.ServiceDiscovery public interface IServiceRegistry { void Register(Service serviceNameAndAddress); + List Lookup(string name); } public class ServiceRegistry : IServiceRegistry { private readonly IServiceRepository _repository; + public ServiceRegistry(IServiceRepository repository) { _repository = repository; - } - + } + public void Register(Service serviceNameAndAddress) { _repository.Set(serviceNameAndAddress); @@ -103,6 +105,7 @@ namespace Ocelot.UnitTests.ServiceDiscovery public interface IServiceRepository { List Get(string serviceName); + void Set(Service serviceNameAndAddress); } @@ -123,15 +126,15 @@ namespace Ocelot.UnitTests.ServiceDiscovery public void Set(Service serviceNameAndAddress) { List services; - if(_registeredServices.TryGetValue(serviceNameAndAddress.Name, out services)) + if (_registeredServices.TryGetValue(serviceNameAndAddress.Name, out services)) { services.Add(serviceNameAndAddress); _registeredServices[serviceNameAndAddress.Name] = services; } else - { - _registeredServices[serviceNameAndAddress.Name] = new List(){ serviceNameAndAddress }; - } + { + _registeredServices[serviceNameAndAddress.Name] = new List() { serviceNameAndAddress }; + } } } -} +} diff --git a/test/Ocelot.UnitTests/appsettings.json b/test/Ocelot.UnitTests/appsettings.json index 455361cb..247f1ad7 100644 --- a/test/Ocelot.UnitTests/appsettings.json +++ b/test/Ocelot.UnitTests/appsettings.json @@ -18,7 +18,7 @@ "shouldRegisterWithEureka": true, "shouldFetchRegistry": true, "port": 5000, - "hostName": "localhost" + "hostName": "localhost" } } }