diff --git a/Ocelot.sln b/Ocelot.sln index e966a5ae..c9ac2782 100644 --- a/Ocelot.sln +++ b/Ocelot.sln @@ -12,6 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution build-and-run-tests.ps1 = build-and-run-tests.ps1 build.cake = build.cake build.ps1 = build.ps1 + codeanalysis.ruleset = codeanalysis.ruleset GitVersion.yml = GitVersion.yml global.json = global.json LICENSE.md = LICENSE.md @@ -39,14 +40,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ocelot.Benchmarks", "test\O EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ocelot.IntegrationTests", "test\Ocelot.IntegrationTests\Ocelot.IntegrationTests.csproj", "{D4575572-99CA-4530-8737-C296EDA326F8}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{E78EF991-3401-459A-94FE-EC4F4E5BD702}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OcelotApplicationApiGateway", "samples\OcelotServiceFabric\src\OcelotApplicationApiGateway\OcelotApplicationApiGateway.csproj", "{1A3A3D97-33AB-48FB-8A9F-92905A15DF74}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OcelotApplicationService", "samples\OcelotServiceFabric\src\OcelotApplicationService\OcelotApplicationService.csproj", "{272DD79B-7D04-4DFB-BB64-B1C098CE8050}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "OcelotServiceFabric", "OcelotServiceFabric", "{98424512-BCF5-4F42-ACB2-6D7040D92487}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -77,14 +70,6 @@ Global {D4575572-99CA-4530-8737-C296EDA326F8}.Debug|Any CPU.Build.0 = Debug|Any CPU {D4575572-99CA-4530-8737-C296EDA326F8}.Release|Any CPU.ActiveCfg = Release|Any CPU {D4575572-99CA-4530-8737-C296EDA326F8}.Release|Any CPU.Build.0 = Release|Any CPU - {1A3A3D97-33AB-48FB-8A9F-92905A15DF74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1A3A3D97-33AB-48FB-8A9F-92905A15DF74}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1A3A3D97-33AB-48FB-8A9F-92905A15DF74}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1A3A3D97-33AB-48FB-8A9F-92905A15DF74}.Release|Any CPU.Build.0 = Release|Any CPU - {272DD79B-7D04-4DFB-BB64-B1C098CE8050}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {272DD79B-7D04-4DFB-BB64-B1C098CE8050}.Debug|Any CPU.Build.0 = Debug|Any CPU - {272DD79B-7D04-4DFB-BB64-B1C098CE8050}.Release|Any CPU.ActiveCfg = Release|Any CPU - {272DD79B-7D04-4DFB-BB64-B1C098CE8050}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -96,9 +81,6 @@ Global {02BBF4C5-517E-4157-8D21-4B8B9E118B7A} = {5B401523-36DA-4491-B73A-7590A26E420B} {106B49E6-95F6-4A7B-B81C-96BFA74AF035} = {5B401523-36DA-4491-B73A-7590A26E420B} {D4575572-99CA-4530-8737-C296EDA326F8} = {5B401523-36DA-4491-B73A-7590A26E420B} - {1A3A3D97-33AB-48FB-8A9F-92905A15DF74} = {98424512-BCF5-4F42-ACB2-6D7040D92487} - {272DD79B-7D04-4DFB-BB64-B1C098CE8050} = {98424512-BCF5-4F42-ACB2-6D7040D92487} - {98424512-BCF5-4F42-ACB2-6D7040D92487} = {E78EF991-3401-459A-94FE-EC4F4E5BD702} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {21476EFF-778A-4F97-8A56-D1AF1CEC0C48} diff --git a/codeanalysis.ruleset b/codeanalysis.ruleset new file mode 100644 index 00000000..ee66e99d --- /dev/null +++ b/codeanalysis.ruleset @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Ocelot/Authentication/Middleware/AuthenticationMiddleware.cs b/src/Ocelot/Authentication/Middleware/AuthenticationMiddleware.cs index ffdd1ac6..bd4683d0 100644 --- a/src/Ocelot/Authentication/Middleware/AuthenticationMiddleware.cs +++ b/src/Ocelot/Authentication/Middleware/AuthenticationMiddleware.cs @@ -63,4 +63,3 @@ namespace Ocelot.Authentication.Middleware } } } - diff --git a/src/Ocelot/Authorisation/ClaimsAuthoriser.cs b/src/Ocelot/Authorisation/ClaimsAuthoriser.cs index 4db1045c..3ca7809e 100644 --- a/src/Ocelot/Authorisation/ClaimsAuthoriser.cs +++ b/src/Ocelot/Authorisation/ClaimsAuthoriser.cs @@ -47,7 +47,8 @@ namespace Ocelot.Authorisation }); } } + return new OkResponse(true); } } -} \ No newline at end of file +} diff --git a/src/Ocelot/Cache/Middleware/OutputCacheMiddleware.cs b/src/Ocelot/Cache/Middleware/OutputCacheMiddleware.cs index 873c4cf7..3d128b72 100644 --- a/src/Ocelot/Cache/Middleware/OutputCacheMiddleware.cs +++ b/src/Ocelot/Cache/Middleware/OutputCacheMiddleware.cs @@ -123,7 +123,6 @@ namespace Ocelot.Cache.Middleware var contentHeaders = response?.Content?.Headers.ToDictionary(v => v.Key, v => v.Value); - var cached = new CachedResponse(statusCode, headers, body, contentHeaders); return cached; } diff --git a/src/Ocelot/Cache/RegionCreator.cs b/src/Ocelot/Cache/RegionCreator.cs index e2ca874b..f5a94c21 100644 --- a/src/Ocelot/Cache/RegionCreator.cs +++ b/src/Ocelot/Cache/RegionCreator.cs @@ -4,7 +4,6 @@ using Ocelot.Configuration.File; namespace Ocelot.Cache { - public class RegionCreator : IRegionCreator { public string Create(FileReRoute reRoute) @@ -21,4 +20,4 @@ namespace Ocelot.Cache return region; } } -} \ No newline at end of file +} diff --git a/src/Ocelot/Cache/Regions.cs b/src/Ocelot/Cache/Regions.cs index f94cc306..baec6087 100644 --- a/src/Ocelot/Cache/Regions.cs +++ b/src/Ocelot/Cache/Regions.cs @@ -8,6 +8,7 @@ namespace Ocelot.Cache { Value = value; } + public List Value {get;private set;} } -} \ No newline at end of file +} diff --git a/src/Ocelot/Claims/Middleware/ClaimsBuilderMiddleware.cs b/src/Ocelot/Claims/Middleware/ClaimsBuilderMiddleware.cs index 5161b247..48f57834 100644 --- a/src/Ocelot/Claims/Middleware/ClaimsBuilderMiddleware.cs +++ b/src/Ocelot/Claims/Middleware/ClaimsBuilderMiddleware.cs @@ -39,6 +39,7 @@ namespace Ocelot.Claims.Middleware return; } } + await _next.Invoke(context); } } diff --git a/src/Ocelot/Configuration/Builder/DownstreamReRouteBuilder.cs b/src/Ocelot/Configuration/Builder/DownstreamReRouteBuilder.cs index 0e7509b9..5f82f688 100644 --- a/src/Ocelot/Configuration/Builder/DownstreamReRouteBuilder.cs +++ b/src/Ocelot/Configuration/Builder/DownstreamReRouteBuilder.cs @@ -215,7 +215,6 @@ namespace Ocelot.Configuration.Builder return this; } - public DownstreamReRoute Build() { return new DownstreamReRoute( diff --git a/src/Ocelot/Configuration/Creator/FileOcelotConfigurationCreator.cs b/src/Ocelot/Configuration/Creator/FileOcelotConfigurationCreator.cs index fbc58020..a35c7d54 100644 --- a/src/Ocelot/Configuration/Creator/FileOcelotConfigurationCreator.cs +++ b/src/Ocelot/Configuration/Creator/FileOcelotConfigurationCreator.cs @@ -35,7 +35,6 @@ namespace Ocelot.Configuration.Creator private readonly IHeaderFindAndReplaceCreator _headerFAndRCreator; private readonly IDownstreamAddressesCreator _downstreamAddressesCreator; - public FileOcelotConfigurationCreator( IOptions options, IConfigurationValidator configurationValidator, diff --git a/src/Ocelot/Configuration/Creator/UpstreamTemplatePatternCreator.cs b/src/Ocelot/Configuration/Creator/UpstreamTemplatePatternCreator.cs index 1700472a..833c61db 100644 --- a/src/Ocelot/Configuration/Creator/UpstreamTemplatePatternCreator.cs +++ b/src/Ocelot/Configuration/Creator/UpstreamTemplatePatternCreator.cs @@ -67,7 +67,6 @@ namespace Ocelot.Configuration.Creator return false; } - private bool IsPlaceHolder(string upstreamTemplate, int i) { return upstreamTemplate[i] == '{'; diff --git a/src/Ocelot/Configuration/DownstreamHostAndPort.cs b/src/Ocelot/Configuration/DownstreamHostAndPort.cs index 483e7523..186cce2f 100644 --- a/src/Ocelot/Configuration/DownstreamHostAndPort.cs +++ b/src/Ocelot/Configuration/DownstreamHostAndPort.cs @@ -7,6 +7,7 @@ Host = host; Port = port; } + public string Host { get; private set; } public int Port { get; private set; } } diff --git a/src/Ocelot/Configuration/File/FileConfiguration.cs b/src/Ocelot/Configuration/File/FileConfiguration.cs index 6d73ce3f..e38ae6cb 100644 --- a/src/Ocelot/Configuration/File/FileConfiguration.cs +++ b/src/Ocelot/Configuration/File/FileConfiguration.cs @@ -12,6 +12,7 @@ namespace Ocelot.Configuration.File } public List ReRoutes { get; set; } + // Seperate field for aggregates because this let's you re-use ReRoutes in multiple Aggregates 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 adbbdce1..8dea9ed6 100644 --- a/src/Ocelot/Configuration/File/FileGlobalConfiguration.cs +++ b/src/Ocelot/Configuration/File/FileGlobalConfiguration.cs @@ -1,5 +1,4 @@ - -namespace Ocelot.Configuration.File +namespace Ocelot.Configuration.File { public class FileGlobalConfiguration { diff --git a/src/Ocelot/Configuration/File/FileRateLimitOptions.cs b/src/Ocelot/Configuration/File/FileRateLimitOptions.cs index b9277a3c..c7f99cb0 100644 --- a/src/Ocelot/Configuration/File/FileRateLimitOptions.cs +++ b/src/Ocelot/Configuration/File/FileRateLimitOptions.cs @@ -34,6 +34,4 @@ namespace Ocelot.Configuration.File /// public int HttpStatusCode { get; set; } = 429; } - - } diff --git a/src/Ocelot/Configuration/File/FileRateLimitRule.cs b/src/Ocelot/Configuration/File/FileRateLimitRule.cs index 55346d2e..5e1616e6 100644 --- a/src/Ocelot/Configuration/File/FileRateLimitRule.cs +++ b/src/Ocelot/Configuration/File/FileRateLimitRule.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; namespace Ocelot.Configuration.File { - public class FileRateLimitRule { public FileRateLimitRule() @@ -27,6 +26,7 @@ namespace Ocelot.Configuration.File public string Period { get; set; } public double PeriodTimespan { get; set; } + /// /// Maximum number of requests that a client can make in a defined period /// @@ -38,6 +38,7 @@ namespace Ocelot.Configuration.File { return string.Empty; } + var sb = new StringBuilder(); sb.Append( $"{nameof(Period)}:{Period},{nameof(PeriodTimespan)}:{PeriodTimespan:F},{nameof(Limit)}:{Limit},{nameof(ClientWhitelist)}:["); diff --git a/src/Ocelot/Configuration/QoSOptions.cs b/src/Ocelot/Configuration/QoSOptions.cs index c518cfec..651bd506 100644 --- a/src/Ocelot/Configuration/QoSOptions.cs +++ b/src/Ocelot/Configuration/QoSOptions.cs @@ -14,8 +14,7 @@ namespace Ocelot.Configuration DurationOfBreak = durationofBreak; TimeoutValue = timeoutValue; TimeoutStrategy = timeoutStrategy; - } - + } public int ExceptionsAllowedBeforeBreaking { get; private set; } @@ -24,6 +23,5 @@ namespace Ocelot.Configuration public int TimeoutValue { get; private set; } public TimeoutStrategy TimeoutStrategy { get; private set; } - } } diff --git a/src/Ocelot/Configuration/RateLimitRule.cs b/src/Ocelot/Configuration/RateLimitRule.cs index d77919ae..9240087c 100644 --- a/src/Ocelot/Configuration/RateLimitRule.cs +++ b/src/Ocelot/Configuration/RateLimitRule.cs @@ -17,9 +17,10 @@ namespace Ocelot.Configuration public string Period { 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; } } -} \ No newline at end of file +} diff --git a/src/Ocelot/Configuration/ReRouteOptions.cs b/src/Ocelot/Configuration/ReRouteOptions.cs index 5ec316c3..e3a7a7b1 100644 --- a/src/Ocelot/Configuration/ReRouteOptions.cs +++ b/src/Ocelot/Configuration/ReRouteOptions.cs @@ -9,12 +9,12 @@ namespace Ocelot.Configuration IsCached = isCached; IsQos = isQos; EnableRateLimiting = isEnableRateLimiting; - } + public bool IsAuthenticated { get; private set; } public bool IsAuthorised { get; private set; } public bool IsCached { get; private set; } public bool IsQos { get; private set; } public bool EnableRateLimiting { get; private set; } } -} \ No newline at end of file +} diff --git a/src/Ocelot/Configuration/Repository/ConsulFileConfigurationPoller.cs b/src/Ocelot/Configuration/Repository/ConsulFileConfigurationPoller.cs index 7e78b3aa..a2780062 100644 --- a/src/Ocelot/Configuration/Repository/ConsulFileConfigurationPoller.cs +++ b/src/Ocelot/Configuration/Repository/ConsulFileConfigurationPoller.cs @@ -34,7 +34,6 @@ namespace Ocelot.Configuration.Repository _polling = true; await Poll(); _polling = false; - }, null, 0, 1000); } diff --git a/src/Ocelot/Configuration/Repository/ConsulFileConfigurationRepository.cs b/src/Ocelot/Configuration/Repository/ConsulFileConfigurationRepository.cs index 13c128b9..97bf7c97 100644 --- a/src/Ocelot/Configuration/Repository/ConsulFileConfigurationRepository.cs +++ b/src/Ocelot/Configuration/Repository/ConsulFileConfigurationRepository.cs @@ -9,7 +9,6 @@ using Ocelot.ServiceDiscovery; namespace Ocelot.Configuration.Repository { - public class ConsulFileConfigurationRepository : IFileConfigurationRepository { private readonly ConsulClient _consul; diff --git a/src/Ocelot/Configuration/ServiceProviderConfiguraion.cs b/src/Ocelot/Configuration/ServiceProviderConfiguration.cs similarity index 95% rename from src/Ocelot/Configuration/ServiceProviderConfiguraion.cs rename to src/Ocelot/Configuration/ServiceProviderConfiguration.cs index 9df16ea2..aa7c492c 100644 --- a/src/Ocelot/Configuration/ServiceProviderConfiguraion.cs +++ b/src/Ocelot/Configuration/ServiceProviderConfiguration.cs @@ -1,16 +1,16 @@ -namespace Ocelot.Configuration -{ - public class ServiceProviderConfiguration - { - public ServiceProviderConfiguration(string type, string host, int port) - { - Host = host; - Port = port; - Type = type; - } - - public string Host { get; private set; } - public int Port { get; private set; } - public string Type { get; private set; } - } -} +namespace Ocelot.Configuration +{ + public class ServiceProviderConfiguration + { + public ServiceProviderConfiguration(string type, string host, int port) + { + Host = host; + Port = port; + Type = type; + } + + public string Host { get; private set; } + public int Port { get; private set; } + public string Type { get; private set; } + } +} \ No newline at end of file diff --git a/src/Ocelot/Configuration/Setter/FileConfigurationSetter.cs b/src/Ocelot/Configuration/Setter/FileConfigurationSetter.cs index 71f56277..38a7c1cb 100644 --- a/src/Ocelot/Configuration/Setter/FileConfigurationSetter.cs +++ b/src/Ocelot/Configuration/Setter/FileConfigurationSetter.cs @@ -12,7 +12,7 @@ namespace Ocelot.Configuration.Setter private readonly IOcelotConfigurationCreator _configCreator; private readonly IFileConfigurationRepository _repo; - public FileConfigurationSetter(IOcelotConfigurationRepository configRepo, + public FileConfigurationSetter(IOcelotConfigurationRepository configRepo, IOcelotConfigurationCreator configCreator, IFileConfigurationRepository repo) { _configRepo = configRepo; @@ -39,4 +39,4 @@ namespace Ocelot.Configuration.Setter return new ErrorResponse(config.Errors); } } -} \ No newline at end of file +} diff --git a/src/Ocelot/Configuration/Validator/FileValidationFailedError.cs b/src/Ocelot/Configuration/Validator/FileValidationFailedError.cs index b661e065..e90aa218 100644 --- a/src/Ocelot/Configuration/Validator/FileValidationFailedError.cs +++ b/src/Ocelot/Configuration/Validator/FileValidationFailedError.cs @@ -9,7 +9,6 @@ namespace Ocelot.Configuration.Validator { public FileValidationFailedError(string message) : base(message, OcelotErrorCode.FileValidationFailedError) { - } } } diff --git a/src/Ocelot/Configuration/Validator/ReRouteFluentValidator.cs b/src/Ocelot/Configuration/Validator/ReRouteFluentValidator.cs index f2ebbace..c2f4dc62 100644 --- a/src/Ocelot/Configuration/Validator/ReRouteFluentValidator.cs +++ b/src/Ocelot/Configuration/Validator/ReRouteFluentValidator.cs @@ -67,6 +67,7 @@ namespace Ocelot.Configuration.Validator { return true; } + var schemes = await _authenticationSchemeProvider.GetAllSchemesAsync(); var supportedSchemes = schemes.Select(scheme => scheme.Name).ToList(); diff --git a/src/Ocelot/DependencyInjection/OcelotBuilder.cs b/src/Ocelot/DependencyInjection/OcelotBuilder.cs index ccd2a9be..e1ef6b42 100644 --- a/src/Ocelot/DependencyInjection/OcelotBuilder.cs +++ b/src/Ocelot/DependencyInjection/OcelotBuilder.cs @@ -125,7 +125,7 @@ namespace Ocelot.DependencyInjection // see this for why we register this as singleton http://stackoverflow.com/questions/37371264/invalidoperationexception-unable-to-resolve-service-for-type-microsoft-aspnetc // could maybe use a scoped data repository - _services.TryAddSingleton(); + _services.TryAddSingleton(); _services.TryAddSingleton(); _services.AddMemoryCache(); _services.TryAddSingleton(); @@ -153,7 +153,6 @@ namespace Ocelot.DependencyInjection // We add this here so that we can always inject something into the factory for IoC.. _services.AddSingleton(); - } public IOcelotAdministrationBuilder AddAdministration(string path, string secret) @@ -264,8 +263,7 @@ namespace Ocelot.DependencyInjection var urlFinder = new BaseUrlFinder(_configurationRoot); var baseSchemeUrlAndPort = urlFinder.Find(); - JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); - + JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); _services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme) .AddIdentityServerAuthentication(o => diff --git a/src/Ocelot/DownstreamRouteFinder/DownstreamRoute.cs b/src/Ocelot/DownstreamRouteFinder/DownstreamRoute.cs index ed04daef..c7696ecf 100644 --- a/src/Ocelot/DownstreamRouteFinder/DownstreamRoute.cs +++ b/src/Ocelot/DownstreamRouteFinder/DownstreamRoute.cs @@ -11,7 +11,8 @@ namespace Ocelot.DownstreamRouteFinder TemplatePlaceholderNameAndValues = templatePlaceholderNameAndValues; ReRoute = reRoute; } + public List TemplatePlaceholderNameAndValues { get; private set; } public ReRoute ReRoute { get; private set; } } -} \ No newline at end of file +} diff --git a/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs b/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs index 4b467b95..c9da50a4 100644 --- a/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs +++ b/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs @@ -17,7 +17,6 @@ namespace Ocelot.DownstreamRouteFinder.Middleware private readonly IOcelotConfigurationProvider _configProvider; private readonly IMultiplexer _multiplexer; - public DownstreamRouteFinderMiddleware(OcelotRequestDelegate next, IOcelotLoggerFactory loggerFactory, IDownstreamRouteFinder downstreamRouteFinder, @@ -60,8 +59,8 @@ namespace Ocelot.DownstreamRouteFinder.Middleware return; } - //todo - put this back in - // _logger.LogDebug("downstream template is {downstreamRoute.Data.ReRoute.DownstreamPath}", downstreamRoute.Data.ReRoute.DownstreamReRoute.DownstreamPathTemplate); + // todo - put this back in + //// _logger.LogDebug("downstream template is {downstreamRoute.Data.ReRoute.DownstreamPath}", downstreamRoute.Data.ReRoute.DownstreamReRoute.DownstreamPathTemplate); context.TemplatePlaceholderNameAndValues = downstreamRoute.Data.TemplatePlaceholderNameAndValues; diff --git a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/IUrlPathPlaceholderNameAndValueFinder.cs b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/IPlaceholderNameAndValueFinder.cs similarity index 96% rename from src/Ocelot/DownstreamRouteFinder/UrlMatcher/IUrlPathPlaceholderNameAndValueFinder.cs rename to src/Ocelot/DownstreamRouteFinder/UrlMatcher/IPlaceholderNameAndValueFinder.cs index d2cb4167..678b1081 100644 --- a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/IUrlPathPlaceholderNameAndValueFinder.cs +++ b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/IPlaceholderNameAndValueFinder.cs @@ -1,10 +1,10 @@ -using System.Collections.Generic; -using Ocelot.Responses; - -namespace Ocelot.DownstreamRouteFinder.UrlMatcher -{ - public interface IPlaceholderNameAndValueFinder - { - Response> Find(string path, string pathTemplate); - } -} +using System.Collections.Generic; +using Ocelot.Responses; + +namespace Ocelot.DownstreamRouteFinder.UrlMatcher +{ + public interface IPlaceholderNameAndValueFinder + { + Response> Find(string path, string pathTemplate); + } +} diff --git a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValue.cs b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/PlaceholderNameAndValue.cs similarity index 96% rename from src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValue.cs rename to src/Ocelot/DownstreamRouteFinder/UrlMatcher/PlaceholderNameAndValue.cs index e299c770..90099d58 100644 --- a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValue.cs +++ b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/PlaceholderNameAndValue.cs @@ -1,13 +1,14 @@ -namespace Ocelot.DownstreamRouteFinder.UrlMatcher -{ - public class PlaceholderNameAndValue - { - public PlaceholderNameAndValue(string name, string value) - { - Name = name; - Value = value; - } - public string Name {get;private set;} - public string Value {get;private set;} - } -} \ No newline at end of file +namespace Ocelot.DownstreamRouteFinder.UrlMatcher +{ + public class PlaceholderNameAndValue + { + public PlaceholderNameAndValue(string name, string value) + { + Name = name; + Value = value; + } + + public string Name {get;private set;} + public string Value {get;private set;} + } +} diff --git a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlMatch.cs b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlMatch.cs index bfbd6fdc..9236ae39 100644 --- a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlMatch.cs +++ b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlMatch.cs @@ -6,6 +6,7 @@ namespace Ocelot.DownstreamRouteFinder.UrlMatcher { Match = match; } + public bool Match {get;private set;} } -} \ No newline at end of file +} diff --git a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinder.cs b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinder.cs index 70cf2272..4471618f 100644 --- a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinder.cs +++ b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinder.cs @@ -50,6 +50,7 @@ namespace Ocelot.DownstreamRouteFinder.UrlMatcher counterForTemplate = endOfPlaceholder; } + counterForPath++; } @@ -90,6 +91,7 @@ namespace Ocelot.DownstreamRouteFinder.UrlMatcher return variableName; } + private int GetNextCounterPosition(string urlTemplate, int counterForTemplate, char delimiter) { var closingPlaceHolderPositionOnTemplate = urlTemplate.IndexOf(delimiter, counterForTemplate); @@ -111,4 +113,4 @@ namespace Ocelot.DownstreamRouteFinder.UrlMatcher return character == '{'; } } -} \ No newline at end of file +} diff --git a/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/DownstreamUrlTemplateVariableReplacer.cs b/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/DownstreamTemplatePathPlaceholderReplacer.cs similarity index 97% rename from src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/DownstreamUrlTemplateVariableReplacer.cs rename to src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/DownstreamTemplatePathPlaceholderReplacer.cs index dfd70eed..1b744819 100644 --- a/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/DownstreamUrlTemplateVariableReplacer.cs +++ b/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/DownstreamTemplatePathPlaceholderReplacer.cs @@ -1,25 +1,25 @@ -using System.Collections.Generic; -using System.Text; -using Ocelot.DownstreamRouteFinder.UrlMatcher; -using Ocelot.Responses; -using Ocelot.Values; - -namespace Ocelot.DownstreamUrlCreator.UrlTemplateReplacer -{ - public class DownstreamTemplatePathPlaceholderReplacer : IDownstreamPathPlaceholderReplacer - { - public Response Replace(PathTemplate downstreamPathTemplate, List urlPathPlaceholderNameAndValues) - { - var downstreamPath = new StringBuilder(); - - downstreamPath.Append(downstreamPathTemplate.Value); - - foreach (var placeholderVariableAndValue in urlPathPlaceholderNameAndValues) - { - downstreamPath.Replace(placeholderVariableAndValue.Name, placeholderVariableAndValue.Value); - } - - return new OkResponse(new DownstreamPath(downstreamPath.ToString())); - } - } +using System.Collections.Generic; +using System.Text; +using Ocelot.DownstreamRouteFinder.UrlMatcher; +using Ocelot.Responses; +using Ocelot.Values; + +namespace Ocelot.DownstreamUrlCreator.UrlTemplateReplacer +{ + public class DownstreamTemplatePathPlaceholderReplacer : IDownstreamPathPlaceholderReplacer + { + public Response Replace(PathTemplate downstreamPathTemplate, List urlPathPlaceholderNameAndValues) + { + var downstreamPath = new StringBuilder(); + + downstreamPath.Append(downstreamPathTemplate.Value); + + foreach (var placeholderVariableAndValue in urlPathPlaceholderNameAndValues) + { + downstreamPath.Replace(placeholderVariableAndValue.Name, placeholderVariableAndValue.Value); + } + + return new OkResponse(new DownstreamPath(downstreamPath.ToString())); + } + } } \ No newline at end of file diff --git a/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/IDownstreamUrlPathTemplateVariableReplacer.cs b/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/IDownstreamPathPlaceholderReplacer.cs similarity index 97% rename from src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/IDownstreamUrlPathTemplateVariableReplacer.cs rename to src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/IDownstreamPathPlaceholderReplacer.cs index 9e12b580..46e998d4 100644 --- a/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/IDownstreamUrlPathTemplateVariableReplacer.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; - -namespace Ocelot.DownstreamUrlCreator.UrlTemplateReplacer -{ - public interface IDownstreamPathPlaceholderReplacer - { - Response Replace(PathTemplate downstreamPathTemplate, List urlPathPlaceholderNameAndValues); - } +using System.Collections.Generic; +using Ocelot.DownstreamRouteFinder.UrlMatcher; +using Ocelot.Responses; +using Ocelot.Values; + +namespace Ocelot.DownstreamUrlCreator.UrlTemplateReplacer +{ + public interface IDownstreamPathPlaceholderReplacer + { + Response Replace(PathTemplate downstreamPathTemplate, List urlPathPlaceholderNameAndValues); + } } \ No newline at end of file diff --git a/src/Ocelot/Errors/Middleware/ExceptionHandlerMiddleware.cs b/src/Ocelot/Errors/Middleware/ExceptionHandlerMiddleware.cs index 9b49c84a..2b9e22e2 100644 --- a/src/Ocelot/Errors/Middleware/ExceptionHandlerMiddleware.cs +++ b/src/Ocelot/Errors/Middleware/ExceptionHandlerMiddleware.cs @@ -100,6 +100,7 @@ namespace Ocelot.Errors.Middleware message = $"{message}, inner exception message {e.InnerException.Message}, inner exception stack {e.InnerException.StackTrace}"; } + return $"{message} RequestId: {context.HttpContext.TraceIdentifier}"; } } diff --git a/src/Ocelot/Headers/HttpResponseHeaderReplacer.cs b/src/Ocelot/Headers/HttpResponseHeaderReplacer.cs index 347923ed..cb45ffc3 100644 --- a/src/Ocelot/Headers/HttpResponseHeaderReplacer.cs +++ b/src/Ocelot/Headers/HttpResponseHeaderReplacer.cs @@ -26,6 +26,7 @@ namespace Ocelot.Headers return $"{downstreamUrl}/"; }); } + public Response Replace(HttpResponseMessage response, List fAndRs, HttpRequestMessage httpRequestMessage) { foreach (var f in fAndRs) @@ -54,4 +55,4 @@ namespace Ocelot.Headers return new OkResponse(); } } -} \ No newline at end of file +} diff --git a/src/Ocelot/Infrastructure/Claims/Parser/ClaimsParser.cs b/src/Ocelot/Infrastructure/Claims/Parser/ClaimsParser.cs index b3a028b3..1af0acbc 100644 --- a/src/Ocelot/Infrastructure/Claims/Parser/ClaimsParser.cs +++ b/src/Ocelot/Infrastructure/Claims/Parser/ClaimsParser.cs @@ -37,7 +37,6 @@ return new OkResponse(value); } - public Response> GetValuesByClaimType(IEnumerable claims, string claimType) { List values = new List(); @@ -47,7 +46,6 @@ return new OkResponse>(values); } - private Response GetValue(IEnumerable claims, string key) { var claim = claims.FirstOrDefault(c => c.Type == key); diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/Lease.cs b/src/Ocelot/LoadBalancer/LoadBalancers/Lease.cs index 583b3002..2713d44b 100644 --- a/src/Ocelot/LoadBalancer/LoadBalancers/Lease.cs +++ b/src/Ocelot/LoadBalancer/LoadBalancers/Lease.cs @@ -9,6 +9,7 @@ namespace Ocelot.LoadBalancer.LoadBalancers HostAndPort = hostAndPort; Connections = connections; } + public ServiceHostAndPort HostAndPort { get; private set; } public int Connections { get; private set; } } diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/RoundRobin.cs b/src/Ocelot/LoadBalancer/LoadBalancers/RoundRobin.cs index efc00e5e..26d55b1f 100644 --- a/src/Ocelot/LoadBalancer/LoadBalancers/RoundRobin.cs +++ b/src/Ocelot/LoadBalancer/LoadBalancers/RoundRobin.cs @@ -17,7 +17,6 @@ namespace Ocelot.LoadBalancer.LoadBalancers _services = services; } - public async Task> Lease() { var services = await _services.Invoke(); diff --git a/src/Ocelot/Logging/IOcelotLoggerFactory.cs b/src/Ocelot/Logging/IOcelotLoggerFactory.cs index 29b4c9d0..3a145595 100644 --- a/src/Ocelot/Logging/IOcelotLoggerFactory.cs +++ b/src/Ocelot/Logging/IOcelotLoggerFactory.cs @@ -6,6 +6,7 @@ namespace Ocelot.Logging { IOcelotLogger CreateLogger(); } + /// /// Thin wrapper around the DotNet core logging framework, used to allow the scopedDataRepository to be injected giving access to the Ocelot RequestId /// diff --git a/src/Ocelot/Middleware/DownstreamContext.cs b/src/Ocelot/Middleware/DownstreamContext.cs index 84ebc77a..1c805deb 100644 --- a/src/Ocelot/Middleware/DownstreamContext.cs +++ b/src/Ocelot/Middleware/DownstreamContext.cs @@ -22,8 +22,6 @@ namespace Ocelot.Middleware public HttpRequestMessage DownstreamRequest { get; set; } public HttpResponseMessage DownstreamResponse { get; set; } public List Errors { get;set; } - //public string RequestId {get;set;} - //public string PreviousRequestId {get;set;} public bool IsError => Errors.Count > 0; } } diff --git a/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs b/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs index 541a8e93..cda82bef 100644 --- a/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs +++ b/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs @@ -59,9 +59,11 @@ var firstDelegate = pipelineBuilder.Build(); - //inject first delegate into first piece of asp.net middleware..maybe not like this - //then because we are updating the http context in ocelot it comes out correct for - //rest of asp.net.. + /* + inject first delegate into first piece of asp.net middleware..maybe not like this + then because we are updating the http context in ocelot it comes out correct for + rest of asp.net.. + */ builder.Use(async (context, task) => { diff --git a/src/Ocelot/Middleware/OcelotPipelineConfiguration.cs b/src/Ocelot/Middleware/OcelotPipelineConfiguration.cs index 3cfded9b..d58b8b09 100644 --- a/src/Ocelot/Middleware/OcelotPipelineConfiguration.cs +++ b/src/Ocelot/Middleware/OcelotPipelineConfiguration.cs @@ -37,7 +37,6 @@ /// /// This allows the user to implement there own query string manipulation logic /// - public Func, Task> PreQueryStringBuilderMiddleware { get; set; } - + public Func, Task> PreQueryStringBuilderMiddleware { get; set; } } } diff --git a/src/Ocelot/Ocelot.csproj b/src/Ocelot/Ocelot.csproj index 62552bed..89ada54d 100644 --- a/src/Ocelot/Ocelot.csproj +++ b/src/Ocelot/Ocelot.csproj @@ -17,6 +17,7 @@ True false Tom Pallister + ..\..\codeanalysis.ruleset full @@ -35,6 +36,9 @@ + + all + diff --git a/src/Ocelot/Raft/ExcludeFromCoverage.cs b/src/Ocelot/Raft/ExcludeFromCoverageAttribute.cs similarity index 97% rename from src/Ocelot/Raft/ExcludeFromCoverage.cs rename to src/Ocelot/Raft/ExcludeFromCoverageAttribute.cs index 70d42167..9ea5544a 100644 --- a/src/Ocelot/Raft/ExcludeFromCoverage.cs +++ b/src/Ocelot/Raft/ExcludeFromCoverageAttribute.cs @@ -1,7 +1,7 @@ -using System; - -namespace Ocelot.Raft -{ - [AttributeUsage(AttributeTargets.Class|AttributeTargets.Method|AttributeTargets.Property)] - public class ExcludeFromCoverageAttribute : Attribute{} +using System; + +namespace Ocelot.Raft +{ + [AttributeUsage(AttributeTargets.Class|AttributeTargets.Method|AttributeTargets.Property)] + public class ExcludeFromCoverageAttribute : Attribute{} } \ No newline at end of file diff --git a/src/Ocelot/Raft/FakeCommand.cs b/src/Ocelot/Raft/FakeCommand.cs index 795ca7a5..45dd1045 100644 --- a/src/Ocelot/Raft/FakeCommand.cs +++ b/src/Ocelot/Raft/FakeCommand.cs @@ -8,8 +8,8 @@ namespace Ocelot.Raft public FakeCommand(string value) { this.Value = value; - } + public string Value { get; private set; } } } diff --git a/src/Ocelot/Raft/FilePeersProvider.cs b/src/Ocelot/Raft/FilePeersProvider.cs index aeca7b2c..d31dc2ca 100644 --- a/src/Ocelot/Raft/FilePeersProvider.cs +++ b/src/Ocelot/Raft/FilePeersProvider.cs @@ -27,16 +27,19 @@ namespace Ocelot.Raft _finder = finder; _options = options; _peers = new List(); + //todo - sort out async nonsense.. var config = _provider.Get().GetAwaiter().GetResult(); foreach (var item in _options.Value.Peers) { var httpClient = new HttpClient(); + //todo what if this errors? var httpPeer = new HttpPeer(item.HostAndPort, httpClient, _finder, config.Data, _identityServerConfig); _peers.Add(httpPeer); } } + public List Get() { return _peers; diff --git a/src/Ocelot/Raft/HttpPeer.cs b/src/Ocelot/Raft/HttpPeer.cs index ef76a583..cd5ceef5 100644 --- a/src/Ocelot/Raft/HttpPeer.cs +++ b/src/Ocelot/Raft/HttpPeer.cs @@ -28,7 +28,7 @@ namespace Ocelot.Raft { _identityServerConfiguration = identityServerConfiguration; _config = config; - Id = hostAndPort; + Id = hostAndPort; _hostAndPort = hostAndPort; _httpClient = httpClient; _jsonSerializerSettings = new JsonSerializerSettings() { @@ -68,6 +68,7 @@ namespace Ocelot.Raft { SetToken(); } + var json = JsonConvert.SerializeObject(appendEntries, _jsonSerializerSettings); var content = new StringContent(json); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); @@ -88,12 +89,14 @@ namespace Ocelot.Raft } } - public Response Request(T command) where T : ICommand + public Response Request(T command) + where T : ICommand { if(_token == null) { SetToken(); } + var json = JsonConvert.SerializeObject(command, _jsonSerializerSettings); var content = new StringContent(json); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); diff --git a/src/Ocelot/Raft/OcelotFiniteStateMachine.cs b/src/Ocelot/Raft/OcelotFiniteStateMachine.cs index f63695f2..feecd7d7 100644 --- a/src/Ocelot/Raft/OcelotFiniteStateMachine.cs +++ b/src/Ocelot/Raft/OcelotFiniteStateMachine.cs @@ -19,7 +19,7 @@ namespace Ocelot.Raft //todo - handle an error //hack it to just cast as at the moment we know this is the only command :P var hack = (UpdateFileConfiguration)log.CommandData; - _setter.Set(hack.Configuration).GetAwaiter().GetResult();; + _setter.Set(hack.Configuration).GetAwaiter().GetResult(); } } -} \ No newline at end of file +} diff --git a/src/Ocelot/Raft/SqlLiteLog.cs b/src/Ocelot/Raft/SqlLiteLog.cs index 098d9c06..aff04bf5 100644 --- a/src/Ocelot/Raft/SqlLiteLog.cs +++ b/src/Ocelot/Raft/SqlLiteLog.cs @@ -24,6 +24,7 @@ namespace Ocelot.Raft FileStream fs = File.Create(_path); fs.Dispose(); } + using(var connection = new SqliteConnection($"Data Source={_path};")) { connection.Open(); @@ -59,6 +60,7 @@ namespace Ocelot.Raft } } } + return result; } } @@ -88,6 +90,7 @@ namespace Ocelot.Raft } } } + return result; } } @@ -113,6 +116,7 @@ namespace Ocelot.Raft } } } + return result; } } @@ -129,6 +133,7 @@ namespace Ocelot.Raft TypeNameHandling = TypeNameHandling.All }; var data = JsonConvert.SerializeObject(log, jsonSerializerSettings); + //todo - sql injection dont copy this.. var sql = $"insert into logs (data) values ('{data}')"; using(var command = new SqliteCommand(sql, connection)) @@ -153,6 +158,7 @@ namespace Ocelot.Raft using(var connection = new SqliteConnection($"Data Source={_path};")) { connection.Open(); + //todo - sql injection dont copy this.. var sql = $"select data from logs where id = {index};"; using(var command = new SqliteCommand(sql, connection)) @@ -183,6 +189,7 @@ namespace Ocelot.Raft using(var connection = new SqliteConnection($"Data Source={_path};")) { connection.Open(); + //todo - sql injection dont copy this.. var sql = $"select data from logs where id = {index}"; using(var command = new SqliteCommand(sql, connection)) @@ -207,6 +214,7 @@ namespace Ocelot.Raft using(var connection = new SqliteConnection($"Data Source={_path};")) { connection.Open(); + //todo - sql injection dont copy this.. var sql = $"select id, data from logs where id >= {index}"; using(var command = new SqliteCommand(sql, connection)) @@ -222,15 +230,13 @@ namespace Ocelot.Raft }; var log = JsonConvert.DeserializeObject(data, jsonSerializerSettings); logsToReturn.Add((id, log)); - } } } } return logsToReturn; - } - + } } public long GetTermAtIndex(int index) @@ -241,6 +247,7 @@ namespace Ocelot.Raft using(var connection = new SqliteConnection($"Data Source={_path};")) { connection.Open(); + //todo - sql injection dont copy this.. var sql = $"select data from logs where id = {index}"; using(var command = new SqliteCommand(sql, connection)) @@ -256,9 +263,11 @@ namespace Ocelot.Raft } } } + return result; } } + public void Remove(int indexOfCommand) { lock(_lock) @@ -266,6 +275,7 @@ namespace Ocelot.Raft using(var connection = new SqliteConnection($"Data Source={_path};")) { connection.Open(); + //todo - sql injection dont copy this.. var deleteSql = $"delete from logs where id >= {indexOfCommand};"; using(var deleteCommand = new SqliteCommand(deleteSql, connection)) @@ -276,4 +286,4 @@ namespace Ocelot.Raft } } } -} \ No newline at end of file +} diff --git a/src/Ocelot/RateLimit/ClientRateLimitProcessor.cs b/src/Ocelot/RateLimit/ClientRateLimitProcessor.cs index 0415489c..65a04504 100644 --- a/src/Ocelot/RateLimit/ClientRateLimitProcessor.cs +++ b/src/Ocelot/RateLimit/ClientRateLimitProcessor.cs @@ -7,7 +7,6 @@ using System.Threading.Tasks; namespace Ocelot.RateLimit { - public class ClientRateLimitProcessor { private readonly IRateLimitCounterHandler _counterHandler; @@ -24,7 +23,6 @@ namespace Ocelot.RateLimit return _core.ProcessRequest(requestIdentity, option); } - public int RetryAfterFrom(DateTime timestamp, RateLimitRule rule) { return _core.RetryAfterFrom(timestamp, rule); @@ -39,7 +37,5 @@ namespace Ocelot.RateLimit { return _core.ConvertToTimeSpan(timeSpan); } - } - } diff --git a/src/Ocelot/RateLimit/DistributedCacheRateLimitCounterHanlder.cs b/src/Ocelot/RateLimit/DistributedCacheRateLimitCounterHanlder.cs index ddcda184..91f933b7 100644 --- a/src/Ocelot/RateLimit/DistributedCacheRateLimitCounterHanlder.cs +++ b/src/Ocelot/RateLimit/DistributedCacheRateLimitCounterHanlder.cs @@ -34,6 +34,7 @@ namespace Ocelot.RateLimit { return JsonConvert.DeserializeObject(stored); } + return null; } diff --git a/src/Ocelot/RateLimit/Middleware/ClientRateLimitMiddleware.cs b/src/Ocelot/RateLimit/Middleware/ClientRateLimitMiddleware.cs index 064ec54b..4ceb91f8 100644 --- a/src/Ocelot/RateLimit/Middleware/ClientRateLimitMiddleware.cs +++ b/src/Ocelot/RateLimit/Middleware/ClientRateLimitMiddleware.cs @@ -31,6 +31,7 @@ namespace Ocelot.RateLimit.Middleware public async Task Invoke(DownstreamContext context) { var options = context.DownstreamReRoute.RateLimitOptions; + // check if rate limiting is enabled if (!context.DownstreamReRoute.EnableEndpointEndpointRateLimiting) { @@ -38,6 +39,7 @@ namespace Ocelot.RateLimit.Middleware await _next.Invoke(context); return; } + // compute identity from request var identity = SetIdentity(context.HttpContext, options); @@ -65,13 +67,14 @@ namespace Ocelot.RateLimit.Middleware LogBlockedRequest(context.HttpContext, identity, counter, rule, context.DownstreamReRoute); var retrystring = retryAfter.ToString(System.Globalization.CultureInfo.InvariantCulture); + // break execution await ReturnQuotaExceededResponse(context.HttpContext, options, retrystring); return; } - } + //set X-Rate-Limit headers for the longest period if (!options.DisableRateLimitHeaders) { @@ -103,6 +106,7 @@ namespace Ocelot.RateLimit.Middleware { return true; } + return false; } @@ -134,8 +138,5 @@ namespace Ocelot.RateLimit.Middleware return Task.CompletedTask; } - } - } - diff --git a/src/Ocelot/RateLimit/RateLimitCore.cs b/src/Ocelot/RateLimit/RateLimitCore.cs index c3455682..82124c85 100644 --- a/src/Ocelot/RateLimit/RateLimitCore.cs +++ b/src/Ocelot/RateLimit/RateLimitCore.cs @@ -38,6 +38,7 @@ namespace Ocelot.RateLimit { // increment request count var totalRequests = entry.Value.TotalRequests + 1; + // deep copy counter = new RateLimitCounter(entry.Value.Timestamp, totalRequests); } @@ -62,6 +63,7 @@ namespace Ocelot.RateLimit var expirationTime = ConvertToTimeSpan(rule.Period); _counterHandler.Set(counterId, counter, expirationTime); } + return counter; } @@ -69,6 +71,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); } @@ -92,7 +95,6 @@ namespace Ocelot.RateLimit rule.Period, rule.Limit.ToString(), (DateTime.UtcNow + ConvertToTimeSpan(rule.Period)).ToUniversalTime().ToString("o", DateTimeFormatInfo.InvariantInfo)); - } return headers; @@ -141,7 +143,6 @@ namespace Ocelot.RateLimit default: throw new FormatException($"{timeSpan} can't be converted to TimeSpan, unknown type {type}"); } - } - + } } } diff --git a/src/Ocelot/Request/Mapper/RequestMapper.cs b/src/Ocelot/Request/Mapper/RequestMapper.cs index a6f22d6d..9af0d08e 100644 --- a/src/Ocelot/Request/Mapper/RequestMapper.cs +++ b/src/Ocelot/Request/Mapper/RequestMapper.cs @@ -92,4 +92,3 @@ } } } - diff --git a/src/Ocelot/RequestId/Middleware/ReRouteRequestIdMiddleware.cs b/src/Ocelot/RequestId/Middleware/ReRouteRequestIdMiddleware.cs index 0b146b27..32ee6c68 100644 --- a/src/Ocelot/RequestId/Middleware/ReRouteRequestIdMiddleware.cs +++ b/src/Ocelot/RequestId/Middleware/ReRouteRequestIdMiddleware.cs @@ -18,7 +18,6 @@ namespace Ocelot.RequestId.Middleware private readonly IOcelotLogger _logger; private readonly IRequestScopedDataRepository _requestScopedDataRepository; - public ReRouteRequestIdMiddleware(OcelotRequestDelegate next, IOcelotLoggerFactory loggerFactory, IRequestScopedDataRepository requestScopedDataRepository) diff --git a/src/Ocelot/Requester/HttpClientHttpRequester.cs b/src/Ocelot/Requester/HttpClientHttpRequester.cs index a531d9b9..de9ea1c6 100644 --- a/src/Ocelot/Requester/HttpClientHttpRequester.cs +++ b/src/Ocelot/Requester/HttpClientHttpRequester.cs @@ -55,7 +55,6 @@ namespace Ocelot.Requester { _cacheHandlers.Set(cacheKey, httpClient, TimeSpan.FromHours(24)); } - } private IHttpClient GetHttpClient(string cacheKey, IHttpClientBuilder builder, DownstreamContext request) diff --git a/src/Ocelot/Requester/ITracingHandler.cs b/src/Ocelot/Requester/ITracingHandler.cs new file mode 100644 index 00000000..87593303 --- /dev/null +++ b/src/Ocelot/Requester/ITracingHandler.cs @@ -0,0 +1,6 @@ +namespace Ocelot.Requester +{ + public interface ITracingHandler + { + } +} diff --git a/src/Ocelot/Requester/MemoryHttpClientCache.cs b/src/Ocelot/Requester/MemoryHttpClientCache.cs index 3ce1716b..e37a46a3 100644 --- a/src/Ocelot/Requester/MemoryHttpClientCache.cs +++ b/src/Ocelot/Requester/MemoryHttpClientCache.cs @@ -41,6 +41,7 @@ namespace Ocelot.Requester { connectionQueue.TryDequeue(out client); } + return client; } diff --git a/src/Ocelot/Requester/OcelotHttpTracingHandler.cs b/src/Ocelot/Requester/OcelotHttpTracingHandler.cs index e2658c7f..33bd4caf 100644 --- a/src/Ocelot/Requester/OcelotHttpTracingHandler.cs +++ b/src/Ocelot/Requester/OcelotHttpTracingHandler.cs @@ -8,10 +8,6 @@ using Butterfly.OpenTracing; namespace Ocelot.Requester { - public interface ITracingHandler - { - } - public class OcelotHttpTracingHandler : DelegatingHandler, ITracingHandler { private readonly IServiceTracer _tracer; @@ -35,7 +31,7 @@ namespace Ocelot.Requester { request.Headers.Remove(prefix_spanId); request.Headers.TryAddWithoutValidation(prefix_spanId, span.SpanContext.SpanId); - }; + } span.Tags.Client().Component("HttpClient") .HttpMethod(request.Method.Method) @@ -51,7 +47,7 @@ namespace Ocelot.Requester if (!c.Contains(k)) { c.Add(k, v); - }; + } }); span.Log(LogField.CreateNew().ClientSend()); diff --git a/src/Ocelot/Responder/HttpContextResponder.cs b/src/Ocelot/Responder/HttpContextResponder.cs index fbfbc6c2..7bc55d94 100644 --- a/src/Ocelot/Responder/HttpContextResponder.cs +++ b/src/Ocelot/Responder/HttpContextResponder.cs @@ -50,7 +50,6 @@ namespace Ocelot.Responder httpContext.Response.StatusCode = (int)response.StatusCode; return Task.CompletedTask; - }, context); using (Stream stream = new MemoryStream(content)) diff --git a/src/Ocelot/Responder/Middleware/ResponderMiddleware.cs b/src/Ocelot/Responder/Middleware/ResponderMiddleware.cs index bac062f8..4bfbad7a 100644 --- a/src/Ocelot/Responder/Middleware/ResponderMiddleware.cs +++ b/src/Ocelot/Responder/Middleware/ResponderMiddleware.cs @@ -29,7 +29,6 @@ namespace Ocelot.Responder.Middleware _responder = responder; _codeMapper = codeMapper; _logger = loggerFactory.CreateLogger(); - } public async Task Invoke(DownstreamContext context) diff --git a/src/Ocelot/Responses/ErrorResponse.cs b/src/Ocelot/Responses/ErrorResponse.cs index 28cd3f02..7a6688e7 100644 --- a/src/Ocelot/Responses/ErrorResponse.cs +++ b/src/Ocelot/Responses/ErrorResponse.cs @@ -8,8 +8,9 @@ namespace Ocelot.Responses public ErrorResponse(Error error) : base(new List{error}) { } + public ErrorResponse(List errors) : base(errors) { } } -} \ No newline at end of file +} diff --git a/src/Ocelot/Responses/ErrorResponseGeneric.cs b/src/Ocelot/Responses/ErrorResponseGeneric.cs index 837c2e5d..f57de97f 100644 --- a/src/Ocelot/Responses/ErrorResponseGeneric.cs +++ b/src/Ocelot/Responses/ErrorResponseGeneric.cs @@ -3,16 +3,18 @@ using Ocelot.Errors; 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(List errors) : base(errors) { } } -} \ No newline at end of file +} diff --git a/src/Ocelot/Responses/OkResponseGeneric.cs b/src/Ocelot/Responses/OkResponseGeneric.cs index 7445d2d9..73fcf1e2 100644 --- a/src/Ocelot/Responses/OkResponseGeneric.cs +++ b/src/Ocelot/Responses/OkResponseGeneric.cs @@ -1,9 +1,11 @@ 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 { public OkResponse(T data) : base(data) { } } -} \ No newline at end of file +} diff --git a/src/Ocelot/Responses/ResponseGeneric.cs b/src/Ocelot/Responses/ResponseGeneric.cs index 479dd08d..0b2514e9 100644 --- a/src/Ocelot/Responses/ResponseGeneric.cs +++ b/src/Ocelot/Responses/ResponseGeneric.cs @@ -3,7 +3,9 @@ using Ocelot.Errors; 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 { protected Response(T data) { @@ -14,7 +16,6 @@ namespace Ocelot.Responses { } - public T Data { get; private set; } - + public T Data { get; private set; } } -} \ No newline at end of file +} diff --git a/src/Ocelot/ServiceDiscovery/ServiceDiscoveryProviderFactory.cs b/src/Ocelot/ServiceDiscovery/ServiceDiscoveryProviderFactory.cs index de93a19d..86b28a72 100644 --- a/src/Ocelot/ServiceDiscovery/ServiceDiscoveryProviderFactory.cs +++ b/src/Ocelot/ServiceDiscovery/ServiceDiscoveryProviderFactory.cs @@ -14,7 +14,7 @@ namespace Ocelot.ServiceDiscovery _factory = factory; } - public IServiceDiscoveryProvider Get(ServiceProviderConfiguration serviceConfig, DownstreamReRoute reRoute) + public IServiceDiscoveryProvider Get(ServiceProviderConfiguration serviceConfig, DownstreamReRoute reRoute) { if (reRoute.UseServiceDiscovery) { diff --git a/src/Ocelot/Values/Service.cs b/src/Ocelot/Values/Service.cs index 1acb26e6..abf5449b 100644 --- a/src/Ocelot/Values/Service.cs +++ b/src/Ocelot/Values/Service.cs @@ -16,6 +16,7 @@ namespace Ocelot.Values Version = version; Tags = tags; } + public string Id { get; private set; } public string Name { get; private set; } diff --git a/test/Ocelot.AcceptanceTests/AggregateTests.cs b/test/Ocelot.AcceptanceTests/AggregateTests.cs index c0ed2de2..3944adfc 100644 --- a/test/Ocelot.AcceptanceTests/AggregateTests.cs +++ b/test/Ocelot.AcceptanceTests/AggregateTests.cs @@ -15,7 +15,6 @@ namespace Ocelot.AcceptanceTests public class AggregateTests : IDisposable { private IWebHost _serviceOneBuilder; - private IWebHost _serviceTwoBuilder; private readonly Steps _steps; private string _downstreamPathOne; private string _downstreamPathTwo; @@ -229,7 +228,6 @@ namespace Ocelot.AcceptanceTests .BDDfy(); } - [Fact] public void should_be_thread_safe() { @@ -365,7 +363,6 @@ namespace Ocelot.AcceptanceTests public void Dispose() { _serviceOneBuilder?.Dispose(); - _serviceTwoBuilder?.Dispose(); _steps.Dispose(); } } diff --git a/test/Ocelot.AcceptanceTests/AuthorisationTests.cs b/test/Ocelot.AcceptanceTests/AuthorisationTests.cs index aaa4faff..06fee4ef 100644 --- a/test/Ocelot.AcceptanceTests/AuthorisationTests.cs +++ b/test/Ocelot.AcceptanceTests/AuthorisationTests.cs @@ -177,7 +177,7 @@ namespace Ocelot.AcceptanceTests AuthenticationOptions = new FileAuthenticationOptions { AuthenticationProviderKey = "Test", - AllowedScopes = new List{ "api", "api.readOnly", "openid", "offline_access" }, + AllowedScopes = new List{ "api", "api.readOnly", "openid", "offline_access" }, }, } } @@ -218,7 +218,7 @@ namespace Ocelot.AcceptanceTests AuthenticationOptions = new FileAuthenticationOptions { AuthenticationProviderKey = "Test", - AllowedScopes = new List{ "api", "openid", "offline_access" }, + AllowedScopes = new List{ "api", "openid", "offline_access" }, }, } } @@ -356,7 +356,6 @@ namespace Ocelot.AcceptanceTests "CustomerId", "LocationId", "UserType", "UserId" } }, - }) .AddInMemoryClients(new List { @@ -437,7 +436,6 @@ namespace Ocelot.AcceptanceTests "CustomerId", "LocationId", "UserType", "UserId", "Role" } }, - }) .AddInMemoryClients(new List { @@ -450,7 +448,6 @@ namespace Ocelot.AcceptanceTests AccessTokenType = tokenType, Enabled = true, RequireClientSecret = false, - } }) .AddTestUsers(users); diff --git a/test/Ocelot.AcceptanceTests/ButterflyTracingTests.cs b/test/Ocelot.AcceptanceTests/ButterflyTracingTests.cs index 84346985..a7411ebe 100644 --- a/test/Ocelot.AcceptanceTests/ButterflyTracingTests.cs +++ b/test/Ocelot.AcceptanceTests/ButterflyTracingTests.cs @@ -52,7 +52,7 @@ namespace Ocelot.AcceptanceTests UpstreamHttpMethod = new List { "Get" }, HttpHandlerOptions = new FileHttpHandlerOptions { - UseTracing = true + UseTracing = true }, QoSOptions = new FileQoSOptions { @@ -77,7 +77,7 @@ namespace Ocelot.AcceptanceTests UpstreamHttpMethod = new List { "Get" }, HttpHandlerOptions = new FileHttpHandlerOptions { - UseTracing = true + UseTracing = true }, QoSOptions = new FileQoSOptions { @@ -104,7 +104,6 @@ namespace Ocelot.AcceptanceTests .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Tom")) .BDDfy(); - var commandOnAllStateMachines = WaitFor(5000).Until(() => _butterflyCalled == 4); commandOnAllStateMachines.ShouldBeTrue(); diff --git a/test/Ocelot.AcceptanceTests/CannotStartOcelotTests.cs b/test/Ocelot.AcceptanceTests/CannotStartOcelotTests.cs index a4dfcac6..e555ade7 100644 --- a/test/Ocelot.AcceptanceTests/CannotStartOcelotTests.cs +++ b/test/Ocelot.AcceptanceTests/CannotStartOcelotTests.cs @@ -1,19 +1,14 @@ - using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Hosting; using Ocelot.Configuration.File; using Shouldly; -using TestStack.BDDfy; using Xunit; namespace Ocelot.AcceptanceTests { public class CannotStartOcelotTests : IDisposable { - private IWebHost _builder; private readonly Steps _steps; - private string _downstreamPath; public CannotStartOcelotTests() { @@ -51,8 +46,7 @@ namespace Ocelot.AcceptanceTests public void Dispose() { - _builder?.Dispose(); _steps.Dispose(); } } -} \ No newline at end of file +} diff --git a/test/Ocelot.AcceptanceTests/ClaimsToQueryStringForwardingTests.cs b/test/Ocelot.AcceptanceTests/ClaimsToQueryStringForwardingTests.cs index b8c1a59e..f73a360e 100644 --- a/test/Ocelot.AcceptanceTests/ClaimsToQueryStringForwardingTests.cs +++ b/test/Ocelot.AcceptanceTests/ClaimsToQueryStringForwardingTests.cs @@ -156,7 +156,7 @@ namespace Ocelot.AcceptanceTests { new ApiResource { - Name = apiName, + Name = apiName, Description = "My API", Enabled = true, DisplayName = "test", diff --git a/test/Ocelot.AcceptanceTests/ClientRateLimitTests.cs b/test/Ocelot.AcceptanceTests/ClientRateLimitTests.cs index 11ec83b1..dc9d5eef 100644 --- a/test/Ocelot.AcceptanceTests/ClientRateLimitTests.cs +++ b/test/Ocelot.AcceptanceTests/ClientRateLimitTests.cs @@ -20,13 +20,11 @@ namespace Ocelot.AcceptanceTests private readonly Steps _steps; private int _counterOne; - public ClientRateLimitTests() { _steps = new Steps(); } - public void Dispose() { _builder?.Dispose(); @@ -56,7 +54,7 @@ namespace Ocelot.AcceptanceTests UpstreamHttpMethod = new List { "Get" }, RequestIdKey = _steps.RequestIdKey, - RateLimitOptions = new FileRateLimitRule() + RateLimitOptions = new FileRateLimitRule() { EnableRateLimiting = true, ClientWhitelist = new List(), @@ -75,7 +73,6 @@ namespace Ocelot.AcceptanceTests QuotaExceededMessage = "", RateLimitCounterPrefix = "", HttpStatusCode = 428 - }, RequestIdKey ="oceclientrequest" } @@ -93,7 +90,6 @@ namespace Ocelot.AcceptanceTests .BDDfy(); } - [Fact] public void should_call_middleware_withWhitelistClient() { @@ -117,7 +113,7 @@ namespace Ocelot.AcceptanceTests UpstreamHttpMethod = new List { "Get" }, RequestIdKey = _steps.RequestIdKey, - RateLimitOptions = new FileRateLimitRule() + RateLimitOptions = new FileRateLimitRule() { EnableRateLimiting = true, ClientWhitelist = new List() { "ocelotclient1"}, @@ -148,7 +144,6 @@ namespace Ocelot.AcceptanceTests .BDDfy(); } - private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath) { _builder = new WebHostBuilder() @@ -172,7 +167,5 @@ namespace Ocelot.AcceptanceTests _builder.Start(); } - - } } diff --git a/test/Ocelot.AcceptanceTests/ConfigurationInConsulTests.cs b/test/Ocelot.AcceptanceTests/ConfigurationInConsulTests.cs index db617718..7c9ac239 100644 --- a/test/Ocelot.AcceptanceTests/ConfigurationInConsulTests.cs +++ b/test/Ocelot.AcceptanceTests/ConfigurationInConsulTests.cs @@ -175,7 +175,6 @@ namespace Ocelot.AcceptanceTests .BDDfy(); } - [Fact] public void should_load_configuration_out_of_consul_if_it_is_changed() { @@ -307,8 +306,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/OcelotConfiguration") { try diff --git a/test/Ocelot.AcceptanceTests/CustomMiddlewareTests.cs b/test/Ocelot.AcceptanceTests/CustomMiddlewareTests.cs index 0f30ba73..341986fe 100644 --- a/test/Ocelot.AcceptanceTests/CustomMiddlewareTests.cs +++ b/test/Ocelot.AcceptanceTests/CustomMiddlewareTests.cs @@ -25,7 +25,7 @@ namespace Ocelot.AcceptanceTests public CustomMiddlewareTests() { _counter = 0; - _steps = new Steps();; + _steps = new Steps(); _configurationPath = "configuration.json"; } @@ -286,7 +286,6 @@ namespace Ocelot.AcceptanceTests .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() @@ -352,14 +351,13 @@ namespace Ocelot.AcceptanceTests app.UsePathBase(basePath); app.Run(context => { - if(string.IsNullOrEmpty(basePath)) { context.Response.StatusCode = statusCode; } else if(context.Request.Path.Value != basePath) { - context.Response.StatusCode = 404;; + context.Response.StatusCode = 404; } return Task.CompletedTask; diff --git a/test/Ocelot.AcceptanceTests/HeaderTests.cs b/test/Ocelot.AcceptanceTests/HeaderTests.cs index e0bd67c8..b5a2711e 100644 --- a/test/Ocelot.AcceptanceTests/HeaderTests.cs +++ b/test/Ocelot.AcceptanceTests/HeaderTests.cs @@ -186,7 +186,6 @@ namespace Ocelot.AcceptanceTests .BDDfy(); } - private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string headerKey) { _builder = new WebHostBuilder() diff --git a/test/Ocelot.AcceptanceTests/HttpDelegatingHandlersTests.cs b/test/Ocelot.AcceptanceTests/HttpDelegatingHandlersTests.cs index bb2a43df..c54294cd 100644 --- a/test/Ocelot.AcceptanceTests/HttpDelegatingHandlersTests.cs +++ b/test/Ocelot.AcceptanceTests/HttpDelegatingHandlersTests.cs @@ -70,8 +70,7 @@ namespace Ocelot.AcceptanceTests } class FakeHandler : DelegatingHandler - { - + { public DateTime TimeCalled { get; private set; } protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) @@ -111,6 +110,5 @@ namespace Ocelot.AcceptanceTests _builder.Start(); } - } } diff --git a/test/Ocelot.AcceptanceTests/LoadBalancerTests.cs b/test/Ocelot.AcceptanceTests/LoadBalancerTests.cs index a5c5e07c..d67e7e41 100644 --- a/test/Ocelot.AcceptanceTests/LoadBalancerTests.cs +++ b/test/Ocelot.AcceptanceTests/LoadBalancerTests.cs @@ -159,8 +159,7 @@ namespace Ocelot.AcceptanceTests catch (System.Exception exception) { await context.Response.WriteAsync(exception.StackTrace); - } - + } }); }) .Build(); diff --git a/test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj b/test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj index 396eb403..90d5bc64 100644 --- a/test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj +++ b/test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj @@ -1,48 +1,53 @@ - - - 0.0.0-dev - netcoreapp2.0 - 2.0.0 - Ocelot.AcceptanceTests - Exe - Ocelot.AcceptanceTests - true - osx.10.11-x64;osx.10.12-x64;win7-x64;win10-x64 - false - false - false - - - - PreserveNewest - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + + 0.0.0-dev + netcoreapp2.0 + 2.0.0 + Ocelot.AcceptanceTests + Exe + Ocelot.AcceptanceTests + true + osx.10.11-x64;osx.10.12-x64;win7-x64;win10-x64 + false + false + false + ..\..\codeanalysis.ruleset + + + + + PreserveNewest + + + + + + + + + + + + + + + + all + + + + + + + + + + + + + + + + + + diff --git a/test/Ocelot.AcceptanceTests/QoSTests.cs b/test/Ocelot.AcceptanceTests/QoSTests.cs index e4f8a026..d11721b8 100644 --- a/test/Ocelot.AcceptanceTests/QoSTests.cs +++ b/test/Ocelot.AcceptanceTests/QoSTests.cs @@ -51,8 +51,7 @@ namespace Ocelot.AcceptanceTests ExceptionsAllowedBeforeBreaking = 1, TimeoutValue = 500, DurationOfBreak = 1000 - }, - + }, } } }; diff --git a/test/Ocelot.AcceptanceTests/RoutingTests.cs b/test/Ocelot.AcceptanceTests/RoutingTests.cs index ea748a04..0a16e565 100644 --- a/test/Ocelot.AcceptanceTests/RoutingTests.cs +++ b/test/Ocelot.AcceptanceTests/RoutingTests.cs @@ -543,7 +543,6 @@ namespace Ocelot.AcceptanceTests .BDDfy(); } - [Fact] public void should_return_response_200_with_complex_url_that_starts_with_placeholder() { @@ -578,7 +577,6 @@ namespace Ocelot.AcceptanceTests .BDDfy(); } - [Fact] public void should_not_add_trailing_slash_to_downstream_url() { @@ -834,7 +832,6 @@ namespace Ocelot.AcceptanceTests .BDDfy(); } - [Fact] public void should_fix_145() { diff --git a/test/Ocelot.AcceptanceTests/ServiceDiscoveryTests.cs b/test/Ocelot.AcceptanceTests/ServiceDiscoveryTests.cs index 572c7126..97e104c4 100644 --- a/test/Ocelot.AcceptanceTests/ServiceDiscoveryTests.cs +++ b/test/Ocelot.AcceptanceTests/ServiceDiscoveryTests.cs @@ -359,8 +359,7 @@ namespace Ocelot.AcceptanceTests catch (System.Exception exception) { await context.Response.WriteAsync(exception.StackTrace); - } - + } }); }) .Build(); @@ -406,4 +405,4 @@ namespace Ocelot.AcceptanceTests _steps.Dispose(); } } -} \ No newline at end of file +} diff --git a/test/Ocelot.AcceptanceTests/Steps.cs b/test/Ocelot.AcceptanceTests/Steps.cs index 6a6fa3c4..61a01059 100644 --- a/test/Ocelot.AcceptanceTests/Steps.cs +++ b/test/Ocelot.AcceptanceTests/Steps.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Concurrent; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; using System.Net; @@ -19,15 +17,11 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Ocelot.Configuration.File; -using Ocelot.Configuration.Repository; using Ocelot.DependencyInjection; using Ocelot.Middleware; -using Ocelot.ServiceDiscovery; using Shouldly; using ConfigurationBuilder = Microsoft.Extensions.Configuration.ConfigurationBuilder; using Ocelot.AcceptanceTests.Caching; -using Butterfly.Client.AspNetCore; -using Butterfly.Client.Tracing; namespace Ocelot.AcceptanceTests { @@ -42,11 +36,9 @@ namespace Ocelot.AcceptanceTests public string RequestIdKey = "OcRequestId"; private readonly Random _random; private IWebHostBuilder _webHostBuilder; - private readonly string _baseUrl; public Steps() { - _baseUrl = "http://localhost:5000"; _random = new Random(); } @@ -144,6 +136,7 @@ namespace Ocelot.AcceptanceTests _ocelotClient = _ocelotServer.CreateClient(); } + /* public void GivenIHaveAddedXForwardedForHeader(string value) { diff --git a/test/Ocelot.AcceptanceTests/UpstreamHostTests.cs b/test/Ocelot.AcceptanceTests/UpstreamHostTests.cs index 16e123a7..a6a495a1 100644 --- a/test/Ocelot.AcceptanceTests/UpstreamHostTests.cs +++ b/test/Ocelot.AcceptanceTests/UpstreamHostTests.cs @@ -58,7 +58,6 @@ namespace Ocelot.AcceptanceTests .BDDfy(); } - [Fact] public void should_return_response_200_with_simple_url_and_hosts_match_multiple_re_routes() { diff --git a/test/Ocelot.Benchmarks/Ocelot.Benchmarks.csproj b/test/Ocelot.Benchmarks/Ocelot.Benchmarks.csproj index 00e25330..8c63914c 100644 --- a/test/Ocelot.Benchmarks/Ocelot.Benchmarks.csproj +++ b/test/Ocelot.Benchmarks/Ocelot.Benchmarks.csproj @@ -11,6 +11,7 @@ false false false + ..\..\codeanalysis.ruleset @@ -19,6 +20,9 @@ + + all + diff --git a/test/Ocelot.Benchmarks/Program.cs b/test/Ocelot.Benchmarks/Program.cs index 231a816b..56b87404 100644 --- a/test/Ocelot.Benchmarks/Program.cs +++ b/test/Ocelot.Benchmarks/Program.cs @@ -8,7 +8,6 @@ namespace Ocelot.Benchmarks { var switcher = new BenchmarkSwitcher(new[] { typeof(UrlPathToUrlPathTemplateMatcherBenchmarks), - }); switcher.Run(args); diff --git a/test/Ocelot.IntegrationTests/AdministrationTests.cs b/test/Ocelot.IntegrationTests/AdministrationTests.cs index 3b2f6a35..763d642c 100644 --- a/test/Ocelot.IntegrationTests/AdministrationTests.cs +++ b/test/Ocelot.IntegrationTests/AdministrationTests.cs @@ -124,7 +124,6 @@ namespace Ocelot.IntegrationTests { Host = "127.0.0.1", } - }, ReRoutes = new List() { @@ -485,7 +484,6 @@ namespace Ocelot.IntegrationTests app.UseOcelot().Wait(); }); - _builderTwo = _webHostBuilderTwo.Build(); _builderTwo.Start(); diff --git a/test/Ocelot.IntegrationTests/Ocelot.IntegrationTests.csproj b/test/Ocelot.IntegrationTests/Ocelot.IntegrationTests.csproj index 6e1fdb4b..8dc250b2 100644 --- a/test/Ocelot.IntegrationTests/Ocelot.IntegrationTests.csproj +++ b/test/Ocelot.IntegrationTests/Ocelot.IntegrationTests.csproj @@ -11,6 +11,7 @@ false false false + ..\..\codeanalysis.ruleset @@ -18,29 +19,32 @@ - + - + - - - - - - - - - - - - - - - - - - + + + + all + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/Ocelot.IntegrationTests/RaftTests.cs b/test/Ocelot.IntegrationTests/RaftTests.cs index e93e9ee4..b8c24d5a 100644 --- a/test/Ocelot.IntegrationTests/RaftTests.cs +++ b/test/Ocelot.IntegrationTests/RaftTests.cs @@ -45,6 +45,7 @@ namespace Ocelot.IntegrationTests _builders = new List(); _threads = new List(); } + public void Dispose() { foreach (var builder in _builders) @@ -194,7 +195,6 @@ namespace Ocelot.IntegrationTests var stopwatch = Stopwatch.StartNew(); while(stopwatch.ElapsedMilliseconds < 10000) { - } } @@ -204,10 +204,9 @@ namespace Ocelot.IntegrationTests var stopwatch = Stopwatch.StartNew(); while(stopwatch.ElapsedMilliseconds < 2000) { - } - bool CommandCalledOnAllStateMachines() + bool CommandCalledOnAllStateMachines() { try { @@ -225,6 +224,7 @@ namespace Ocelot.IntegrationTests index.ShouldBe(1); } } + _httpClientForAssertions.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _token.AccessToken); var result = _httpClientForAssertions.GetAsync($"{peer.HostAndPort}/administration/configuration").Result; var json = result.Content.ReadAsStringAsync().Result; @@ -248,6 +248,7 @@ namespace Ocelot.IntegrationTests response.ReRoutes[i].UpstreamPathTemplate.ShouldBe(expecteds.Configuration.ReRoutes[i].UpstreamPathTemplate); response.ReRoutes[i].UpstreamHttpMethod.ShouldBe(expecteds.Configuration.ReRoutes[i].UpstreamHttpMethod); } + passed++; } @@ -384,7 +385,6 @@ namespace Ocelot.IntegrationTests var stopwatch = Stopwatch.StartNew(); while(stopwatch.ElapsedMilliseconds < 20000) { - } } } diff --git a/test/Ocelot.IntegrationTests/ThreadSafeHeadersTests.cs b/test/Ocelot.IntegrationTests/ThreadSafeHeadersTests.cs index f8533a04..e61fa63b 100644 --- a/test/Ocelot.IntegrationTests/ThreadSafeHeadersTests.cs +++ b/test/Ocelot.IntegrationTests/ThreadSafeHeadersTests.cs @@ -195,6 +195,7 @@ namespace Ocelot.IntegrationTests result.Result.ShouldBe(result.Random); } } + public void Dispose() { _builder?.Dispose(); @@ -208,7 +209,6 @@ namespace Ocelot.IntegrationTests { Result = result; Random = random; - } public int Result { get; private set; } diff --git a/test/Ocelot.ManualTest/Ocelot.ManualTest.csproj b/test/Ocelot.ManualTest/Ocelot.ManualTest.csproj index 7ec84c3d..ed0e2cb8 100644 --- a/test/Ocelot.ManualTest/Ocelot.ManualTest.csproj +++ b/test/Ocelot.ManualTest/Ocelot.ManualTest.csproj @@ -9,6 +9,7 @@ Exe Ocelot.ManualTest osx.10.11-x64;osx.10.12-x64;win7-x64;win10-x64 + ..\..\codeanalysis.ruleset @@ -38,6 +39,9 @@ + + all + diff --git a/test/Ocelot.UnitTests/Authentication/AuthenticationMiddlewareTests.cs b/test/Ocelot.UnitTests/Authentication/AuthenticationMiddlewareTests.cs index 07368127..e5cb64ae 100644 --- a/test/Ocelot.UnitTests/Authentication/AuthenticationMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Authentication/AuthenticationMiddlewareTests.cs @@ -6,24 +6,17 @@ namespace Ocelot.UnitTests.Authentication using System.Collections.Generic; using System.IO; using System.Text; - using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; - using Microsoft.Extensions.DependencyInjection; using Moq; using Ocelot.Authentication.Middleware; using Ocelot.Configuration.Builder; - using Ocelot.DownstreamRouteFinder; - using Ocelot.DownstreamRouteFinder.Middleware; - using Ocelot.DownstreamRouteFinder.UrlMatcher; using Ocelot.Logging; - using Ocelot.Responses; using Shouldly; using TestStack.BDDfy; using Xunit; public class AuthenticationMiddlewareTests { - private OkResponse _downstreamRoute; private AuthenticationMiddleware _middleware; private Mock _factory; private Mock _logger; @@ -49,7 +42,7 @@ namespace Ocelot.UnitTests.Authentication .BDDfy(); } - private void WhenICallTheMiddleware() + private void WhenICallTheMiddleware() { _next = async (context) => { byte[] byteArray = Encoding.ASCII.GetBytes("The user is authenticated"); @@ -89,7 +82,7 @@ namespace Ocelot.UnitTests.Authentication { string text = reader.ReadToEnd(); return text; - }; + } } } } diff --git a/test/Ocelot.UnitTests/Authorization/ClaimsAuthoriserTests.cs b/test/Ocelot.UnitTests/Authorization/ClaimsAuthoriserTests.cs index 0333268b..e2990864 100644 --- a/test/Ocelot.UnitTests/Authorization/ClaimsAuthoriserTests.cs +++ b/test/Ocelot.UnitTests/Authorization/ClaimsAuthoriserTests.cs @@ -28,7 +28,6 @@ namespace Ocelot.UnitTests.Authorization this.Given(x => x.GivenAClaimsPrincipal(new ClaimsPrincipal(new ClaimsIdentity(new List { new Claim("UserType", "registered"), - })))) .And(x => x.GivenARouteClaimsRequirement(new Dictionary { diff --git a/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareRealCacheTests.cs b/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareRealCacheTests.cs index 4e9ef04d..c0a76b2a 100644 --- a/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareRealCacheTests.cs +++ b/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareRealCacheTests.cs @@ -1,5 +1,4 @@ using Ocelot.Errors; -using Ocelot.Infrastructure.RequestData; using Ocelot.Middleware; namespace Ocelot.UnitTests.Cache @@ -11,26 +10,19 @@ namespace Ocelot.UnitTests.Cache using Shouldly; using System.Collections.Generic; using System.Net.Http; - using Microsoft.AspNetCore.Builder; - using Microsoft.Extensions.DependencyInjection; using Moq; using Ocelot.Cache; using Ocelot.Cache.Middleware; using Ocelot.Configuration; using Ocelot.Configuration.Builder; - using Ocelot.DownstreamRouteFinder; - using Ocelot.DownstreamRouteFinder.UrlMatcher; using Ocelot.Logging; - using Ocelot.Responses; using TestStack.BDDfy; using Xunit; - using Ocelot.DownstreamRouteFinder.Middleware; using Microsoft.AspNetCore.Http; public class OutputCacheMiddlewareRealCacheTests { private IOcelotCache _cacheManager; - private CachedResponse _response; private OutputCacheMiddleware _middleware; private DownstreamContext _downstreamContext; private OcelotRequestDelegate _next; diff --git a/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareTests.cs b/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareTests.cs index 42c1e695..31cc11a8 100644 --- a/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareTests.cs @@ -110,7 +110,6 @@ namespace Ocelot.UnitTests.Cache private void GivenThereAreNoErrors() { _downstreamContext.Errors = new List(); - } private void ThenTheCacheGetIsCalledCorrectly() diff --git a/test/Ocelot.UnitTests/Claims/AddClaimsToRequestTests.cs b/test/Ocelot.UnitTests/Claims/AddClaimsToRequestTests.cs index ac60ee8b..33ff1e06 100644 --- a/test/Ocelot.UnitTests/Claims/AddClaimsToRequestTests.cs +++ b/test/Ocelot.UnitTests/Claims/AddClaimsToRequestTests.cs @@ -93,7 +93,6 @@ namespace Ocelot.UnitTests.Claims .BDDfy(); } - private void GivenClaimsToThings(List configuration) { _claimsToThings = configuration; @@ -129,7 +128,6 @@ namespace Ocelot.UnitTests.Claims private void ThenTheResultIsError() { - _result.IsError.ShouldBe(true); } diff --git a/test/Ocelot.UnitTests/Claims/ClaimsBuilderMiddlewareTests.cs b/test/Ocelot.UnitTests/Claims/ClaimsBuilderMiddlewareTests.cs index be266f9e..f6bf052c 100644 --- a/test/Ocelot.UnitTests/Claims/ClaimsBuilderMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Claims/ClaimsBuilderMiddlewareTests.cs @@ -15,12 +15,10 @@ namespace Ocelot.UnitTests.Claims using Ocelot.Responses; using TestStack.BDDfy; using Xunit; - using Ocelot.DownstreamRouteFinder.Middleware; public class ClaimsBuilderMiddlewareTests { private readonly Mock _addHeaders; - private Response _downstreamRoute; private Mock _loggerFactory; private Mock _logger; private readonly ClaimsBuilderMiddleware _middleware; @@ -68,7 +66,6 @@ namespace Ocelot.UnitTests.Claims _middleware.Invoke(_downstreamContext).GetAwaiter().GetResult(); } - private void GivenTheDownStreamRouteIs(DownstreamRoute downstreamRoute) { _downstreamContext.TemplatePlaceholderNameAndValues = downstreamRoute.TemplatePlaceholderNameAndValues; diff --git a/test/Ocelot.UnitTests/Configuration/ClaimsToThingCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/ClaimsToThingCreatorTests.cs index 656fe5dc..522d853f 100644 --- a/test/Ocelot.UnitTests/Configuration/ClaimsToThingCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/ClaimsToThingCreatorTests.cs @@ -79,6 +79,7 @@ namespace Ocelot.UnitTests.Configuration { _result.Count.ShouldBeGreaterThan(0); } + private void GivenTheFollowingDictionary(Dictionary claimsToThings) { _claimsToThings = claimsToThings; @@ -107,4 +108,4 @@ namespace Ocelot.UnitTests.Configuration .Verify(x => x.Extract(_claimsToThings.First().Key, _claimsToThings.First().Value), Times.Once); } } -} \ No newline at end of file +} diff --git a/test/Ocelot.UnitTests/Configuration/ConfigurationFluentValidationTests.cs b/test/Ocelot.UnitTests/Configuration/ConfigurationFluentValidationTests.cs index ba7bfd01..d33bb6f4 100644 --- a/test/Ocelot.UnitTests/Configuration/ConfigurationFluentValidationTests.cs +++ b/test/Ocelot.UnitTests/Configuration/ConfigurationFluentValidationTests.cs @@ -588,7 +588,8 @@ namespace Ocelot.UnitTests.Configuration AuthenticationOptions = new FileAuthenticationOptions() { AuthenticationProviderKey = "Test" - } } + } + } } })) .When(x => x.WhenIValidateTheConfiguration()) @@ -869,7 +870,6 @@ namespace Ocelot.UnitTests.Configuration .BDDfy(); } - [Theory] [InlineData(null)] [InlineData("")] @@ -981,7 +981,8 @@ namespace Ocelot.UnitTests.Configuration .And(x => x.ThenTheErrorMessageAtPositionIs(0, "When not using service discovery DownstreamHostAndPorts must be set and not empty or Ocelot cannot find your service!")) .BDDfy(); } - [Fact] + + [Fact] public void configuration_is_not_valid_when_host_and_port_is_empty() { this.Given(x => x.GivenAConfiguration(new FileConfiguration @@ -1007,7 +1008,6 @@ namespace Ocelot.UnitTests.Configuration .BDDfy(); } - private void GivenAConfiguration(FileConfiguration fileConfiguration) { _fileConfiguration = fileConfiguration; diff --git a/test/Ocelot.UnitTests/Configuration/ConsulFileConfigurationPollerTests.cs b/test/Ocelot.UnitTests/Configuration/ConsulFileConfigurationPollerTests.cs index 64104871..4a6faba2 100644 --- a/test/Ocelot.UnitTests/Configuration/ConsulFileConfigurationPollerTests.cs +++ b/test/Ocelot.UnitTests/Configuration/ConsulFileConfigurationPollerTests.cs @@ -12,7 +12,6 @@ using Xunit; using Shouldly; using static Ocelot.UnitTests.Wait; - namespace Ocelot.UnitTests.Configuration { public class ConsulFileConfigurationPollerTests : IDisposable @@ -34,6 +33,7 @@ namespace Ocelot.UnitTests.Configuration _repo.Setup(x => x.Get()).ReturnsAsync(new OkResponse(_fileConfig)); _poller = new ConsulFileConfigurationPoller(_factory.Object, _repo.Object, _setter.Object); } + public void Dispose() { _poller.Dispose(); @@ -49,7 +49,6 @@ namespace Ocelot.UnitTests.Configuration [Fact] public void should_call_setter_when_gets_new_config() { - var newConfig = new FileConfiguration { ReRoutes = new List { @@ -84,7 +83,7 @@ namespace Ocelot.UnitTests.Configuration _setter.Verify(x => x.Set(fileConfig), Times.Once); return true; } - catch(Exception ex) + catch(Exception) { return false; } diff --git a/test/Ocelot.UnitTests/Configuration/FileConfigurationCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/FileConfigurationCreatorTests.cs index 8bb0ecd2..4de07053 100644 --- a/test/Ocelot.UnitTests/Configuration/FileConfigurationCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/FileConfigurationCreatorTests.cs @@ -502,7 +502,6 @@ namespace Ocelot.UnitTests.Configuration .WithUseServiceDiscovery(false) .Build(); - this.Given(x => x.GivenTheConfigIs(new FileConfiguration { ReRoutes = new List @@ -545,7 +544,6 @@ namespace Ocelot.UnitTests.Configuration .WithUpstreamTemplatePattern(new UpstreamPathTemplate("(?i)/api/products/.*/$", 1)) .Build(); - this.Given(x => x.GivenTheConfigIs(new FileConfiguration { ReRoutes = new List @@ -823,8 +821,7 @@ namespace Ocelot.UnitTests.Configuration result.DownstreamReRoute[0].ClaimsToClaims.Count.ShouldBe(expected.DownstreamReRoute[0].ClaimsToClaims.Count); result.DownstreamReRoute[0].ClaimsToHeaders.Count.ShouldBe(expected.DownstreamReRoute[0].ClaimsToHeaders.Count); result.DownstreamReRoute[0].ClaimsToQueries.Count.ShouldBe(expected.DownstreamReRoute[0].ClaimsToQueries.Count); - result.DownstreamReRoute[0].RequestIdKey.ShouldBe(expected.DownstreamReRoute[0].RequestIdKey); - + result.DownstreamReRoute[0].RequestIdKey.ShouldBe(expected.DownstreamReRoute[0].RequestIdKey); } } @@ -916,7 +913,6 @@ namespace Ocelot.UnitTests.Configuration .Setup(x => x.Create(It.IsAny())).Returns(serviceProviderConfiguration); } - private void GivenTheFollowingRegionIsReturned(string region) { _regionCreator diff --git a/test/Ocelot.UnitTests/Configuration/FileConfigurationProviderTests.cs b/test/Ocelot.UnitTests/Configuration/FileConfigurationProviderTests.cs index be3df6cc..506da50c 100644 --- a/test/Ocelot.UnitTests/Configuration/FileConfigurationProviderTests.cs +++ b/test/Ocelot.UnitTests/Configuration/FileConfigurationProviderTests.cs @@ -38,8 +38,6 @@ namespace Ocelot.UnitTests.Configuration .BDDfy(); } - - private void GivenTheConfigurationIs(FileConfiguration fileConfiguration) { _fileConfiguration = fileConfiguration; @@ -59,4 +57,4 @@ namespace Ocelot.UnitTests.Configuration .Verify(x => x.Get(), Times.Once); } } -} \ No newline at end of file +} diff --git a/test/Ocelot.UnitTests/Configuration/FileConfigurationRepositoryTests.cs b/test/Ocelot.UnitTests/Configuration/FileConfigurationRepositoryTests.cs index e74d0067..15dd3729 100644 --- a/test/Ocelot.UnitTests/Configuration/FileConfigurationRepositoryTests.cs +++ b/test/Ocelot.UnitTests/Configuration/FileConfigurationRepositoryTests.cs @@ -111,7 +111,7 @@ namespace Ocelot.UnitTests.Configuration } } - private void GivenTheConfigurationIs(FileConfiguration fileConfiguration) + private void GivenTheConfigurationIs(FileConfiguration fileConfiguration) { var configurationPath = $"{AppContext.BaseDirectory}/configuration{(string.IsNullOrEmpty(_environmentName) ? string.Empty : ".")}{_environmentName}.json"; diff --git a/test/Ocelot.UnitTests/Configuration/FileConfigurationSetterTests.cs b/test/Ocelot.UnitTests/Configuration/FileConfigurationSetterTests.cs index 60365661..e16148f2 100644 --- a/test/Ocelot.UnitTests/Configuration/FileConfigurationSetterTests.cs +++ b/test/Ocelot.UnitTests/Configuration/FileConfigurationSetterTests.cs @@ -48,7 +48,6 @@ namespace Ocelot.UnitTests.Configuration .BDDfy(); } - [Fact] public void should_return_error_if_unable_to_set_file_configuration() { @@ -110,4 +109,4 @@ namespace Ocelot.UnitTests.Configuration .Verify(x => x.AddOrReplace(_configuration.Data), Times.Once); } } -} \ No newline at end of file +} diff --git a/test/Ocelot.UnitTests/Configuration/HeaderFindAndReplaceCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/HeaderFindAndReplaceCreatorTests.cs index 76c3c47f..37ee8957 100644 --- a/test/Ocelot.UnitTests/Configuration/HeaderFindAndReplaceCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/HeaderFindAndReplaceCreatorTests.cs @@ -33,13 +33,11 @@ namespace Ocelot.UnitTests.Configuration UpstreamHeaderTransform = new Dictionary { {"Test", "Test, Chicken"}, - {"Moop", "o, a"} }, DownstreamHeaderTransform = new Dictionary { {"Pop", "West, East"}, - {"Bop", "e, r"} } }; @@ -86,7 +84,6 @@ namespace Ocelot.UnitTests.Configuration .BDDfy(); } - [Fact] public void should_use_base_url_partial_placeholder() { @@ -155,4 +152,4 @@ namespace Ocelot.UnitTests.Configuration } } } -} \ No newline at end of file +} diff --git a/test/Ocelot.UnitTests/Configuration/HttpHandlerOptionsCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/HttpHandlerOptionsCreatorTests.cs index 3821ef6b..b0b11bfc 100644 --- a/test/Ocelot.UnitTests/Configuration/HttpHandlerOptionsCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/HttpHandlerOptionsCreatorTests.cs @@ -7,7 +7,6 @@ using Xunit; namespace Ocelot.UnitTests.Configuration { - public class HttpHandlerOptionsCreatorTests { private readonly IHttpHandlerOptionsCreator _httpHandlerOptionsCreator; diff --git a/test/Ocelot.UnitTests/Configuration/UpstreamTemplatePatternCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/UpstreamTemplatePatternCreatorTests.cs index ab7fba4a..9dce0e50 100644 --- a/test/Ocelot.UnitTests/Configuration/UpstreamTemplatePatternCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/UpstreamTemplatePatternCreatorTests.cs @@ -35,7 +35,6 @@ namespace Ocelot.UnitTests.Configuration .BDDfy(); } - [Fact] public void should_match_forward_slash_or_no_forward_slash_if_template_end_with_forward_slash() { @@ -70,7 +69,7 @@ namespace Ocelot.UnitTests.Configuration [Fact] public void should_create_template_pattern_that_matches_anything_to_end_of_string() { - var fileReRoute = new FileReRoute + var fileReRoute = new FileReRoute { UpstreamPathTemplate = "/api/products/{productId}", ReRouteIsCaseSensitive = true @@ -181,4 +180,4 @@ namespace Ocelot.UnitTests.Configuration _result.Priority.ShouldBe(v); } } -} \ No newline at end of file +} diff --git a/test/Ocelot.UnitTests/Controllers/FileConfigurationControllerTests.cs b/test/Ocelot.UnitTests/Controllers/FileConfigurationControllerTests.cs index 0d95f0ea..c0ae8b87 100644 --- a/test/Ocelot.UnitTests/Controllers/FileConfigurationControllerTests.cs +++ b/test/Ocelot.UnitTests/Controllers/FileConfigurationControllerTests.cs @@ -111,7 +111,6 @@ namespace Ocelot.UnitTests.Controllers .BDDfy(); } - private void ThenTheNodeIsCalledCorrectly() { _node.Verify(x => x.Accept(It.IsAny()), Times.Once); diff --git a/test/Ocelot.UnitTests/DependencyInjection/OcelotBuilderTests.cs b/test/Ocelot.UnitTests/DependencyInjection/OcelotBuilderTests.cs index 6f256d7f..c2f35990 100644 --- a/test/Ocelot.UnitTests/DependencyInjection/OcelotBuilderTests.cs +++ b/test/Ocelot.UnitTests/DependencyInjection/OcelotBuilderTests.cs @@ -15,7 +15,6 @@ using Ocelot.DependencyInjection; using Ocelot.Requester; using Ocelot.UnitTests.Requester; using Shouldly; -using System; using IdentityServer4.AccessTokenValidation; using TestStack.BDDfy; using Xunit; @@ -38,6 +37,7 @@ namespace Ocelot.UnitTests.DependencyInjection _services.AddSingleton(_configRoot); _maxRetries = 100; } + private Exception _ex; [Fact] @@ -69,7 +69,6 @@ namespace Ocelot.UnitTests.DependencyInjection .BDDfy(); } - [Fact] public void should_set_up_cache_manager() { @@ -102,9 +101,7 @@ namespace Ocelot.UnitTests.DependencyInjection [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)) @@ -152,7 +149,6 @@ namespace Ocelot.UnitTests.DependencyInjection .BDDfy(); } - [Fact] public void should_set_up_without_passing_in_config() { diff --git a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs index b7761c60..cb5c2a67 100644 --- a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs +++ b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs @@ -35,7 +35,6 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder _downstreamRouteFinder = new Ocelot.DownstreamRouteFinder.Finder.DownstreamRouteFinder(_mockMatcher.Object, _finder.Object); } - [Fact] public void should_return_highest_priority_when_first() { @@ -182,7 +181,6 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder .BDDfy(); } - [Fact] public void should_not_append_slash_to_upstream_url_path() { @@ -598,7 +596,6 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder .BDDfy(); } - [Fact] public void should_return_route_when_host_matches_but_null_host_on_same_path_first() { diff --git a/test/Ocelot.UnitTests/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinderTests.cs b/test/Ocelot.UnitTests/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinderTests.cs index afd1b3ae..29bc8fcd 100644 --- a/test/Ocelot.UnitTests/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinderTests.cs +++ b/test/Ocelot.UnitTests/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinderTests.cs @@ -30,7 +30,6 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher .BDDfy(); } - [Fact] public void can_match_down_stream_url_with_nothing_then_placeholder_no_value_is_blank() { @@ -264,4 +263,4 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher _result = _finder.Find(_downstreamUrlPath, _downstreamPathTemplate); } } -} \ No newline at end of file +} diff --git a/test/Ocelot.UnitTests/Errors/ExceptionHandlerMiddlewareTests.cs b/test/Ocelot.UnitTests/Errors/ExceptionHandlerMiddlewareTests.cs index c5180f74..89eaaa38 100644 --- a/test/Ocelot.UnitTests/Errors/ExceptionHandlerMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Errors/ExceptionHandlerMiddlewareTests.cs @@ -29,7 +29,6 @@ namespace Ocelot.UnitTests.Errors private DownstreamContext _downstreamContext; private OcelotRequestDelegate _next; - public ExceptionHandlerMiddlewareTests() { _provider = new Mock(); @@ -135,7 +134,7 @@ namespace Ocelot.UnitTests.Errors private void GivenTheConfigThrows() { - var ex = new Exception("outer", new Exception("inner")); + var ex = new Exception("outer", new Exception("inner")); _provider .Setup(x => x.Get()).ThrowsAsync(ex); } @@ -174,7 +173,6 @@ namespace Ocelot.UnitTests.Errors .Setup(x => x.Get()).ReturnsAsync(response); } - private void GivenAnExceptionWillNotBeThrownDownstream() { _shouldThrowAnException = false; @@ -192,7 +190,6 @@ namespace Ocelot.UnitTests.Errors private void ThenTheResponseIsError() { - _downstreamContext.HttpContext.Response.StatusCode.ShouldBe(500); } diff --git a/test/Ocelot.UnitTests/Headers/AddHeadersToRequestTests.cs b/test/Ocelot.UnitTests/Headers/AddHeadersToRequestTests.cs index f69c6b9e..0a8290bc 100644 --- a/test/Ocelot.UnitTests/Headers/AddHeadersToRequestTests.cs +++ b/test/Ocelot.UnitTests/Headers/AddHeadersToRequestTests.cs @@ -130,7 +130,6 @@ namespace Ocelot.UnitTests.Headers private void ThenTheResultIsError() { - _result.IsError.ShouldBe(true); } diff --git a/test/Ocelot.UnitTests/Headers/HttpHeadersTransformationMiddlewareTests.cs b/test/Ocelot.UnitTests/Headers/HttpHeadersTransformationMiddlewareTests.cs index 90a24eaa..0a69bf89 100644 --- a/test/Ocelot.UnitTests/Headers/HttpHeadersTransformationMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Headers/HttpHeadersTransformationMiddlewareTests.cs @@ -80,7 +80,6 @@ namespace Ocelot.UnitTests.Headers _downstreamContext.TemplatePlaceholderNameAndValues = dR.TemplatePlaceholderNameAndValues; _downstreamContext.DownstreamReRoute = dR.ReRoute.DownstreamReRoute[0]; - } private void ThenTheIHttpContextRequestHeaderReplacerIsCalledCorrectly() diff --git a/test/Ocelot.UnitTests/Headers/HttpResponseHeaderReplacerTests.cs b/test/Ocelot.UnitTests/Headers/HttpResponseHeaderReplacerTests.cs index de8161c9..95ae6e6d 100644 --- a/test/Ocelot.UnitTests/Headers/HttpResponseHeaderReplacerTests.cs +++ b/test/Ocelot.UnitTests/Headers/HttpResponseHeaderReplacerTests.cs @@ -22,6 +22,7 @@ namespace Ocelot.UnitTests.Headers { _replacer = new HttpResponseHeaderReplacer(); } + [Fact] public void should_replace_headers() { @@ -97,7 +98,6 @@ namespace Ocelot.UnitTests.Headers .BDDfy(); } - [Fact] public void should_replace_downstream_base_url_with_ocelot_base_url_and_path() { @@ -232,4 +232,4 @@ namespace Ocelot.UnitTests.Headers } } } -} \ No newline at end of file +} diff --git a/test/Ocelot.UnitTests/Infrastructure/HttpDataRepositoryTests.cs b/test/Ocelot.UnitTests/Infrastructure/HttpDataRepositoryTests.cs index df5068d3..c9f66009 100644 --- a/test/Ocelot.UnitTests/Infrastructure/HttpDataRepositoryTests.cs +++ b/test/Ocelot.UnitTests/Infrastructure/HttpDataRepositoryTests.cs @@ -21,13 +21,14 @@ namespace Ocelot.UnitTests.Infrastructure _httpDataRepository = new HttpDataRepository(_httpContextAccessor); } - //TODO - Additional tests -> Type mistmatch aka Add string, request int - //TODO - Additional tests -> HttpContent null. This should never happen + /* + TODO - Additional tests -> Type mistmatch aka Add string, request int + TODO - Additional tests -> HttpContent null. This should never happen + */ [Fact] public void get_returns_correct_key_from_http_context() { - this.Given(x => x.GivenAHttpContextContaining("key", "string")) .When(x => x.GetIsCalledWithKey("key")) .Then(x => x.ThenTheResultIsAnOkResponse("string")) @@ -83,6 +84,5 @@ namespace Ocelot.UnitTests.Infrastructure _result.ShouldBeOfType>(); ((OkResponse)_result).Data.ShouldBe(resultValue); } - } } diff --git a/test/Ocelot.UnitTests/Infrastructure/ScopesAuthoriserTests.cs b/test/Ocelot.UnitTests/Infrastructure/ScopesAuthoriserTests.cs index 1d476db3..08f6a46d 100644 --- a/test/Ocelot.UnitTests/Infrastructure/ScopesAuthoriserTests.cs +++ b/test/Ocelot.UnitTests/Infrastructure/ScopesAuthoriserTests.cs @@ -35,7 +35,6 @@ namespace Ocelot.UnitTests.Infrastructure .BDDfy(); } - [Fact] public void should_return_ok_if_null_allowed_scopes() { @@ -121,4 +120,4 @@ namespace Ocelot.UnitTests.Infrastructure { } } -} \ No newline at end of file +} diff --git a/test/Ocelot.UnitTests/LoadBalancer/LeastConnectionTests.cs b/test/Ocelot.UnitTests/LoadBalancer/LeastConnectionTests.cs index e372ac4e..687f8f40 100644 --- a/test/Ocelot.UnitTests/LoadBalancer/LeastConnectionTests.cs +++ b/test/Ocelot.UnitTests/LoadBalancer/LeastConnectionTests.cs @@ -91,7 +91,6 @@ namespace Ocelot.UnitTests.LoadBalancer hostAndPortTwo.Data.DownstreamHost.ShouldBe("127.0.0.2"); _leastConnection.Release(hostAndPortOne.Data); _leastConnection.Release(hostAndPortTwo.Data); - } private async Task LeaseDelayAndRelease() diff --git a/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerHouseTests.cs b/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerHouseTests.cs index f5604ab1..e8808f17 100644 --- a/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerHouseTests.cs +++ b/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerHouseTests.cs @@ -17,9 +17,7 @@ namespace Ocelot.UnitTests.LoadBalancer private DownstreamReRoute _reRoute; private ILoadBalancer _loadBalancer; private readonly LoadBalancerHouse _loadBalancerHouse; - private Response _addResult; private Response _getResult; - private string _key; private readonly Mock _factory; private ServiceProviderConfiguration _serviceProviderConfig; @@ -116,7 +114,6 @@ namespace Ocelot.UnitTests.LoadBalancer _factory.Verify(x => x.Get(_reRoute, _serviceProviderConfig), Times.Once); } - private void GivenThereIsALoadBalancer(DownstreamReRoute reRoute, ILoadBalancer loadBalancer) { _reRoute = reRoute; diff --git a/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerMiddlewareTests.cs b/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerMiddlewareTests.cs index 310c1818..242463a2 100644 --- a/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerMiddlewareTests.cs @@ -4,15 +4,10 @@ namespace Ocelot.UnitTests.LoadBalancer { using System.Collections.Generic; using System.Net.Http; - using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; - using Microsoft.Extensions.DependencyInjection; using Moq; using Ocelot.Configuration; using Ocelot.Configuration.Builder; - using Ocelot.Configuration.Provider; - using Ocelot.DownstreamRouteFinder; - using Ocelot.DownstreamRouteFinder.Middleware; using Ocelot.Errors; using Ocelot.LoadBalancer.LoadBalancers; using Ocelot.LoadBalancer.Middleware; @@ -28,7 +23,6 @@ namespace Ocelot.UnitTests.LoadBalancer private readonly Mock _loadBalancerHouse; private readonly Mock _loadBalancer; private ServiceHostAndPort _hostAndPort; - private OkResponse _downstreamRoute; private ErrorResponse _getLoadBalancerHouseError; private ErrorResponse _getHostAndPortError; private HttpRequestMessage _downstreamRequest; @@ -188,7 +182,6 @@ namespace Ocelot.UnitTests.LoadBalancer { _downstreamContext.IsError.ShouldBeTrue(); _downstreamContext.Errors.ShouldBe(_getHostAndPortError.Errors); - } private void ThenTheDownstreamUrlIsReplacedWith(string expectedUri) diff --git a/test/Ocelot.UnitTests/Middleware/MultiplexerTests.cs b/test/Ocelot.UnitTests/Middleware/MultiplexerTests.cs index 8a0e5670..adef00d5 100644 --- a/test/Ocelot.UnitTests/Middleware/MultiplexerTests.cs +++ b/test/Ocelot.UnitTests/Middleware/MultiplexerTests.cs @@ -58,7 +58,6 @@ namespace Ocelot.UnitTests.Middleware private void WhenIMultiplex() { _multiplexer.Multiplex(_context, _reRoute, _pipeline).GetAwaiter().GetResult(); - } private void ThePipelineIsCalled(int expected) diff --git a/test/Ocelot.UnitTests/Middleware/OcelotPiplineBuilderTests.cs b/test/Ocelot.UnitTests/Middleware/OcelotPiplineBuilderTests.cs index dbb0ae63..988d0b21 100644 --- a/test/Ocelot.UnitTests/Middleware/OcelotPiplineBuilderTests.cs +++ b/test/Ocelot.UnitTests/Middleware/OcelotPiplineBuilderTests.cs @@ -1,6 +1,5 @@ namespace Ocelot.UnitTests.Middleware { - using System; using System.Collections.Generic; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Internal; @@ -17,9 +16,7 @@ public class OcelotPiplineBuilderTests { private readonly IServiceCollection _services; - private IServiceProvider _serviceProvider; private readonly IConfiguration _configRoot; - private IOcelotBuilder _ocelotBuilder; private DownstreamContext _downstreamContext; private int _counter; diff --git a/test/Ocelot.UnitTests/Middleware/SimpleJsonResponseAggregatorTests.cs b/test/Ocelot.UnitTests/Middleware/SimpleJsonResponseAggregatorTests.cs index b5fabaee..27d1b7e0 100644 --- a/test/Ocelot.UnitTests/Middleware/SimpleJsonResponseAggregatorTests.cs +++ b/test/Ocelot.UnitTests/Middleware/SimpleJsonResponseAggregatorTests.cs @@ -42,7 +42,6 @@ namespace Ocelot.UnitTests.Middleware .WithDownstreamReRoutes(downstreamReRoutes) .Build(); - var billDownstreamContext = new DownstreamContext(new DefaultHttpContext()) { DownstreamResponse = diff --git a/test/Ocelot.UnitTests/Ocelot.UnitTests.csproj b/test/Ocelot.UnitTests/Ocelot.UnitTests.csproj index fcc2c7e2..80084a4d 100644 --- a/test/Ocelot.UnitTests/Ocelot.UnitTests.csproj +++ b/test/Ocelot.UnitTests/Ocelot.UnitTests.csproj @@ -12,6 +12,7 @@ false false false + ..\..\codeanalysis.ruleset @@ -37,6 +38,9 @@ + + all + diff --git a/test/Ocelot.UnitTests/RateLimit/ClientRateLimitMiddlewareTests.cs b/test/Ocelot.UnitTests/RateLimit/ClientRateLimitMiddlewareTests.cs index 168781bc..57d2fdc8 100644 --- a/test/Ocelot.UnitTests/RateLimit/ClientRateLimitMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/RateLimit/ClientRateLimitMiddlewareTests.cs @@ -19,7 +19,6 @@ namespace Ocelot.UnitTests.RateLimit using Microsoft.Extensions.Caching.Memory; using System.IO; - public class ClientRateLimitMiddlewareTests { private int _responseStatusCode; diff --git a/test/Ocelot.UnitTests/Request/DownstreamRequestInitialiserMiddlewareTests.cs b/test/Ocelot.UnitTests/Request/DownstreamRequestInitialiserMiddlewareTests.cs index 5661ace6..2bd26a4b 100644 --- a/test/Ocelot.UnitTests/Request/DownstreamRequestInitialiserMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Request/DownstreamRequestInitialiserMiddlewareTests.cs @@ -36,7 +36,6 @@ namespace Ocelot.UnitTests.Request public DownstreamRequestInitialiserMiddlewareTests() { - _httpContext = new Mock(); _httpRequest = new Mock(); _requestMapper = new Mock(); diff --git a/test/Ocelot.UnitTests/RequestId/ReRouteRequestIdMiddlewareTests.cs b/test/Ocelot.UnitTests/RequestId/ReRouteRequestIdMiddlewareTests.cs index 40276547..f6bf4eb7 100644 --- a/test/Ocelot.UnitTests/RequestId/ReRouteRequestIdMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/RequestId/ReRouteRequestIdMiddlewareTests.cs @@ -4,7 +4,6 @@ namespace Ocelot.UnitTests.RequestId { using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Primitives; - using Ocelot.DownstreamRouteFinder.Middleware; using Ocelot.Infrastructure.RequestData; using System; using System.Collections.Generic; @@ -24,7 +23,6 @@ namespace Ocelot.UnitTests.RequestId public class ReRouteRequestIdMiddlewareTests { private readonly HttpRequestMessage _downstreamRequest; - private Response _downstreamRoute; private string _value; private string _key; private Mock _loggerFactory; @@ -165,7 +163,6 @@ namespace Ocelot.UnitTests.RequestId _repo.Verify(x => x.Update("RequestId", _value), Times.Once); } - private void GivenTheDownStreamRouteIs(DownstreamRoute downstreamRoute) { _downstreamContext.TemplatePlaceholderNameAndValues = downstreamRoute.TemplatePlaceholderNameAndValues; diff --git a/test/Ocelot.UnitTests/Requester/DelegatingHandlerHandlerProviderFactoryTests.cs b/test/Ocelot.UnitTests/Requester/DelegatingHandlerHandlerProviderFactoryTests.cs index e6942681..c63e04d2 100644 --- a/test/Ocelot.UnitTests/Requester/DelegatingHandlerHandlerProviderFactoryTests.cs +++ b/test/Ocelot.UnitTests/Requester/DelegatingHandlerHandlerProviderFactoryTests.cs @@ -41,7 +41,6 @@ namespace Ocelot.UnitTests.Requester .Returns(qosProvider); } - [Fact] public void should_all_from_all_routes_provider_and_qos() { diff --git a/test/Ocelot.UnitTests/Requester/FakeDelegatingHandler.cs b/test/Ocelot.UnitTests/Requester/FakeDelegatingHandler.cs index 545e956e..a53487a3 100644 --- a/test/Ocelot.UnitTests/Requester/FakeDelegatingHandler.cs +++ b/test/Ocelot.UnitTests/Requester/FakeDelegatingHandler.cs @@ -9,13 +9,13 @@ namespace Ocelot.UnitTests.Requester { public FakeDelegatingHandler() { - } public FakeDelegatingHandler(int order) { Order = order; } + public int Order {get;private set;} public DateTime TimeCalled {get;private set;} @@ -25,4 +25,4 @@ namespace Ocelot.UnitTests.Requester return new HttpResponseMessage(); } } -} \ No newline at end of file +} diff --git a/test/Ocelot.UnitTests/Requester/HttpClientBuilderTests.cs b/test/Ocelot.UnitTests/Requester/HttpClientBuilderTests.cs index b5d7e1e6..b788c826 100644 --- a/test/Ocelot.UnitTests/Requester/HttpClientBuilderTests.cs +++ b/test/Ocelot.UnitTests/Requester/HttpClientBuilderTests.cs @@ -17,7 +17,6 @@ namespace Ocelot.UnitTests.Requester private readonly HttpClientBuilder _builder; private readonly Mock _house; private readonly Mock _provider; - private IHttpClientBuilder _builderResult; private IHttpClient _httpClient; private HttpResponseMessage _response; private DownstreamReRoute _request; diff --git a/test/Ocelot.UnitTests/Requester/QosProviderHouseTests.cs b/test/Ocelot.UnitTests/Requester/QosProviderHouseTests.cs index 487a3509..ae027143 100644 --- a/test/Ocelot.UnitTests/Requester/QosProviderHouseTests.cs +++ b/test/Ocelot.UnitTests/Requester/QosProviderHouseTests.cs @@ -13,7 +13,6 @@ namespace Ocelot.UnitTests.Requester { private IQoSProvider _qoSProvider; private readonly QosProviderHouse _qosProviderHouse; - private Response _addResult; private Response _getResult; private DownstreamReRoute _reRoute; private readonly Mock _factory; @@ -111,7 +110,6 @@ namespace Ocelot.UnitTests.Requester _getResult.Data.ShouldBe(_qoSProvider); } - private void GivenThereIsAQoSProvider(DownstreamReRoute reRoute, IQoSProvider qoSProvider) { _reRoute = reRoute; diff --git a/test/Ocelot.UnitTests/Responder/ErrorsToHttpStatusCodeMapperTests.cs b/test/Ocelot.UnitTests/Responder/ErrorsToHttpStatusCodeMapperTests.cs index 9922df6a..9800ffef 100644 --- a/test/Ocelot.UnitTests/Responder/ErrorsToHttpStatusCodeMapperTests.cs +++ b/test/Ocelot.UnitTests/Responder/ErrorsToHttpStatusCodeMapperTests.cs @@ -42,10 +42,9 @@ namespace Ocelot.UnitTests.Responder [InlineData(OcelotErrorCode.RequestTimedOutError)] public void should_return_service_unavailable(OcelotErrorCode errorCode) { - ShouldMapErrorToStatusCode(OcelotErrorCode.RequestTimedOutError, HttpStatusCode.ServiceUnavailable); + ShouldMapErrorToStatusCode(errorCode, HttpStatusCode.ServiceUnavailable); } - [Theory] [InlineData(OcelotErrorCode.CannotAddDataError)] [InlineData(OcelotErrorCode.CannotFindDataError)] diff --git a/test/Ocelot.UnitTests/Responder/ResponderMiddlewareTests.cs b/test/Ocelot.UnitTests/Responder/ResponderMiddlewareTests.cs index fb0720b4..54b795a2 100644 --- a/test/Ocelot.UnitTests/Responder/ResponderMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Responder/ResponderMiddlewareTests.cs @@ -4,7 +4,6 @@ using Ocelot.Middleware; namespace Ocelot.UnitTests.Responder { using Microsoft.AspNetCore.Http; - using Ocelot.DownstreamRouteFinder.Middleware; using System.Net.Http; using Moq; using Ocelot.DownstreamRouteFinder.Finder; @@ -12,7 +11,6 @@ namespace Ocelot.UnitTests.Responder using Ocelot.Logging; using Ocelot.Responder; using Ocelot.Responder.Middleware; - using Ocelot.Responses; using TestStack.BDDfy; using Xunit; @@ -20,14 +18,12 @@ namespace Ocelot.UnitTests.Responder { private readonly Mock _responder; private readonly Mock _codeMapper; - private OkResponse _response; private Mock _loggerFactory; private Mock _logger; private readonly ResponderMiddleware _middleware; private readonly DownstreamContext _downstreamContext; private OcelotRequestDelegate _next; - public ResponderMiddlewareTests() { _responder = new Mock(); diff --git a/test/Ocelot.UnitTests/ServiceDiscovery/ServiceRegistryTests.cs b/test/Ocelot.UnitTests/ServiceDiscovery/ServiceRegistryTests.cs index 8a41fe7e..1079f201 100644 --- a/test/Ocelot.UnitTests/ServiceDiscovery/ServiceRegistryTests.cs +++ b/test/Ocelot.UnitTests/ServiceDiscovery/ServiceRegistryTests.cs @@ -131,8 +131,7 @@ namespace Ocelot.UnitTests.ServiceDiscovery else { _registeredServices[serviceNameAndAddress.Name] = new List(){ serviceNameAndAddress }; - } - + } } } } diff --git a/test/Ocelot.UnitTests/Wait.cs b/test/Ocelot.UnitTests/Wait.cs new file mode 100644 index 00000000..d8fd3a88 --- /dev/null +++ b/test/Ocelot.UnitTests/Wait.cs @@ -0,0 +1,10 @@ +namespace Ocelot.UnitTests +{ + public class Wait + { + public static Waiter WaitFor(int milliSeconds) + { + return new Waiter(milliSeconds); + } + } +} \ No newline at end of file diff --git a/test/Ocelot.UnitTests/Waiter.cs b/test/Ocelot.UnitTests/Waiter.cs index 8fb51ae5..8847c5b9 100644 --- a/test/Ocelot.UnitTests/Waiter.cs +++ b/test/Ocelot.UnitTests/Waiter.cs @@ -3,14 +3,6 @@ using System.Diagnostics; namespace Ocelot.UnitTests { - public class Wait - { - public static Waiter WaitFor(int milliSeconds) - { - return new Waiter(milliSeconds); - } - } - public class Waiter { private readonly int _milliSeconds; @@ -52,4 +44,4 @@ namespace Ocelot.UnitTests return passed; } } -} \ No newline at end of file +}