mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-10-31 22:45:28 +08:00 
			
		
		
		
	merge and script updates
This commit is contained in:
		
							
								
								
									
										4
									
								
								build.sh
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								build.sh
									
									
									
									
									
								
							| @@ -3,14 +3,18 @@ echo ------------------------- | ||||
|  | ||||
| echo Running Ocelot.UnitTests | ||||
|  | ||||
| dotnet restore test/Ocelot.UnitTests/ | ||||
| dotnet test test/Ocelot.UnitTests/ | ||||
|  | ||||
| echo Running Ocelot.AcceptanceTests | ||||
|  | ||||
| dotnet restore test/Ocelot.AcceptanceTests/ | ||||
| dotnet test test/Ocelot.AcceptanceTests/ | ||||
|  | ||||
| echo Building Ocelot | ||||
|  | ||||
| dotnet restore src/Ocelot | ||||
| dotnet build src/Ocelot | ||||
| dotnet publish src/Ocelot | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -5,6 +5,8 @@ echo Running Ocelot.Benchmarks | ||||
|  | ||||
| cd test/Ocelot.Benchmarks | ||||
|  | ||||
| dotnet restore  | ||||
|  | ||||
| dotnet run  | ||||
|  | ||||
| cd ../../ | ||||
|   | ||||
| @@ -3,10 +3,12 @@ echo ------------------------- | ||||
|  | ||||
| echo Running Ocelot.UnitTests | ||||
|  | ||||
| dotnet restore test/Ocelot.UnitTests/ | ||||
| dotnet test test/Ocelot.UnitTests/ | ||||
|  | ||||
| echo Running Ocelot.AcceptanceTests | ||||
|  | ||||
| dotnet restore test/Ocelot.AcceptanceTests/ | ||||
| dotnet test test/Ocelot.AcceptanceTests/ | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -9,6 +9,7 @@ using Shouldly; | ||||
| namespace Ocelot.AcceptanceTests | ||||
| { | ||||
|     using System.Net; | ||||
|     using TestStack.BDDfy; | ||||
|  | ||||
|     public class RouterTests : IDisposable | ||||
|     { | ||||
| @@ -30,8 +31,9 @@ namespace Ocelot.AcceptanceTests | ||||
|         [Fact] | ||||
|         public void should_return_response_404() | ||||
|         { | ||||
|             WhenIRequestTheUrl("/"); | ||||
|             ThenTheStatusCodeShouldBe(HttpStatusCode.NotFound); | ||||
|             this.When(x => x.WhenIRequestTheUrl("/")) | ||||
|                 .Then(x => x.ThenTheStatusCodeShouldBe(HttpStatusCode.NotFound)) | ||||
|                 .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         private void WhenIRequestTheUrl(string url) | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| { | ||||
| { | ||||
|     "version": "1.0.0-*", | ||||
|  | ||||
|     "testRunner": "xunit", | ||||
| @@ -24,7 +24,8 @@ | ||||
|         "dotnet-test-xunit": "2.2.0-preview2-build1029", | ||||
|         "Shouldly": "2.8.0", | ||||
|         "Ocelot": "1.0.0-*", | ||||
|         "Microsoft.AspNetCore.TestHost": "1.0.0" | ||||
|       "Microsoft.AspNetCore.TestHost": "1.0.0", | ||||
|       "TestStack.BDDfy": "4.3.1" | ||||
|     }, | ||||
|  | ||||
|     "frameworks": { | ||||
|   | ||||
| @@ -5,11 +5,13 @@ using Xunit; | ||||
|  | ||||
| namespace Ocelot.UnitTests | ||||
| { | ||||
|     using TestStack.BDDfy; | ||||
|  | ||||
|     public class HostUrlMapRepositoryTests | ||||
|     { | ||||
|         private string _upstreamBaseUrl; | ||||
|         private string _downstreamBaseUrl; | ||||
|         private IHostUrlMapRepository _repository; | ||||
|         private readonly IHostUrlMapRepository _repository; | ||||
|         private Response _response; | ||||
|         private Response<HostUrlMap> _getRouteResponse; | ||||
|   | ||||
| @@ -21,34 +23,38 @@ namespace Ocelot.UnitTests | ||||
|         [Fact] | ||||
|         public void can_add_route() | ||||
|         { | ||||
|             GivenIHaveAnUpstreamBaseUrl("www.someapi.com"); | ||||
|             GivenIWantToRouteRequestsFromMyDownstreamBaseUrl("api"); | ||||
|             WhenIAddTheConfiguration(); | ||||
|             ThenTheResponseIsSuccesful(); | ||||
|             this.Given(x => x.GivenIHaveAnUpstreamBaseUrl("www.someapi.com")) | ||||
|                 .And(x => x.GivenIWantToRouteRequestsFromMyDownstreamBaseUrl("api")) | ||||
|                 .When(x => x.WhenIAddTheConfiguration()) | ||||
|                 .Then(x => x.ThenTheResponseIsSuccesful()) | ||||
|                 .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
|         public void can_get_route_by_key() | ||||
|         { | ||||
|             GivenIHaveSetUpAnApiKeyAndUpstreamUrl("api2", "www.someapi.com"); | ||||
|             WhenIRetrieveTheRouteByKey(); | ||||
|             ThenTheRouteIsReturned(); | ||||
|             this.Given(x => x.GivenIHaveSetUpAnApiKeyAndUpstreamUrl("api2", "www.someapi.com")) | ||||
|                 .When(x => x.WhenIRetrieveTheRouteByKey()) | ||||
|                 .Then(x => x.ThenTheRouteIsReturned()) | ||||
|                 .BDDfy(); | ||||
|         } | ||||
|   | ||||
|         [Fact] | ||||
|         public void should_return_error_response_when_key_already_used() | ||||
|         { | ||||
|             GivenIHaveSetUpAnApiKeyAndUpstreamUrl("api2", "www.someapi.com"); | ||||
|             WhenITryToUseTheSameKey(); | ||||
|             ThenTheKeyHasAlreadyBeenUsed(); | ||||
|             this.Given(x => x.GivenIHaveSetUpAnApiKeyAndUpstreamUrl("api2", "www.someapi.com")) | ||||
|                 .When(x => x.WhenITryToUseTheSameKey()) | ||||
|                 .Then(x => x.ThenTheKeyHasAlreadyBeenUsed()) | ||||
|                 .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
|         public void should_return_error_response_if_key_doesnt_exist() | ||||
|         { | ||||
|             GivenIWantToRouteRequestsFromMyDownstreamBaseUrl("api"); | ||||
|             WhenIRetrieveTheRouteByKey(); | ||||
|             ThenTheKeyDoesNotExist(); | ||||
|             this.Given(x => x.GivenIWantToRouteRequestsFromMyDownstreamBaseUrl("api")) | ||||
|                 .When(x => x.WhenIRetrieveTheRouteByKey()) | ||||
|                 .Then(x => x.ThenTheKeyDoesNotExist()) | ||||
|                 .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         private void WhenITryToUseTheSameKey() | ||||
|   | ||||
| @@ -3,14 +3,14 @@ using Ocelot.Library.Infrastructure.UrlFinder; | ||||
| using Ocelot.Library.Infrastructure.Responses; | ||||
| using Xunit; | ||||
| using Shouldly; | ||||
| using System; | ||||
| using TestStack.BDDfy; | ||||
|  | ||||
| namespace Ocelot.UnitTests | ||||
| { | ||||
|     public class UpstreamBaseUrlFinderTests | ||||
|     { | ||||
|         private IUpstreamHostUrlFinder _upstreamBaseUrlFinder; | ||||
|         private IHostUrlMapRepository _hostUrlMapRepository; | ||||
|         private readonly IUpstreamHostUrlFinder _upstreamBaseUrlFinder; | ||||
|         private readonly IHostUrlMapRepository _hostUrlMapRepository; | ||||
|         private string _downstreamBaseUrl; | ||||
|         private Response<string> _result; | ||||
|         public UpstreamBaseUrlFinderTests() | ||||
| @@ -22,18 +22,20 @@ namespace Ocelot.UnitTests | ||||
|         [Fact] | ||||
|         public void can_find_base_url() | ||||
|         { | ||||
|             GivenTheBaseUrlMapExists(new HostUrlMap("api.tom.com", "api.laura.com")); | ||||
|             GivenTheDownstreamBaseUrlIs("api.tom.com"); | ||||
|             WhenIFindTheMatchingUpstreamBaseUrl(); | ||||
|             ThenTheFollowingIsReturned("api.laura.com"); | ||||
|             this.Given(x => x.GivenTheBaseUrlMapExists(new HostUrlMap("api.tom.com", "api.laura.com"))) | ||||
|                 .And(x => x.GivenTheDownstreamBaseUrlIs("api.tom.com")) | ||||
|                 .When(x => x.WhenIFindTheMatchingUpstreamBaseUrl()) | ||||
|                 .Then(x => x.ThenTheFollowingIsReturned("api.laura.com")) | ||||
|                 .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
|         public void cant_find_base_url() | ||||
|         { | ||||
|             GivenTheDownstreamBaseUrlIs("api.tom.com"); | ||||
|             WhenIFindTheMatchingUpstreamBaseUrl(); | ||||
|             ThenAnErrorIsReturned(); | ||||
|             this.Given(x => x.GivenTheDownstreamBaseUrlIs("api.tom.com")) | ||||
|                 .When(x => x.WhenIFindTheMatchingUpstreamBaseUrl()) | ||||
|                 .Then(x => x.ThenAnErrorIsReturned()) | ||||
|                 .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         private void ThenAnErrorIsReturned() | ||||
|   | ||||
| @@ -6,52 +6,58 @@ using Xunit; | ||||
|  | ||||
| namespace Ocelot.UnitTests | ||||
| { | ||||
|     using TestStack.BDDfy; | ||||
|  | ||||
|     public class UpstreamUrlPathTemplateVariableReplacerTests | ||||
|     { | ||||
|  | ||||
|         private string _upstreamUrlPath; | ||||
|         private UrlPathMatch _urlPathMatch; | ||||
|         private string _result; | ||||
|         private IUpstreamUrlPathTemplateVariableReplacer _upstreamUrlPathReplacer; | ||||
|         private readonly IUpstreamUrlPathTemplateVariableReplacer _upstreamUrlPathReplacer; | ||||
|  | ||||
|         public UpstreamUrlPathTemplateVariableReplacerTests() | ||||
|         { | ||||
|             _upstreamUrlPathReplacer = new UpstreamUrlPathTemplateVariableReplacer(); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
|         public void can_replace_no_template_variables() | ||||
|         { | ||||
|             GivenThereIsAnUpstreamUrlPath(""); | ||||
|             GivenThereIsAUrlPathMatch(new UrlPathMatch(true, new List<TemplateVariableNameAndValue>(), "")); | ||||
|             WhenIReplaceTheTemplateVariables(); | ||||
|             ThenTheUpstreamUrlPathIsReturned(""); | ||||
|             this.Given(x => x.GivenThereIsAnUpstreamUrlPath("")) | ||||
|                 .And(x => x.GivenThereIsAUrlPathMatch(new UrlPathMatch(true, new List<TemplateVariableNameAndValue>(), ""))) | ||||
|                 .When(x => x.WhenIReplaceTheTemplateVariables()) | ||||
|                 .Then(x => x.ThenTheUpstreamUrlPathIsReturned("")) | ||||
|                 .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
|         public void can_replace_url_no_slash() | ||||
|         { | ||||
|             GivenThereIsAnUpstreamUrlPath("api"); | ||||
|             GivenThereIsAUrlPathMatch(new UrlPathMatch(true, new List<TemplateVariableNameAndValue>(), "api")); | ||||
|             WhenIReplaceTheTemplateVariables(); | ||||
|             ThenTheUpstreamUrlPathIsReturned("api"); | ||||
|             this.Given(x => x.GivenThereIsAnUpstreamUrlPath("api")) | ||||
|                 .And(x => x.GivenThereIsAUrlPathMatch(new UrlPathMatch(true, new List<TemplateVariableNameAndValue>(), "api"))) | ||||
|                 .When(x => x.WhenIReplaceTheTemplateVariables()) | ||||
|                 .Then(x => x.ThenTheUpstreamUrlPathIsReturned("api")) | ||||
|                 .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
|         public void can_replace_url_one_slash() | ||||
|         { | ||||
|             GivenThereIsAnUpstreamUrlPath("api/"); | ||||
|             GivenThereIsAUrlPathMatch(new UrlPathMatch(true, new List<TemplateVariableNameAndValue>(), "api/")); | ||||
|             WhenIReplaceTheTemplateVariables(); | ||||
|             ThenTheUpstreamUrlPathIsReturned("api/"); | ||||
|             this.Given(x => x.GivenThereIsAnUpstreamUrlPath("api/")) | ||||
|                 .And(x => x.GivenThereIsAUrlPathMatch(new UrlPathMatch(true, new List<TemplateVariableNameAndValue>(), "api/"))) | ||||
|                 .When(x => x.WhenIReplaceTheTemplateVariables()) | ||||
|                 .Then(x => x.ThenTheUpstreamUrlPathIsReturned("api/")) | ||||
|                 .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
|         public void can_replace_url_multiple_slash() | ||||
|         { | ||||
|             GivenThereIsAnUpstreamUrlPath("api/product/products/"); | ||||
|             GivenThereIsAUrlPathMatch(new UrlPathMatch(true, new List<TemplateVariableNameAndValue>(), "api/product/products/")); | ||||
|             WhenIReplaceTheTemplateVariables(); | ||||
|             ThenTheUpstreamUrlPathIsReturned("api/product/products/"); | ||||
|             this.Given(x => x.GivenThereIsAnUpstreamUrlPath("api/product/products/")) | ||||
|                 .And(x => x.GivenThereIsAUrlPathMatch(new UrlPathMatch(true, new List<TemplateVariableNameAndValue>(), "api/product/products/"))) | ||||
|                 .When(x => x.WhenIReplaceTheTemplateVariables()) | ||||
|                 .Then(x => x.ThenTheUpstreamUrlPathIsReturned("api/product/products/")) | ||||
|                 .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
| @@ -62,10 +68,11 @@ namespace Ocelot.UnitTests | ||||
|                 new TemplateVariableNameAndValue("{productId}", "1") | ||||
|             }; | ||||
|  | ||||
|             GivenThereIsAnUpstreamUrlPath("productservice/products/{productId}/"); | ||||
|             GivenThereIsAUrlPathMatch(new UrlPathMatch(true, templateVariables, "api/products/{productId}/")); | ||||
|             WhenIReplaceTheTemplateVariables(); | ||||
|             ThenTheUpstreamUrlPathIsReturned("productservice/products/1/"); | ||||
|             this.Given(x => x.GivenThereIsAnUpstreamUrlPath("productservice/products/{productId}/")) | ||||
|              .And(x => x.GivenThereIsAUrlPathMatch(new UrlPathMatch(true, templateVariables, "api/products/{productId}/"))) | ||||
|              .When(x => x.WhenIReplaceTheTemplateVariables()) | ||||
|              .Then(x => x.ThenTheUpstreamUrlPathIsReturned("productservice/products/1/")) | ||||
|              .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
| @@ -76,10 +83,11 @@ namespace Ocelot.UnitTests | ||||
|                 new TemplateVariableNameAndValue("{productId}", "1") | ||||
|             }; | ||||
|  | ||||
|             GivenThereIsAnUpstreamUrlPath("productservice/products/{productId}/variants"); | ||||
|             GivenThereIsAUrlPathMatch(new UrlPathMatch(true, templateVariables, "api/products/{productId}/")); | ||||
|             WhenIReplaceTheTemplateVariables(); | ||||
|             ThenTheUpstreamUrlPathIsReturned("productservice/products/1/variants"); | ||||
|             this.Given(x => x.GivenThereIsAnUpstreamUrlPath("productservice/products/{productId}/variants")) | ||||
|              .And(x => x.GivenThereIsAUrlPathMatch(new UrlPathMatch(true, templateVariables, "api/products/{productId}/"))) | ||||
|              .When(x => x.WhenIReplaceTheTemplateVariables()) | ||||
|              .Then(x => x.ThenTheUpstreamUrlPathIsReturned("productservice/products/1/variants")) | ||||
|              .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
| @@ -91,10 +99,11 @@ namespace Ocelot.UnitTests | ||||
|                 new TemplateVariableNameAndValue("{variantId}", "12") | ||||
|             }; | ||||
|  | ||||
|             GivenThereIsAnUpstreamUrlPath("productservice/products/{productId}/variants/{variantId}"); | ||||
|             GivenThereIsAUrlPathMatch(new UrlPathMatch(true, templateVariables, "api/products/{productId}/{variantId}")); | ||||
|             WhenIReplaceTheTemplateVariables(); | ||||
|             ThenTheUpstreamUrlPathIsReturned("productservice/products/1/variants/12"); | ||||
|             this.Given(x => x.GivenThereIsAnUpstreamUrlPath("productservice/products/{productId}/variants/{variantId}")) | ||||
|              .And(x => x.GivenThereIsAUrlPathMatch(new UrlPathMatch(true, templateVariables, "api/products/{productId}/{variantId}"))) | ||||
|              .When(x => x.WhenIReplaceTheTemplateVariables()) | ||||
|              .Then(x => x.ThenTheUpstreamUrlPathIsReturned("productservice/products/1/variants/12")) | ||||
|              .BDDfy(); | ||||
|         } | ||||
|  | ||||
|            [Fact] | ||||
| @@ -107,10 +116,11 @@ namespace Ocelot.UnitTests | ||||
|                 new TemplateVariableNameAndValue("{categoryId}", "34") | ||||
|             }; | ||||
|  | ||||
|             GivenThereIsAnUpstreamUrlPath("productservice/category/{categoryId}/products/{productId}/variants/{variantId}"); | ||||
|             GivenThereIsAUrlPathMatch(new UrlPathMatch(true, templateVariables, "api/products/{categoryId}/{productId}/{variantId}")); | ||||
|             WhenIReplaceTheTemplateVariables(); | ||||
|             ThenTheUpstreamUrlPathIsReturned("productservice/category/34/products/1/variants/12"); | ||||
|             this.Given(x => x.GivenThereIsAnUpstreamUrlPath("productservice/category/{categoryId}/products/{productId}/variants/{variantId}")) | ||||
|              .And(x => x.GivenThereIsAUrlPathMatch(new UrlPathMatch(true, templateVariables, "api/products/{categoryId}/{productId}/{variantId}"))) | ||||
|              .When(x => x.WhenIReplaceTheTemplateVariables()) | ||||
|              .Then(x => x.ThenTheUpstreamUrlPathIsReturned("productservice/category/34/products/1/variants/12")) | ||||
|              .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         private void GivenThereIsAnUpstreamUrlPath(string upstreamUrlPath) | ||||
|   | ||||
| @@ -6,6 +6,8 @@ using Xunit; | ||||
|  | ||||
| namespace Ocelot.UnitTests | ||||
| { | ||||
|     using TestStack.BDDfy; | ||||
|  | ||||
|     public class UrlPathTemplateMapRepositoryTests | ||||
|     { | ||||
|         private string _upstreamUrlPath;  | ||||
| @@ -23,42 +25,47 @@ namespace Ocelot.UnitTests | ||||
|         [Fact] | ||||
|         public void can_add_url_path() | ||||
|         { | ||||
|             GivenIHaveAnUpstreamUrlPath("/api/products/products/{productId}"); | ||||
|             GivenIWantToRouteRequestsToMyUpstreamUrlPath("/api/products/{productId}"); | ||||
|             WhenIAddTheConfiguration(); | ||||
|             ThenTheResponseIsSuccesful(); | ||||
|             this.Given(x => x.GivenIHaveAnUpstreamUrlPath("/api/products/products/{productId}")) | ||||
|                 .And(x => x.GivenIWantToRouteRequestsToMyUpstreamUrlPath("/api/products/{productId}")) | ||||
|                 .When(x => x.WhenIAddTheConfiguration()) | ||||
|                 .Then(x => x.ThenTheResponseIsSuccesful()) | ||||
|                 .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
|         public void can_get_url_path() | ||||
|         { | ||||
|             GivenIHaveSetUpADownstreamUrlPathAndAnUpstreamUrlPath("/api2", "http://www.someapi.com/api2"); | ||||
|             WhenIRetrieveTheUrlPathByDownstreamUrl(); | ||||
|             ThenTheUrlPathIsReturned(); | ||||
|             this.Given(x => x.GivenIHaveSetUpADownstreamUrlPathAndAnUpstreamUrlPath("/api2", "http://www.someapi.com/api2")) | ||||
|                  .When(x => x.WhenIRetrieveTheUrlPathByDownstreamUrl()) | ||||
|                  .Then(x => x.ThenTheUrlPathIsReturned()) | ||||
|                  .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
|         public void can_get_all_urls() | ||||
|         { | ||||
|             GivenIHaveSetUpADownstreamUrlPathAndAnUpstreamUrlPath("/api2", "http://www.someapi.com/api2"); | ||||
|             WhenIRetrieveTheUrls(); | ||||
|             ThenTheUrlsAreReturned(); | ||||
|             this.Given(x => x.GivenIHaveSetUpADownstreamUrlPathAndAnUpstreamUrlPath("/api2", "http://www.someapi.com/api2")) | ||||
|                  .When(x => x.WhenIRetrieveTheUrls()) | ||||
|                  .Then(x => x.ThenTheUrlsAreReturned()) | ||||
|                  .BDDfy(); | ||||
|         } | ||||
|   | ||||
|         [Fact] | ||||
|         public void should_return_error_response_when_url_path_already_used() | ||||
|         { | ||||
|             GivenIHaveSetUpADownstreamUrlPathAndAnUpstreamUrlPath("/api2", "http://www.someapi.com/api2"); | ||||
|             WhenITryToUseTheSameDownstreamUrl(); | ||||
|             ThenTheDownstreamUrlAlreadyBeenUsed(); | ||||
|             this.Given(x => x.GivenIHaveSetUpADownstreamUrlPathAndAnUpstreamUrlPath("/api2", "http://www.someapi.com/api2")) | ||||
|                  .When(x => x.WhenITryToUseTheSameDownstreamUrl()) | ||||
|                  .Then(x => x.ThenTheDownstreamUrlAlreadyBeenUsed()) | ||||
|                  .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
|         public void should_return_error_response_if_key_doesnt_exist() | ||||
|         { | ||||
|             GivenIWantToRouteRequestsToMyUpstreamUrlPath("/api"); | ||||
|             WhenIRetrieveTheUrlPathByDownstreamUrl(); | ||||
|             ThenTheKeyDoesNotExist(); | ||||
|             this.Given(x => x.GivenIWantToRouteRequestsToMyUpstreamUrlPath("/api")) | ||||
|                  .When(x => x.WhenIRetrieveTheUrlPathByDownstreamUrl()) | ||||
|                  .Then(x => x.ThenTheKeyDoesNotExist()) | ||||
|                  .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         private void WhenITryToUseTheSameDownstreamUrl() | ||||
|   | ||||
| @@ -1,4 +1,3 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using Ocelot.Library.Infrastructure.UrlPathMatcher; | ||||
| @@ -7,9 +6,11 @@ using Xunit; | ||||
|  | ||||
| namespace Ocelot.UnitTests | ||||
| { | ||||
|     using TestStack.BDDfy; | ||||
|  | ||||
|     public class UrlPathToUrlPathTemplateMatcherTests  | ||||
|     { | ||||
|         private IUrlPathToUrlPathTemplateMatcher _urlMapper; | ||||
|         private readonly IUrlPathToUrlPathTemplateMatcher _urlMapper; | ||||
|         private string _downstreamPath; | ||||
|         private string _downstreamPathTemplate; | ||||
|         private UrlPathMatch _result; | ||||
| @@ -21,56 +22,61 @@ namespace Ocelot.UnitTests | ||||
|         [Fact] | ||||
|         public void can_match_down_stream_url() | ||||
|         { | ||||
|             GivenIHaveADownstreamPath(""); | ||||
|             GivenIHaveAnDownstreamPathTemplate(""); | ||||
|             WhenIMatchThePaths(); | ||||
|             ThenTheResultIsTrue(); | ||||
|             ThenTheTemplatesDictionaryIs(new List<TemplateVariableNameAndValue>()); | ||||
|             ThenTheUrlPathTemplateIs(""); | ||||
|             this.Given(x => x.GivenIHaveADownstreamPath("")) | ||||
|                 .And(x => x.GivenIHaveAnDownstreamPathTemplate("")) | ||||
|                 .When(x => x.WhenIMatchThePaths()) | ||||
|                 .And(x => x.ThenTheResultIsTrue()) | ||||
|                 .And(x => x.ThenTheTemplatesDictionaryIs(new List<TemplateVariableNameAndValue>())) | ||||
|                 .And(x => x.ThenTheUrlPathTemplateIs("")) | ||||
|                 .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
|         public void can_match_down_stream_url_with_no_slash() | ||||
|         { | ||||
|             GivenIHaveADownstreamPath("api"); | ||||
|             GivenIHaveAnDownstreamPathTemplate("api"); | ||||
|             WhenIMatchThePaths(); | ||||
|             ThenTheResultIsTrue(); | ||||
|             ThenTheTemplatesDictionaryIs(new List<TemplateVariableNameAndValue>()); | ||||
|             ThenTheUrlPathTemplateIs("api"); | ||||
|             this.Given(x => x.GivenIHaveADownstreamPath("api")) | ||||
|                  .Given(x => x.GivenIHaveAnDownstreamPathTemplate("api")) | ||||
|                  .When(x => x.WhenIMatchThePaths()) | ||||
|                  .Then(x => x.ThenTheResultIsTrue()) | ||||
|                  .And(x => x.ThenTheTemplatesDictionaryIs(new List<TemplateVariableNameAndValue>())) | ||||
|                  .And(x => x.ThenTheUrlPathTemplateIs("api")) | ||||
|                  .BDDfy(); | ||||
|         } | ||||
|  | ||||
|          [Fact] | ||||
|         public void can_match_down_stream_url_with_one_slash() | ||||
|         { | ||||
|             GivenIHaveADownstreamPath("api/"); | ||||
|             GivenIHaveAnDownstreamPathTemplate("api/"); | ||||
|             WhenIMatchThePaths(); | ||||
|             ThenTheResultIsTrue(); | ||||
|             ThenTheTemplatesDictionaryIs(new List<TemplateVariableNameAndValue>()); | ||||
|             ThenTheUrlPathTemplateIs("api/"); | ||||
|             this.Given(x => x.GivenIHaveADownstreamPath("api/")) | ||||
|                  .Given(x => x.GivenIHaveAnDownstreamPathTemplate("api/")) | ||||
|                  .When(x => x.WhenIMatchThePaths()) | ||||
|                  .Then(x => x.ThenTheResultIsTrue()) | ||||
|                  .And(x => x.ThenTheTemplatesDictionaryIs(new List<TemplateVariableNameAndValue>())) | ||||
|                  .And(x => x.ThenTheUrlPathTemplateIs("api/")) | ||||
|                  .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
|         public void can_match_down_stream_url_with_downstream_template() | ||||
|         { | ||||
|             GivenIHaveADownstreamPath("api/product/products/"); | ||||
|             GivenIHaveAnDownstreamPathTemplate("api/product/products/"); | ||||
|             WhenIMatchThePaths(); | ||||
|             ThenTheResultIsTrue(); | ||||
|             ThenTheTemplatesDictionaryIs(new List<TemplateVariableNameAndValue>()); | ||||
|             ThenTheUrlPathTemplateIs("api/product/products/"); | ||||
|             this.Given(x => x.GivenIHaveADownstreamPath("api/product/products/")) | ||||
|               .Given(x => x.GivenIHaveAnDownstreamPathTemplate("api/product/products/")) | ||||
|               .When(x => x.WhenIMatchThePaths()) | ||||
|               .Then(x => x.ThenTheResultIsTrue()) | ||||
|               .And(x => x.ThenTheTemplatesDictionaryIs(new List<TemplateVariableNameAndValue>())) | ||||
|               .And(x => x.ThenTheUrlPathTemplateIs("api/product/products/")) | ||||
|               .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
|         public void can_match_down_stream_url_with_downstream_template_with_one_query_string_parameter() | ||||
|         { | ||||
|             GivenIHaveADownstreamPath("api/product/products/?soldout=false"); | ||||
|             GivenIHaveAnDownstreamPathTemplate("api/product/products/"); | ||||
|             WhenIMatchThePaths(); | ||||
|             ThenTheResultIsTrue(); | ||||
|             ThenTheTemplatesDictionaryIs(new List<TemplateVariableNameAndValue>()); | ||||
|             ThenTheUrlPathTemplateIs("api/product/products/"); | ||||
|             this.Given(x => x.GivenIHaveADownstreamPath("api/product/products/?soldout=false")) | ||||
|               .Given(x => x.GivenIHaveAnDownstreamPathTemplate("api/product/products/")) | ||||
|               .When(x => x.WhenIMatchThePaths()) | ||||
|               .Then(x => x.ThenTheResultIsTrue()) | ||||
|               .And(x => x.ThenTheTemplatesDictionaryIs(new List<TemplateVariableNameAndValue>())) | ||||
|               .And(x => x.ThenTheUrlPathTemplateIs("api/product/products/")) | ||||
|               .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
| @@ -80,13 +86,14 @@ namespace Ocelot.UnitTests | ||||
|             { | ||||
|                 new TemplateVariableNameAndValue("{productId}", "1") | ||||
|             }; | ||||
|             | ||||
|             GivenIHaveADownstreamPath("api/product/products/1/variants/?soldout=false"); | ||||
|             GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/variants/"); | ||||
|             WhenIMatchThePaths(); | ||||
|             ThenTheResultIsTrue(); | ||||
|             ThenTheTemplatesDictionaryIs(expectedTemplates); | ||||
|             ThenTheUrlPathTemplateIs("api/product/products/{productId}/variants/"); | ||||
|  | ||||
|             this.Given(x => x.GivenIHaveADownstreamPath("api/product/products/1/variants/?soldout=false")) | ||||
|               .Given(x => x.GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/variants/")) | ||||
|               .When(x => x.WhenIMatchThePaths()) | ||||
|               .Then(x => x.ThenTheResultIsTrue()) | ||||
|               .And(x => x.ThenTheTemplatesDictionaryIs(expectedTemplates)) | ||||
|               .And(x => x.ThenTheUrlPathTemplateIs("api/product/products/{productId}/variants/")) | ||||
|               .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
| @@ -97,13 +104,13 @@ namespace Ocelot.UnitTests | ||||
|                 new TemplateVariableNameAndValue("{productId}", "1") | ||||
|             }; | ||||
|  | ||||
|             GivenIHaveADownstreamPath("api/product/products/1"); | ||||
|             GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}"); | ||||
|             WhenIMatchThePaths(); | ||||
|             ThenTheResultIsTrue(); | ||||
|             ThenTheTemplatesDictionaryIs(expectedTemplates); | ||||
|             ThenTheUrlPathTemplateIs("api/product/products/{productId}"); | ||||
|  | ||||
|             this.Given(x => x.GivenIHaveADownstreamPath("api/product/products/1")) | ||||
|                .Given(x => x.GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}")) | ||||
|                .When(x => x.WhenIMatchThePaths()) | ||||
|                .Then(x => x.ThenTheResultIsTrue()) | ||||
|                .And(x => x.ThenTheTemplatesDictionaryIs(expectedTemplates)) | ||||
|                .And(x => x.ThenTheUrlPathTemplateIs("api/product/products/{productId}")) | ||||
|                .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
| @@ -114,14 +121,14 @@ namespace Ocelot.UnitTests | ||||
|                 new TemplateVariableNameAndValue("{productId}", "1"), | ||||
|                 new TemplateVariableNameAndValue("{categoryId}", "2") | ||||
|             }; | ||||
|              | ||||
|             GivenIHaveADownstreamPath("api/product/products/1/2"); | ||||
|             GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/{categoryId}"); | ||||
|             WhenIMatchThePaths(); | ||||
|             ThenTheResultIsTrue(); | ||||
|             ThenTheTemplatesDictionaryIs(expectedTemplates); | ||||
|             ThenTheUrlPathTemplateIs("api/product/products/{productId}/{categoryId}"); | ||||
|  | ||||
|             this.Given(x => x.GivenIHaveADownstreamPath("api/product/products/1/2")) | ||||
|                  .Given(x => x.GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/{categoryId}")) | ||||
|                  .When(x => x.WhenIMatchThePaths()) | ||||
|                  .Then(x => x.ThenTheResultIsTrue()) | ||||
|                  .And(x => x.ThenTheTemplatesDictionaryIs(expectedTemplates)) | ||||
|                  .And(x => x.ThenTheUrlPathTemplateIs("api/product/products/{productId}/{categoryId}")) | ||||
|                  .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
| @@ -132,14 +139,14 @@ namespace Ocelot.UnitTests | ||||
|                 new TemplateVariableNameAndValue("{productId}", "1"), | ||||
|                 new TemplateVariableNameAndValue("{categoryId}", "2") | ||||
|             }; | ||||
|              | ||||
|             GivenIHaveADownstreamPath("api/product/products/1/categories/2"); | ||||
|             GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/categories/{categoryId}"); | ||||
|             WhenIMatchThePaths(); | ||||
|             ThenTheResultIsTrue(); | ||||
|             ThenTheTemplatesDictionaryIs(expectedTemplates); | ||||
|             ThenTheUrlPathTemplateIs("api/product/products/{productId}/categories/{categoryId}"); | ||||
|  | ||||
|             this.Given(x => x.GivenIHaveADownstreamPath("api/product/products/1/categories/2")) | ||||
|                 .And(x => x.GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/categories/{categoryId}")) | ||||
|                 .When(x => x.WhenIMatchThePaths()) | ||||
|                 .Then(x => x.ThenTheResultIsTrue()) | ||||
|                 .And(x => x.ThenTheTemplatesDictionaryIs(expectedTemplates)) | ||||
|                 .And(x => x.ThenTheUrlPathTemplateIs("api/product/products/{productId}/categories/{categoryId}")) | ||||
|                 .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
| @@ -151,14 +158,14 @@ namespace Ocelot.UnitTests | ||||
|                 new TemplateVariableNameAndValue("{categoryId}", "2"), | ||||
|                 new TemplateVariableNameAndValue("{variantId}", "123") | ||||
|             }; | ||||
|              | ||||
|             GivenIHaveADownstreamPath("api/product/products/1/categories/2/variant/123"); | ||||
|             GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/categories/{categoryId}/variant/{variantId}"); | ||||
|             WhenIMatchThePaths(); | ||||
|             ThenTheResultIsTrue(); | ||||
|             ThenTheTemplatesDictionaryIs(expectedTemplates); | ||||
|             ThenTheUrlPathTemplateIs("api/product/products/{productId}/categories/{categoryId}/variant/{variantId}"); | ||||
|  | ||||
|             this.Given(x => x.GivenIHaveADownstreamPath("api/product/products/1/categories/2/variant/123")) | ||||
|                 .And(x => x.GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/categories/{categoryId}/variant/{variantId}")) | ||||
|                 .When(x => x.WhenIMatchThePaths()) | ||||
|                 .Then(x => x.ThenTheResultIsTrue()) | ||||
|                 .And(x => x.ThenTheTemplatesDictionaryIs(expectedTemplates)) | ||||
|                 .And(x => x.ThenTheUrlPathTemplateIs("api/product/products/{productId}/categories/{categoryId}/variant/{variantId}")) | ||||
|                 .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
| @@ -169,14 +176,14 @@ namespace Ocelot.UnitTests | ||||
|                 new TemplateVariableNameAndValue("{productId}", "1"), | ||||
|                 new TemplateVariableNameAndValue("{categoryId}", "2") | ||||
|             }; | ||||
|              | ||||
|             GivenIHaveADownstreamPath("api/product/products/1/categories/2/variant/"); | ||||
|             GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/categories/{categoryId}/variant/"); | ||||
|             WhenIMatchThePaths(); | ||||
|             ThenTheResultIsTrue(); | ||||
|             ThenTheTemplatesDictionaryIs(expectedTemplates); | ||||
|             ThenTheUrlPathTemplateIs("api/product/products/{productId}/categories/{categoryId}/variant/"); | ||||
|  | ||||
|             this.Given(x => x.GivenIHaveADownstreamPath("api/product/products/1/categories/2/variant/")) | ||||
|                  .And(x => x.GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/categories/{categoryId}/variant/")) | ||||
|                  .When(x => x.WhenIMatchThePaths()) | ||||
|                  .Then(x => x.ThenTheResultIsTrue()) | ||||
|                  .And(x => x.ThenTheTemplatesDictionaryIs(expectedTemplates)) | ||||
|                  .And(x => x.ThenTheUrlPathTemplateIs("api/product/products/{productId}/categories/{categoryId}/variant/")) | ||||
|                  .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         private void ThenTheTemplatesDictionaryIs(List<TemplateVariableNameAndValue> expectedResults) | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| { | ||||
| { | ||||
|     "version": "1.0.0-*", | ||||
|  | ||||
|     "testRunner": "xunit", | ||||
| @@ -22,7 +22,8 @@ | ||||
|         "Ocelot.Library": "1.0.0-*", | ||||
|         "xunit": "2.1.0", | ||||
|         "dotnet-test-xunit": "2.2.0-preview2-build1029", | ||||
|         "Shouldly": "2.8.0" | ||||
|       "Shouldly": "2.8.0", | ||||
|       "TestStack.BDDfy": "4.3.1" | ||||
|     }, | ||||
|  | ||||
|     "frameworks": { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Tom Gardham-Pallister
					Tom Gardham-Pallister