diff --git a/src/Ocelot/DependencyInjection/OcelotBuilder.cs b/src/Ocelot/DependencyInjection/OcelotBuilder.cs index b8ebc8a2..c5317a51 100644 --- a/src/Ocelot/DependencyInjection/OcelotBuilder.cs +++ b/src/Ocelot/DependencyInjection/OcelotBuilder.cs @@ -108,7 +108,7 @@ namespace Ocelot.DependencyInjection _services.TryAddSingleton(); _services.TryAddSingleton(); _services.TryAddSingleton(); - _services.TryAddSingleton(); + _services.TryAddSingleton(); _services.TryAddSingleton(); _services.TryAddSingleton(); _services.TryAddSingleton(); diff --git a/src/Ocelot/DownstreamRouteFinder/DownstreamRoute.cs b/src/Ocelot/DownstreamRouteFinder/DownstreamRoute.cs index d4a117c0..7a4a66ea 100644 --- a/src/Ocelot/DownstreamRouteFinder/DownstreamRoute.cs +++ b/src/Ocelot/DownstreamRouteFinder/DownstreamRoute.cs @@ -6,12 +6,12 @@ namespace Ocelot.DownstreamRouteFinder { public class DownstreamRoute { - public DownstreamRoute(List templatePlaceholderNameAndValues, ReRoute reRoute) + public DownstreamRoute(List templatePlaceholderNameAndValues, ReRoute reRoute) { TemplatePlaceholderNameAndValues = templatePlaceholderNameAndValues; ReRoute = reRoute; } - public List TemplatePlaceholderNameAndValues { get; private set; } + public List TemplatePlaceholderNameAndValues { get; private set; } public ReRoute ReRoute { get; private set; } } } \ No newline at end of file diff --git a/src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteFinder.cs b/src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteFinder.cs index 2c3077cc..b568f31b 100644 --- a/src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteFinder.cs +++ b/src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteFinder.cs @@ -13,9 +13,9 @@ namespace Ocelot.DownstreamRouteFinder.Finder public class DownstreamRouteFinder : IDownstreamRouteFinder { private readonly IUrlPathToUrlTemplateMatcher _urlMatcher; - private readonly IUrlPathPlaceholderNameAndValueFinder _urlPathPlaceholderNameAndValueFinder; + private readonly IPlaceholderNameAndValueFinder _urlPathPlaceholderNameAndValueFinder; - public DownstreamRouteFinder(IUrlPathToUrlTemplateMatcher urlMatcher, IUrlPathPlaceholderNameAndValueFinder urlPathPlaceholderNameAndValueFinder) + public DownstreamRouteFinder(IUrlPathToUrlTemplateMatcher urlMatcher, IPlaceholderNameAndValueFinder urlPathPlaceholderNameAndValueFinder) { _urlMatcher = urlMatcher; _urlPathPlaceholderNameAndValueFinder = urlPathPlaceholderNameAndValueFinder; diff --git a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/IUrlPathPlaceholderNameAndValueFinder.cs b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/IUrlPathPlaceholderNameAndValueFinder.cs index 788299cb..678b1081 100644 --- a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/IUrlPathPlaceholderNameAndValueFinder.cs +++ b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/IUrlPathPlaceholderNameAndValueFinder.cs @@ -3,8 +3,8 @@ using Ocelot.Responses; namespace Ocelot.DownstreamRouteFinder.UrlMatcher { - public interface IUrlPathPlaceholderNameAndValueFinder + public interface IPlaceholderNameAndValueFinder { - Response> Find(string upstreamUrlPath, string upstreamUrlPathTemplate); + Response> Find(string path, string pathTemplate); } } diff --git a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValue.cs b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValue.cs index cb690666..825f1bab 100644 --- a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValue.cs +++ b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValue.cs @@ -1,13 +1,13 @@ namespace Ocelot.DownstreamRouteFinder.UrlMatcher { - public class UrlPathPlaceholderNameAndValue + public class PlaceholderNameAndValue { - public UrlPathPlaceholderNameAndValue(string templateVariableName, string templateVariableValue) + public PlaceholderNameAndValue(string name, string value) { - TemplateVariableName = templateVariableName; - TemplateVariableValue = templateVariableValue; + Name = name; + Value = value; } - public string TemplateVariableName {get;private set;} - public string TemplateVariableValue {get;private set;} + public string Name {get;private set;} + public string Value {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 0715aeb1..8b1c6acf 100644 --- a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinder.cs +++ b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinder.cs @@ -3,68 +3,72 @@ using Ocelot.Responses; namespace Ocelot.DownstreamRouteFinder.UrlMatcher { - public class UrlPathPlaceholderNameAndValueFinder : IUrlPathPlaceholderNameAndValueFinder + public class UrlPathPlaceholderNameAndValueFinder : IPlaceholderNameAndValueFinder { - public Response> Find(string upstreamUrlPath, string upstreamUrlPathTemplate) + public Response> Find(string path, string pathTemplate) { - var templateKeysAndValues = new List(); + var placeHolderNameAndValues = new List(); - int counterForUrl = 0; + int counterForPath = 0; - for (int counterForTemplate = 0; counterForTemplate < upstreamUrlPathTemplate.Length; counterForTemplate++) + for (int counterForTemplate = 0; counterForTemplate < pathTemplate.Length; counterForTemplate++) { - if ((upstreamUrlPath.Length > counterForUrl) && CharactersDontMatch(upstreamUrlPathTemplate[counterForTemplate], upstreamUrlPath[counterForUrl]) && ContinueScanningUrl(counterForUrl,upstreamUrlPath.Length)) + if ((path.Length > counterForPath) && CharactersDontMatch(pathTemplate[counterForTemplate], path[counterForPath]) && ContinueScanningUrl(counterForPath,path.Length)) { - if (IsPlaceholder(upstreamUrlPathTemplate[counterForTemplate])) + if (IsPlaceholder(pathTemplate[counterForTemplate])) { - var variableName = GetPlaceholderVariableName(upstreamUrlPathTemplate, counterForTemplate); + var placeholderName = GetPlaceholderName(pathTemplate, counterForTemplate); - var variableValue = GetPlaceholderVariableValue(upstreamUrlPathTemplate, variableName, upstreamUrlPath, counterForUrl); + var placeholderValue = GetPlaceholderValue(pathTemplate, placeholderName, path, counterForPath); - var templateVariableNameAndValue = new UrlPathPlaceholderNameAndValue(variableName, variableValue); + placeHolderNameAndValues.Add(new PlaceholderNameAndValue(placeholderName, placeholderValue)); - templateKeysAndValues.Add(templateVariableNameAndValue); + counterForTemplate = GetNextCounterPosition(pathTemplate, counterForTemplate, '}'); - counterForTemplate = GetNextCounterPosition(upstreamUrlPathTemplate, counterForTemplate, '}'); - - counterForUrl = GetNextCounterPosition(upstreamUrlPath, counterForUrl, '/'); + counterForPath = GetNextCounterPosition(path, counterForPath, '/'); continue; } - return new OkResponse>(templateKeysAndValues); + return new OkResponse>(placeHolderNameAndValues); } - //hacking to handle special case of /{url} - //if this char is a forward slash and the template starts with /{ and last character of string is the next } - else if(string.IsNullOrEmpty(upstreamUrlPath) || (upstreamUrlPath.Length > counterForUrl && upstreamUrlPath[counterForUrl] == '/') && upstreamUrlPathTemplate.Length > 1 - && upstreamUrlPathTemplate.Substring(0, 2) == "/{" - && upstreamUrlPathTemplate.IndexOf('}') == upstreamUrlPathTemplate.Length - 1) + else if(IsCatchAll(path, counterForPath, pathTemplate)) { - var endOfPlaceholder = GetNextCounterPosition(upstreamUrlPathTemplate, counterForTemplate, '}'); - var variableName = GetPlaceholderVariableName(upstreamUrlPathTemplate, 1); + var endOfPlaceholder = GetNextCounterPosition(pathTemplate, counterForTemplate, '}'); - UrlPathPlaceholderNameAndValue templateVariableNameAndValue; + var placeholderName = GetPlaceholderName(pathTemplate, 1); - if(upstreamUrlPath.Length == 1 || upstreamUrlPath.Length == 0) + if(NothingAfterFirstForwardSlash(path)) { - templateVariableNameAndValue = new UrlPathPlaceholderNameAndValue(variableName, ""); + placeHolderNameAndValues.Add(new PlaceholderNameAndValue(placeholderName, "")); } else { - var variableValue = GetPlaceholderVariableValue(upstreamUrlPathTemplate, variableName, upstreamUrlPath, counterForUrl + 1); - templateVariableNameAndValue = new UrlPathPlaceholderNameAndValue(variableName, variableValue); + var placeholderValue = GetPlaceholderValue(pathTemplate, placeholderName, path, counterForPath + 1); + placeHolderNameAndValues.Add(new PlaceholderNameAndValue(placeholderName, placeholderValue)); } - templateKeysAndValues.Add(templateVariableNameAndValue); counterForTemplate = endOfPlaceholder; } - counterForUrl++; + counterForPath++; } - return new OkResponse>(templateKeysAndValues); + return new OkResponse>(placeHolderNameAndValues); } - private string GetPlaceholderVariableValue(string urlPathTemplate, string variableName, string urlPath, int counterForUrl) + private bool IsCatchAll(string path, int counterForPath, string pathTemplate) + { + return string.IsNullOrEmpty(path) || (path.Length > counterForPath && path[counterForPath] == '/') && pathTemplate.Length > 1 + && pathTemplate.Substring(0, 2) == "/{" + && pathTemplate.IndexOf('}') == pathTemplate.Length - 1; + } + + private bool NothingAfterFirstForwardSlash(string path) + { + return path.Length == 1 || path.Length == 0; + } + + private string GetPlaceholderValue(string urlPathTemplate, string variableName, string urlPath, int counterForUrl) { var positionOfNextSlash = urlPath.IndexOf('/', counterForUrl); @@ -78,7 +82,7 @@ namespace Ocelot.DownstreamRouteFinder.UrlMatcher return variableValue; } - private string GetPlaceholderVariableName(string urlPathTemplate, int counterForTemplate) + private string GetPlaceholderName(string urlPathTemplate, int counterForTemplate) { var postitionOfPlaceHolderClosingBracket = urlPathTemplate.IndexOf('}', counterForTemplate) + 1; diff --git a/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/DownstreamUrlTemplateVariableReplacer.cs b/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/DownstreamUrlTemplateVariableReplacer.cs index 3c42b4f4..1b744819 100644 --- a/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/DownstreamUrlTemplateVariableReplacer.cs +++ b/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/DownstreamUrlTemplateVariableReplacer.cs @@ -8,7 +8,7 @@ namespace Ocelot.DownstreamUrlCreator.UrlTemplateReplacer { public class DownstreamTemplatePathPlaceholderReplacer : IDownstreamPathPlaceholderReplacer { - public Response Replace(PathTemplate downstreamPathTemplate, List urlPathPlaceholderNameAndValues) + public Response Replace(PathTemplate downstreamPathTemplate, List urlPathPlaceholderNameAndValues) { var downstreamPath = new StringBuilder(); @@ -16,7 +16,7 @@ namespace Ocelot.DownstreamUrlCreator.UrlTemplateReplacer foreach (var placeholderVariableAndValue in urlPathPlaceholderNameAndValues) { - downstreamPath.Replace(placeholderVariableAndValue.TemplateVariableName, placeholderVariableAndValue.TemplateVariableValue); + downstreamPath.Replace(placeholderVariableAndValue.Name, placeholderVariableAndValue.Value); } return new OkResponse(new DownstreamPath(downstreamPath.ToString())); diff --git a/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/IDownstreamUrlPathTemplateVariableReplacer.cs b/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/IDownstreamUrlPathTemplateVariableReplacer.cs index 647af63a..46e998d4 100644 --- a/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/IDownstreamUrlPathTemplateVariableReplacer.cs +++ b/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/IDownstreamUrlPathTemplateVariableReplacer.cs @@ -7,6 +7,6 @@ namespace Ocelot.DownstreamUrlCreator.UrlTemplateReplacer { public interface IDownstreamPathPlaceholderReplacer { - Response Replace(PathTemplate downstreamPathTemplate, List urlPathPlaceholderNameAndValues); + Response Replace(PathTemplate downstreamPathTemplate, List urlPathPlaceholderNameAndValues); } } \ No newline at end of file diff --git a/test/Ocelot.UnitTests/Authentication/AuthenticationMiddlewareTests.cs b/test/Ocelot.UnitTests/Authentication/AuthenticationMiddlewareTests.cs index e6bcc500..dcb54388 100644 --- a/test/Ocelot.UnitTests/Authentication/AuthenticationMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Authentication/AuthenticationMiddlewareTests.cs @@ -29,7 +29,7 @@ { this.Given(x => x.GivenTheDownStreamRouteIs( new DownstreamRoute( - new List(), + new List(), new ReRouteBuilder().WithUpstreamHttpMethod(new List { "Get" }).Build()))) .When(x => x.WhenICallTheMiddleware()) .Then(x => x.ThenTheUserIsAuthenticated()) diff --git a/test/Ocelot.UnitTests/Authorization/AuthorisationMiddlewareTests.cs b/test/Ocelot.UnitTests/Authorization/AuthorisationMiddlewareTests.cs index ca346974..9ab81f94 100644 --- a/test/Ocelot.UnitTests/Authorization/AuthorisationMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Authorization/AuthorisationMiddlewareTests.cs @@ -32,7 +32,7 @@ [Fact] public void should_call_authorisation_service() { - this.Given(x => x.GivenTheDownStreamRouteIs(new DownstreamRoute(new List(), + this.Given(x => x.GivenTheDownStreamRouteIs(new DownstreamRoute(new List(), new ReRouteBuilder() .WithIsAuthorised(true) .WithUpstreamHttpMethod(new List { "Get" }) diff --git a/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareTests.cs b/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareTests.cs index 9b78b3cc..1499e19d 100644 --- a/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareTests.cs @@ -94,7 +94,7 @@ .WithUpstreamHttpMethod(new List { "Get" }) .Build(); - var downstreamRoute = new DownstreamRoute(new List(), reRoute); + var downstreamRoute = new DownstreamRoute(new List(), reRoute); ScopedRepository .Setup(x => x.Get(It.IsAny())) diff --git a/test/Ocelot.UnitTests/Claims/ClaimsBuilderMiddlewareTests.cs b/test/Ocelot.UnitTests/Claims/ClaimsBuilderMiddlewareTests.cs index 3eb86d1e..2470a6fb 100644 --- a/test/Ocelot.UnitTests/Claims/ClaimsBuilderMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Claims/ClaimsBuilderMiddlewareTests.cs @@ -31,7 +31,7 @@ [Fact] public void should_call_claims_to_request_correctly() { - var downstreamRoute = new DownstreamRoute(new List(), + var downstreamRoute = new DownstreamRoute(new List(), new ReRouteBuilder() .WithDownstreamPathTemplate("any old string") .WithClaimsToClaims(new List diff --git a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderMiddlewareTests.cs b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderMiddlewareTests.cs index 9b241fbe..5781996b 100644 --- a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderMiddlewareTests.cs @@ -38,7 +38,7 @@ this.Given(x => x.GivenTheDownStreamRouteFinderReturns( new DownstreamRoute( - new List(), + new List(), new ReRouteBuilder() .WithDownstreamPathTemplate("any old string") .WithUpstreamHttpMethod(new List { "Get" }) diff --git a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs index a1839bea..3b935bb4 100644 --- a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs +++ b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs @@ -17,7 +17,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder { private readonly IDownstreamRouteFinder _downstreamRouteFinder; private readonly Mock _mockMatcher; - private readonly Mock _finder; + private readonly Mock _finder; private string _upstreamUrlPath; private Response _result; private List _reRoutesConfig; @@ -28,7 +28,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder public DownstreamRouteFinderTests() { _mockMatcher = new Mock(); - _finder = new Mock(); + _finder = new Mock(); _downstreamRouteFinder = new Ocelot.DownstreamRouteFinder.Finder.DownstreamRouteFinder(_mockMatcher.Object, _finder.Object); } @@ -39,8 +39,8 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder this.Given(x => x.GivenThereIsAnUpstreamUrlPath("matchInUrlMatcher/")) .And(x =>x.GivenTheTemplateVariableAndNameFinderReturns( - new OkResponse>( - new List()))) + new OkResponse>( + new List()))) .And(x => x.GivenTheConfigurationIs(new List { new ReRouteBuilder() @@ -56,7 +56,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder .When(x => x.WhenICallTheFinder()) .Then( x => x.ThenTheFollowingIsReturned(new DownstreamRoute( - new List(), + new List(), new ReRouteBuilder() .WithDownstreamPathTemplate("someDownstreamPath") .WithUpstreamHttpMethod(new List { "Get" }) @@ -74,8 +74,8 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder this.Given(x => x.GivenThereIsAnUpstreamUrlPath("matchInUrlMatcher")) .And(x =>x.GivenTheTemplateVariableAndNameFinderReturns( - new OkResponse>( - new List()))) + new OkResponse>( + new List()))) .And(x => x.GivenTheConfigurationIs(new List { new ReRouteBuilder() @@ -91,7 +91,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder .When(x => x.WhenICallTheFinder()) .Then( x => x.ThenTheFollowingIsReturned(new DownstreamRoute( - new List(), + new List(), new ReRouteBuilder() .WithDownstreamPathTemplate("someDownstreamPath") .WithUpstreamHttpMethod(new List { "Get" }) @@ -110,7 +110,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder .And( x => x.GivenTheTemplateVariableAndNameFinderReturns( - new OkResponse>(new List()))) + new OkResponse>(new List()))) .And(x => x.GivenTheConfigurationIs(new List { new ReRouteBuilder() @@ -125,7 +125,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder .And(x => x.GivenTheUpstreamHttpMethodIs("Get")) .When(x => x.WhenICallTheFinder()) .Then( - x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List(), + x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List(), new ReRouteBuilder() .WithDownstreamPathTemplate("someDownstreamPath") .WithUpstreamHttpMethod(new List { "Get" }) @@ -144,7 +144,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder .And( x => x.GivenTheTemplateVariableAndNameFinderReturns( - new OkResponse>(new List()))) + new OkResponse>(new List()))) .And(x => x.GivenTheConfigurationIs(new List { new ReRouteBuilder() @@ -165,7 +165,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder .And(x => x.GivenTheUpstreamHttpMethodIs("Post")) .When(x => x.WhenICallTheFinder()) .Then( - x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List(), + x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List(), new ReRouteBuilder() .WithDownstreamPathTemplate("someDownstreamPathForAPost") .WithUpstreamHttpMethod(new List { "Post" }) @@ -208,7 +208,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder .And( x => x.GivenTheTemplateVariableAndNameFinderReturns( - new OkResponse>(new List()))) + new OkResponse>(new List()))) .And(x => x.GivenTheConfigurationIs(new List { new ReRouteBuilder() @@ -223,7 +223,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder .And(x => x.GivenTheUpstreamHttpMethodIs("Post")) .When(x => x.WhenICallTheFinder()) .Then( - x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List(), + x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List(), new ReRouteBuilder() .WithDownstreamPathTemplate("someDownstreamPath") .WithUpstreamHttpMethod(new List { "Post" }) @@ -241,7 +241,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder .And( x => x.GivenTheTemplateVariableAndNameFinderReturns( - new OkResponse>(new List()))) + new OkResponse>(new List()))) .And(x => x.GivenTheConfigurationIs(new List { new ReRouteBuilder() @@ -256,7 +256,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder .And(x => x.GivenTheUpstreamHttpMethodIs("Post")) .When(x => x.WhenICallTheFinder()) .Then( - x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List(), + x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List(), new ReRouteBuilder() .WithDownstreamPathTemplate("someDownstreamPath") .WithUpstreamHttpMethod(new List { "Post" }) @@ -274,7 +274,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder .And( x => x.GivenTheTemplateVariableAndNameFinderReturns( - new OkResponse>(new List()))) + new OkResponse>(new List()))) .And(x => x.GivenTheConfigurationIs(new List { new ReRouteBuilder() @@ -294,7 +294,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder .BDDfy(); } - private void GivenTheTemplateVariableAndNameFinderReturns(Response> response) + private void GivenTheTemplateVariableAndNameFinderReturns(Response> response) { _finder .Setup(x => x.Find(It.IsAny(), It.IsAny())) @@ -359,11 +359,11 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder for (int i = 0; i < _result.Data.TemplatePlaceholderNameAndValues.Count; i++) { - _result.Data.TemplatePlaceholderNameAndValues[i].TemplateVariableName.ShouldBe( - expected.TemplatePlaceholderNameAndValues[i].TemplateVariableName); + _result.Data.TemplatePlaceholderNameAndValues[i].Name.ShouldBe( + expected.TemplatePlaceholderNameAndValues[i].Name); - _result.Data.TemplatePlaceholderNameAndValues[i].TemplateVariableValue.ShouldBe( - expected.TemplatePlaceholderNameAndValues[i].TemplateVariableValue); + _result.Data.TemplatePlaceholderNameAndValues[i].Value.ShouldBe( + expected.TemplatePlaceholderNameAndValues[i].Value); } _result.IsError.ShouldBeFalse(); diff --git a/test/Ocelot.UnitTests/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinderTests.cs b/test/Ocelot.UnitTests/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinderTests.cs index ec955038..9fa9366b 100644 --- a/test/Ocelot.UnitTests/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinderTests.cs +++ b/test/Ocelot.UnitTests/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinderTests.cs @@ -10,10 +10,10 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher { public class UrlPathPlaceholderNameAndValueFinderTests { - private readonly IUrlPathPlaceholderNameAndValueFinder _finder; + private readonly IPlaceholderNameAndValueFinder _finder; private string _downstreamUrlPath; private string _downstreamPathTemplate; - private Response> _result; + private Response> _result; public UrlPathPlaceholderNameAndValueFinderTests() { @@ -26,7 +26,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher this.Given(x => x.GivenIHaveAUpstreamPath("")) .And(x => x.GivenIHaveAnUpstreamUrlTemplate("")) .When(x => x.WhenIFindTheUrlVariableNamesAndValues()) - .And(x => x.ThenTheTemplatesVariablesAre(new List())) + .And(x => x.ThenTheTemplatesVariablesAre(new List())) .BDDfy(); } @@ -34,9 +34,9 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher [Fact] public void can_match_down_stream_url_with_nothing_then_placeholder_no_value_is_blank() { - var expectedTemplates = new List + var expectedTemplates = new List { - new UrlPathPlaceholderNameAndValue("{url}", "") + new PlaceholderNameAndValue("{url}", "") }; this.Given(x => x.GivenIHaveAUpstreamPath("")) @@ -49,9 +49,9 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher [Fact] public void can_match_down_stream_url_with_nothing_then_placeholder_value_is_test() { - var expectedTemplates = new List + var expectedTemplates = new List { - new UrlPathPlaceholderNameAndValue("{url}", "test") + new PlaceholderNameAndValue("{url}", "test") }; this.Given(x => x.GivenIHaveAUpstreamPath("/test")) @@ -64,9 +64,9 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher [Fact] public void can_match_down_stream_url_with_forward_slash_then_placeholder_no_value_is_blank() { - var expectedTemplates = new List + var expectedTemplates = new List { - new UrlPathPlaceholderNameAndValue("{url}", "") + new PlaceholderNameAndValue("{url}", "") }; this.Given(x => x.GivenIHaveAUpstreamPath("/")) @@ -79,7 +79,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher [Fact] public void can_match_down_stream_url_with_forward_slash() { - var expectedTemplates = new List + var expectedTemplates = new List { }; @@ -93,9 +93,9 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher [Fact] public void can_match_down_stream_url_with_forward_slash_then_placeholder_then_another_value() { - var expectedTemplates = new List + var expectedTemplates = new List { - new UrlPathPlaceholderNameAndValue("{url}", "1") + new PlaceholderNameAndValue("{url}", "1") }; this.Given(x => x.GivenIHaveAUpstreamPath("/1/products")) @@ -111,7 +111,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher this.Given(x => x.GivenIHaveAUpstreamPath("/products")) .And(x => x.GivenIHaveAnUpstreamUrlTemplate("/products/")) .When(x => x.WhenIFindTheUrlVariableNamesAndValues()) - .And(x => x.ThenTheTemplatesVariablesAre(new List())) + .And(x => x.ThenTheTemplatesVariablesAre(new List())) .BDDfy(); } @@ -121,7 +121,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher this.Given(x => x.GivenIHaveAUpstreamPath("api")) .Given(x => x.GivenIHaveAnUpstreamUrlTemplate("api")) .When(x => x.WhenIFindTheUrlVariableNamesAndValues()) - .And(x => x.ThenTheTemplatesVariablesAre(new List())) + .And(x => x.ThenTheTemplatesVariablesAre(new List())) .BDDfy(); } @@ -131,7 +131,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher this.Given(x => x.GivenIHaveAUpstreamPath("api/")) .Given(x => x.GivenIHaveAnUpstreamUrlTemplate("api/")) .When(x => x.WhenIFindTheUrlVariableNamesAndValues()) - .And(x => x.ThenTheTemplatesVariablesAre(new List())) + .And(x => x.ThenTheTemplatesVariablesAre(new List())) .BDDfy(); } @@ -141,16 +141,16 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher this.Given(x => x.GivenIHaveAUpstreamPath("api/product/products/")) .Given(x => x.GivenIHaveAnUpstreamUrlTemplate("api/product/products/")) .When(x => x.WhenIFindTheUrlVariableNamesAndValues()) - .And(x => x.ThenTheTemplatesVariablesAre(new List())) + .And(x => x.ThenTheTemplatesVariablesAre(new List())) .BDDfy(); } [Fact] public void can_match_down_stream_url_with_downstream_template_with_one_place_holder() { - var expectedTemplates = new List + var expectedTemplates = new List { - new UrlPathPlaceholderNameAndValue("{productId}", "1") + new PlaceholderNameAndValue("{productId}", "1") }; this.Given(x => x.GivenIHaveAUpstreamPath("api/product/products/1")) @@ -163,10 +163,10 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher [Fact] public void can_match_down_stream_url_with_downstream_template_with_two_place_holders() { - var expectedTemplates = new List + var expectedTemplates = new List { - new UrlPathPlaceholderNameAndValue("{productId}", "1"), - new UrlPathPlaceholderNameAndValue("{categoryId}", "2") + new PlaceholderNameAndValue("{productId}", "1"), + new PlaceholderNameAndValue("{categoryId}", "2") }; this.Given(x => x.GivenIHaveAUpstreamPath("api/product/products/1/2")) @@ -179,10 +179,10 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher [Fact] public void can_match_down_stream_url_with_downstream_template_with_two_place_holders_seperated_by_something() { - var expectedTemplates = new List + var expectedTemplates = new List { - new UrlPathPlaceholderNameAndValue("{productId}", "1"), - new UrlPathPlaceholderNameAndValue("{categoryId}", "2") + new PlaceholderNameAndValue("{productId}", "1"), + new PlaceholderNameAndValue("{categoryId}", "2") }; this.Given(x => x.GivenIHaveAUpstreamPath("api/product/products/1/categories/2")) @@ -195,11 +195,11 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher [Fact] public void can_match_down_stream_url_with_downstream_template_with_three_place_holders_seperated_by_something() { - var expectedTemplates = new List + var expectedTemplates = new List { - new UrlPathPlaceholderNameAndValue("{productId}", "1"), - new UrlPathPlaceholderNameAndValue("{categoryId}", "2"), - new UrlPathPlaceholderNameAndValue("{variantId}", "123") + new PlaceholderNameAndValue("{productId}", "1"), + new PlaceholderNameAndValue("{categoryId}", "2"), + new PlaceholderNameAndValue("{variantId}", "123") }; this.Given(x => x.GivenIHaveAUpstreamPath("api/product/products/1/categories/2/variant/123")) @@ -212,10 +212,10 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher [Fact] public void can_match_down_stream_url_with_downstream_template_with_three_place_holders() { - var expectedTemplates = new List + var expectedTemplates = new List { - new UrlPathPlaceholderNameAndValue("{productId}", "1"), - new UrlPathPlaceholderNameAndValue("{categoryId}", "2") + new PlaceholderNameAndValue("{productId}", "1"), + new PlaceholderNameAndValue("{categoryId}", "2") }; this.Given(x => x.GivenIHaveAUpstreamPath("api/product/products/1/categories/2/variant/")) @@ -228,9 +228,9 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher [Fact] public void can_match_down_stream_url_with_downstream_template_with_place_holder_to_final_url_path() { - var expectedTemplates = new List + var expectedTemplates = new List { - new UrlPathPlaceholderNameAndValue("{finalUrlPath}", "product/products/categories/"), + new PlaceholderNameAndValue("{finalUrlPath}", "product/products/categories/"), }; this.Given(x => x.GivenIHaveAUpstreamPath("api/product/products/categories/")) @@ -240,12 +240,12 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher .BDDfy(); } - private void ThenTheTemplatesVariablesAre(List expectedResults) + private void ThenTheTemplatesVariablesAre(List expectedResults) { foreach (var expectedResult in expectedResults) { - var result = _result.Data.First(t => t.TemplateVariableName == expectedResult.TemplateVariableName); - result.TemplateVariableValue.ShouldBe(expectedResult.TemplateVariableValue); + var result = _result.Data.First(t => t.Name == expectedResult.Name); + result.Value.ShouldBe(expectedResult.Value); } } diff --git a/test/Ocelot.UnitTests/DownstreamUrlCreator/DownstreamUrlCreatorMiddlewareTests.cs b/test/Ocelot.UnitTests/DownstreamUrlCreator/DownstreamUrlCreatorMiddlewareTests.cs index 1af70f71..04afdf3a 100644 --- a/test/Ocelot.UnitTests/DownstreamUrlCreator/DownstreamUrlCreatorMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/DownstreamUrlCreator/DownstreamUrlCreatorMiddlewareTests.cs @@ -47,7 +47,7 @@ { this.Given(x => x.GivenTheDownStreamRouteIs( new DownstreamRoute( - new List(), + new List(), new ReRouteBuilder() .WithDownstreamPathTemplate("any old string") .WithUpstreamHttpMethod(new List { "Get" }) @@ -91,7 +91,7 @@ { _downstreamPath = new OkResponse(new DownstreamPath(path)); _downstreamUrlTemplateVariableReplacer - .Setup(x => x.Replace(It.IsAny(), It.IsAny>())) + .Setup(x => x.Replace(It.IsAny(), It.IsAny>())) .Returns(_downstreamPath); } diff --git a/test/Ocelot.UnitTests/DownstreamUrlCreator/UrlTemplateReplacer/UpstreamUrlPathTemplateVariableReplacerTests.cs b/test/Ocelot.UnitTests/DownstreamUrlCreator/UrlTemplateReplacer/UpstreamUrlPathTemplateVariableReplacerTests.cs index 4939c901..7aa8fc16 100644 --- a/test/Ocelot.UnitTests/DownstreamUrlCreator/UrlTemplateReplacer/UpstreamUrlPathTemplateVariableReplacerTests.cs +++ b/test/Ocelot.UnitTests/DownstreamUrlCreator/UrlTemplateReplacer/UpstreamUrlPathTemplateVariableReplacerTests.cs @@ -27,7 +27,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer { this.Given(x => x.GivenThereIsAUrlMatch( new DownstreamRoute( - new List(), + new List(), new ReRouteBuilder() .WithUpstreamHttpMethod(new List { "Get" }) .Build()))) @@ -41,7 +41,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer { this.Given(x => x.GivenThereIsAUrlMatch( new DownstreamRoute( - new List(), + new List(), new ReRouteBuilder() .WithDownstreamPathTemplate("/") .WithUpstreamHttpMethod(new List { "Get" }) @@ -54,7 +54,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer [Fact] public void can_replace_url_no_slash() { - this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(new List(), + this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(new List(), new ReRouteBuilder() .WithDownstreamPathTemplate("api") .WithUpstreamHttpMethod(new List { "Get" }) @@ -67,7 +67,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer [Fact] public void can_replace_url_one_slash() { - this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(new List(), + this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(new List(), new ReRouteBuilder() .WithDownstreamPathTemplate("api/") .WithUpstreamHttpMethod(new List { "Get" }) @@ -80,7 +80,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer [Fact] public void can_replace_url_multiple_slash() { - this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(new List(), + this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(new List(), new ReRouteBuilder() .WithDownstreamPathTemplate("api/product/products/") .WithUpstreamHttpMethod(new List { "Get" }) @@ -93,9 +93,9 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer [Fact] public void can_replace_url_one_template_variable() { - var templateVariables = new List() + var templateVariables = new List() { - new UrlPathPlaceholderNameAndValue("{productId}", "1") + new PlaceholderNameAndValue("{productId}", "1") }; this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(templateVariables, @@ -111,9 +111,9 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer [Fact] public void can_replace_url_one_template_variable_with_path_after() { - var templateVariables = new List() + var templateVariables = new List() { - new UrlPathPlaceholderNameAndValue("{productId}", "1") + new PlaceholderNameAndValue("{productId}", "1") }; this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(templateVariables, @@ -129,10 +129,10 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer [Fact] public void can_replace_url_two_template_variable() { - var templateVariables = new List() + var templateVariables = new List() { - new UrlPathPlaceholderNameAndValue("{productId}", "1"), - new UrlPathPlaceholderNameAndValue("{variantId}", "12") + new PlaceholderNameAndValue("{productId}", "1"), + new PlaceholderNameAndValue("{variantId}", "12") }; this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(templateVariables, @@ -148,11 +148,11 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer [Fact] public void can_replace_url_three_template_variable() { - var templateVariables = new List() + var templateVariables = new List() { - new UrlPathPlaceholderNameAndValue("{productId}", "1"), - new UrlPathPlaceholderNameAndValue("{variantId}", "12"), - new UrlPathPlaceholderNameAndValue("{categoryId}", "34") + new PlaceholderNameAndValue("{productId}", "1"), + new PlaceholderNameAndValue("{variantId}", "12"), + new PlaceholderNameAndValue("{categoryId}", "34") }; this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(templateVariables, diff --git a/test/Ocelot.UnitTests/Headers/HttpRequestHeadersBuilderMiddlewareTests.cs b/test/Ocelot.UnitTests/Headers/HttpRequestHeadersBuilderMiddlewareTests.cs index 76a75d0a..20dbe84d 100644 --- a/test/Ocelot.UnitTests/Headers/HttpRequestHeadersBuilderMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Headers/HttpRequestHeadersBuilderMiddlewareTests.cs @@ -37,7 +37,7 @@ [Fact] public void should_call_add_headers_to_request_correctly() { - var downstreamRoute = new DownstreamRoute(new List(), + var downstreamRoute = new DownstreamRoute(new List(), new ReRouteBuilder() .WithDownstreamPathTemplate("any old string") .WithClaimsToHeaders(new List diff --git a/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerMiddlewareTests.cs b/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerMiddlewareTests.cs index 002e64a0..936e9249 100644 --- a/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerMiddlewareTests.cs @@ -47,7 +47,7 @@ namespace Ocelot.UnitTests.LoadBalancer [Fact] public void should_call_scoped_data_repository_correctly() { - var downstreamRoute = new DownstreamRoute(new List(), + var downstreamRoute = new DownstreamRoute(new List(), new ReRouteBuilder() .WithUpstreamHttpMethod(new List { "Get" }) .Build()); @@ -68,7 +68,7 @@ namespace Ocelot.UnitTests.LoadBalancer [Fact] public void should_set_pipeline_error_if_cannot_get_load_balancer() { - var downstreamRoute = new DownstreamRoute(new List(), + var downstreamRoute = new DownstreamRoute(new List(), new ReRouteBuilder() .WithUpstreamHttpMethod(new List { "Get" }) .Build()); @@ -88,7 +88,7 @@ namespace Ocelot.UnitTests.LoadBalancer [Fact] public void should_set_pipeline_error_if_cannot_get_least() { - var downstreamRoute = new DownstreamRoute(new List(), + var downstreamRoute = new DownstreamRoute(new List(), new ReRouteBuilder() .WithUpstreamHttpMethod(new List { "Get" }) .Build()); diff --git a/test/Ocelot.UnitTests/QueryStrings/QueryStringBuilderMiddlewareTests.cs b/test/Ocelot.UnitTests/QueryStrings/QueryStringBuilderMiddlewareTests.cs index 4bbcfd2c..a4a3b197 100644 --- a/test/Ocelot.UnitTests/QueryStrings/QueryStringBuilderMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/QueryStrings/QueryStringBuilderMiddlewareTests.cs @@ -37,7 +37,7 @@ [Fact] public void should_call_add_queries_correctly() { - var downstreamRoute = new DownstreamRoute(new List(), + var downstreamRoute = new DownstreamRoute(new List(), new ReRouteBuilder() .WithDownstreamPathTemplate("any old string") .WithClaimsToQueries(new List diff --git a/test/Ocelot.UnitTests/RateLimit/ClientRateLimitMiddlewareTests.cs b/test/Ocelot.UnitTests/RateLimit/ClientRateLimitMiddlewareTests.cs index 1b73e233..e832760b 100644 --- a/test/Ocelot.UnitTests/RateLimit/ClientRateLimitMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/RateLimit/ClientRateLimitMiddlewareTests.cs @@ -31,7 +31,7 @@ [Fact] public void should_call_middleware_and_ratelimiting() { - var downstreamRoute = new DownstreamRoute(new List(), + var downstreamRoute = new DownstreamRoute(new List(), new ReRouteBuilder().WithEnableRateLimiting(true).WithRateLimitOptions( new Ocelot.Configuration.RateLimitOptions(true, "ClientId", new List(), false, "", "", new Ocelot.Configuration.RateLimitRule("1s", 100, 3), 429)) .WithUpstreamHttpMethod(new List { "Get" }) @@ -48,7 +48,7 @@ [Fact] public void should_call_middleware_withWhitelistClient() { - var downstreamRoute = new DownstreamRoute(new List(), + var downstreamRoute = new DownstreamRoute(new List(), new ReRouteBuilder().WithEnableRateLimiting(true).WithRateLimitOptions( new Ocelot.Configuration.RateLimitOptions(true, "ClientId", new List() { "ocelotclient2" }, false, "", "", new RateLimitRule( "1s", 100,3),429)) .WithUpstreamHttpMethod(new List { "Get" }) diff --git a/test/Ocelot.UnitTests/Request/HttpRequestBuilderMiddlewareTests.cs b/test/Ocelot.UnitTests/Request/HttpRequestBuilderMiddlewareTests.cs index 4c72d137..10cbc120 100644 --- a/test/Ocelot.UnitTests/Request/HttpRequestBuilderMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Request/HttpRequestBuilderMiddlewareTests.cs @@ -47,7 +47,7 @@ public void should_call_scoped_data_repository_correctly() { - var downstreamRoute = new DownstreamRoute(new List(), + var downstreamRoute = new DownstreamRoute(new List(), new ReRouteBuilder() .WithRequestIdKey("LSRequestId") .WithUpstreamHttpMethod(new List { "Get" }) diff --git a/test/Ocelot.UnitTests/RequestId/RequestIdMiddlewareTests.cs b/test/Ocelot.UnitTests/RequestId/RequestIdMiddlewareTests.cs index a34290f1..4d684084 100644 --- a/test/Ocelot.UnitTests/RequestId/RequestIdMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/RequestId/RequestIdMiddlewareTests.cs @@ -40,7 +40,7 @@ [Fact] public void should_pass_down_request_id_from_upstream_request() { - var downstreamRoute = new DownstreamRoute(new List(), + var downstreamRoute = new DownstreamRoute(new List(), new ReRouteBuilder() .WithDownstreamPathTemplate("any old string") .WithRequestIdKey("LSRequestId") @@ -59,7 +59,7 @@ [Fact] public void should_add_request_id_when_not_on_upstream_request() { - var downstreamRoute = new DownstreamRoute(new List(), + var downstreamRoute = new DownstreamRoute(new List(), new ReRouteBuilder() .WithDownstreamPathTemplate("any old string") .WithRequestIdKey("LSRequestId")