merge and script updates

This commit is contained in:
Tom Gardham-Pallister 2016-08-25 21:07:01 +01:00
commit 267ad5e98b
11 changed files with 198 additions and 154 deletions

View File

@ -3,14 +3,18 @@ echo -------------------------
echo Running Ocelot.UnitTests echo Running Ocelot.UnitTests
dotnet restore test/Ocelot.UnitTests/
dotnet test test/Ocelot.UnitTests/ dotnet test test/Ocelot.UnitTests/
echo Running Ocelot.AcceptanceTests echo Running Ocelot.AcceptanceTests
dotnet restore test/Ocelot.AcceptanceTests/
dotnet test test/Ocelot.AcceptanceTests/ dotnet test test/Ocelot.AcceptanceTests/
echo Building Ocelot echo Building Ocelot
dotnet restore src/Ocelot
dotnet build src/Ocelot
dotnet publish src/Ocelot dotnet publish src/Ocelot

View File

@ -5,6 +5,8 @@ echo Running Ocelot.Benchmarks
cd test/Ocelot.Benchmarks cd test/Ocelot.Benchmarks
dotnet restore
dotnet run dotnet run
cd ../../ cd ../../

View File

@ -3,10 +3,12 @@ echo -------------------------
echo Running Ocelot.UnitTests echo Running Ocelot.UnitTests
dotnet restore test/Ocelot.UnitTests/
dotnet test test/Ocelot.UnitTests/ dotnet test test/Ocelot.UnitTests/
echo Running Ocelot.AcceptanceTests echo Running Ocelot.AcceptanceTests
dotnet restore test/Ocelot.AcceptanceTests/
dotnet test test/Ocelot.AcceptanceTests/ dotnet test test/Ocelot.AcceptanceTests/

View File

@ -9,6 +9,7 @@ using Shouldly;
namespace Ocelot.AcceptanceTests namespace Ocelot.AcceptanceTests
{ {
using System.Net; using System.Net;
using TestStack.BDDfy;
public class RouterTests : IDisposable public class RouterTests : IDisposable
{ {
@ -30,8 +31,9 @@ namespace Ocelot.AcceptanceTests
[Fact] [Fact]
public void should_return_response_404() public void should_return_response_404()
{ {
WhenIRequestTheUrl("/"); this.When(x => x.WhenIRequestTheUrl("/"))
ThenTheStatusCodeShouldBe(HttpStatusCode.NotFound); .Then(x => x.ThenTheStatusCodeShouldBe(HttpStatusCode.NotFound))
.BDDfy();
} }
private void WhenIRequestTheUrl(string url) private void WhenIRequestTheUrl(string url)

View File

@ -1,4 +1,4 @@
{ {
"version": "1.0.0-*", "version": "1.0.0-*",
"testRunner": "xunit", "testRunner": "xunit",
@ -24,7 +24,8 @@
"dotnet-test-xunit": "2.2.0-preview2-build1029", "dotnet-test-xunit": "2.2.0-preview2-build1029",
"Shouldly": "2.8.0", "Shouldly": "2.8.0",
"Ocelot": "1.0.0-*", "Ocelot": "1.0.0-*",
"Microsoft.AspNetCore.TestHost": "1.0.0" "Microsoft.AspNetCore.TestHost": "1.0.0",
"TestStack.BDDfy": "4.3.1"
}, },
"frameworks": { "frameworks": {

View File

@ -5,11 +5,13 @@ using Xunit;
namespace Ocelot.UnitTests namespace Ocelot.UnitTests
{ {
using TestStack.BDDfy;
public class HostUrlMapRepositoryTests public class HostUrlMapRepositoryTests
{ {
private string _upstreamBaseUrl; private string _upstreamBaseUrl;
private string _downstreamBaseUrl; private string _downstreamBaseUrl;
private IHostUrlMapRepository _repository; private readonly IHostUrlMapRepository _repository;
private Response _response; private Response _response;
private Response<HostUrlMap> _getRouteResponse; private Response<HostUrlMap> _getRouteResponse;
@ -21,34 +23,38 @@ namespace Ocelot.UnitTests
[Fact] [Fact]
public void can_add_route() public void can_add_route()
{ {
GivenIHaveAnUpstreamBaseUrl("www.someapi.com"); this.Given(x => x.GivenIHaveAnUpstreamBaseUrl("www.someapi.com"))
GivenIWantToRouteRequestsFromMyDownstreamBaseUrl("api"); .And(x => x.GivenIWantToRouteRequestsFromMyDownstreamBaseUrl("api"))
WhenIAddTheConfiguration(); .When(x => x.WhenIAddTheConfiguration())
ThenTheResponseIsSuccesful(); .Then(x => x.ThenTheResponseIsSuccesful())
.BDDfy();
} }
[Fact] [Fact]
public void can_get_route_by_key() public void can_get_route_by_key()
{ {
GivenIHaveSetUpAnApiKeyAndUpstreamUrl("api2", "www.someapi.com"); this.Given(x => x.GivenIHaveSetUpAnApiKeyAndUpstreamUrl("api2", "www.someapi.com"))
WhenIRetrieveTheRouteByKey(); .When(x => x.WhenIRetrieveTheRouteByKey())
ThenTheRouteIsReturned(); .Then(x => x.ThenTheRouteIsReturned())
.BDDfy();
} }
[Fact] [Fact]
public void should_return_error_response_when_key_already_used() public void should_return_error_response_when_key_already_used()
{ {
GivenIHaveSetUpAnApiKeyAndUpstreamUrl("api2", "www.someapi.com"); this.Given(x => x.GivenIHaveSetUpAnApiKeyAndUpstreamUrl("api2", "www.someapi.com"))
WhenITryToUseTheSameKey(); .When(x => x.WhenITryToUseTheSameKey())
ThenTheKeyHasAlreadyBeenUsed(); .Then(x => x.ThenTheKeyHasAlreadyBeenUsed())
.BDDfy();
} }
[Fact] [Fact]
public void should_return_error_response_if_key_doesnt_exist() public void should_return_error_response_if_key_doesnt_exist()
{ {
GivenIWantToRouteRequestsFromMyDownstreamBaseUrl("api"); this.Given(x => x.GivenIWantToRouteRequestsFromMyDownstreamBaseUrl("api"))
WhenIRetrieveTheRouteByKey(); .When(x => x.WhenIRetrieveTheRouteByKey())
ThenTheKeyDoesNotExist(); .Then(x => x.ThenTheKeyDoesNotExist())
.BDDfy();
} }
private void WhenITryToUseTheSameKey() private void WhenITryToUseTheSameKey()

View File

@ -3,14 +3,14 @@ using Ocelot.Library.Infrastructure.UrlFinder;
using Ocelot.Library.Infrastructure.Responses; using Ocelot.Library.Infrastructure.Responses;
using Xunit; using Xunit;
using Shouldly; using Shouldly;
using System; using TestStack.BDDfy;
namespace Ocelot.UnitTests namespace Ocelot.UnitTests
{ {
public class UpstreamBaseUrlFinderTests public class UpstreamBaseUrlFinderTests
{ {
private IUpstreamHostUrlFinder _upstreamBaseUrlFinder; private readonly IUpstreamHostUrlFinder _upstreamBaseUrlFinder;
private IHostUrlMapRepository _hostUrlMapRepository; private readonly IHostUrlMapRepository _hostUrlMapRepository;
private string _downstreamBaseUrl; private string _downstreamBaseUrl;
private Response<string> _result; private Response<string> _result;
public UpstreamBaseUrlFinderTests() public UpstreamBaseUrlFinderTests()
@ -22,18 +22,20 @@ namespace Ocelot.UnitTests
[Fact] [Fact]
public void can_find_base_url() public void can_find_base_url()
{ {
GivenTheBaseUrlMapExists(new HostUrlMap("api.tom.com", "api.laura.com")); this.Given(x => x.GivenTheBaseUrlMapExists(new HostUrlMap("api.tom.com", "api.laura.com")))
GivenTheDownstreamBaseUrlIs("api.tom.com"); .And(x => x.GivenTheDownstreamBaseUrlIs("api.tom.com"))
WhenIFindTheMatchingUpstreamBaseUrl(); .When(x => x.WhenIFindTheMatchingUpstreamBaseUrl())
ThenTheFollowingIsReturned("api.laura.com"); .Then(x => x.ThenTheFollowingIsReturned("api.laura.com"))
.BDDfy();
} }
[Fact] [Fact]
public void cant_find_base_url() public void cant_find_base_url()
{ {
GivenTheDownstreamBaseUrlIs("api.tom.com"); this.Given(x => x.GivenTheDownstreamBaseUrlIs("api.tom.com"))
WhenIFindTheMatchingUpstreamBaseUrl(); .When(x => x.WhenIFindTheMatchingUpstreamBaseUrl())
ThenAnErrorIsReturned(); .Then(x => x.ThenAnErrorIsReturned())
.BDDfy();
} }
private void ThenAnErrorIsReturned() private void ThenAnErrorIsReturned()

View File

@ -6,52 +6,58 @@ using Xunit;
namespace Ocelot.UnitTests namespace Ocelot.UnitTests
{ {
using TestStack.BDDfy;
public class UpstreamUrlPathTemplateVariableReplacerTests public class UpstreamUrlPathTemplateVariableReplacerTests
{ {
private string _upstreamUrlPath; private string _upstreamUrlPath;
private UrlPathMatch _urlPathMatch; private UrlPathMatch _urlPathMatch;
private string _result; private string _result;
private IUpstreamUrlPathTemplateVariableReplacer _upstreamUrlPathReplacer; private readonly IUpstreamUrlPathTemplateVariableReplacer _upstreamUrlPathReplacer;
public UpstreamUrlPathTemplateVariableReplacerTests() public UpstreamUrlPathTemplateVariableReplacerTests()
{ {
_upstreamUrlPathReplacer = new UpstreamUrlPathTemplateVariableReplacer(); _upstreamUrlPathReplacer = new UpstreamUrlPathTemplateVariableReplacer();
} }
[Fact] [Fact]
public void can_replace_no_template_variables() public void can_replace_no_template_variables()
{ {
GivenThereIsAnUpstreamUrlPath(""); this.Given(x => x.GivenThereIsAnUpstreamUrlPath(""))
GivenThereIsAUrlPathMatch(new UrlPathMatch(true, new List<TemplateVariableNameAndValue>(), "")); .And(x => x.GivenThereIsAUrlPathMatch(new UrlPathMatch(true, new List<TemplateVariableNameAndValue>(), "")))
WhenIReplaceTheTemplateVariables(); .When(x => x.WhenIReplaceTheTemplateVariables())
ThenTheUpstreamUrlPathIsReturned(""); .Then(x => x.ThenTheUpstreamUrlPathIsReturned(""))
.BDDfy();
} }
[Fact] [Fact]
public void can_replace_url_no_slash() public void can_replace_url_no_slash()
{ {
GivenThereIsAnUpstreamUrlPath("api"); this.Given(x => x.GivenThereIsAnUpstreamUrlPath("api"))
GivenThereIsAUrlPathMatch(new UrlPathMatch(true, new List<TemplateVariableNameAndValue>(), "api")); .And(x => x.GivenThereIsAUrlPathMatch(new UrlPathMatch(true, new List<TemplateVariableNameAndValue>(), "api")))
WhenIReplaceTheTemplateVariables(); .When(x => x.WhenIReplaceTheTemplateVariables())
ThenTheUpstreamUrlPathIsReturned("api"); .Then(x => x.ThenTheUpstreamUrlPathIsReturned("api"))
.BDDfy();
} }
[Fact] [Fact]
public void can_replace_url_one_slash() public void can_replace_url_one_slash()
{ {
GivenThereIsAnUpstreamUrlPath("api/"); this.Given(x => x.GivenThereIsAnUpstreamUrlPath("api/"))
GivenThereIsAUrlPathMatch(new UrlPathMatch(true, new List<TemplateVariableNameAndValue>(), "api/")); .And(x => x.GivenThereIsAUrlPathMatch(new UrlPathMatch(true, new List<TemplateVariableNameAndValue>(), "api/")))
WhenIReplaceTheTemplateVariables(); .When(x => x.WhenIReplaceTheTemplateVariables())
ThenTheUpstreamUrlPathIsReturned("api/"); .Then(x => x.ThenTheUpstreamUrlPathIsReturned("api/"))
.BDDfy();
} }
[Fact] [Fact]
public void can_replace_url_multiple_slash() public void can_replace_url_multiple_slash()
{ {
GivenThereIsAnUpstreamUrlPath("api/product/products/"); this.Given(x => x.GivenThereIsAnUpstreamUrlPath("api/product/products/"))
GivenThereIsAUrlPathMatch(new UrlPathMatch(true, new List<TemplateVariableNameAndValue>(), "api/product/products/")); .And(x => x.GivenThereIsAUrlPathMatch(new UrlPathMatch(true, new List<TemplateVariableNameAndValue>(), "api/product/products/")))
WhenIReplaceTheTemplateVariables(); .When(x => x.WhenIReplaceTheTemplateVariables())
ThenTheUpstreamUrlPathIsReturned("api/product/products/"); .Then(x => x.ThenTheUpstreamUrlPathIsReturned("api/product/products/"))
.BDDfy();
} }
[Fact] [Fact]
@ -62,10 +68,11 @@ namespace Ocelot.UnitTests
new TemplateVariableNameAndValue("{productId}", "1") new TemplateVariableNameAndValue("{productId}", "1")
}; };
GivenThereIsAnUpstreamUrlPath("productservice/products/{productId}/"); this.Given(x => x.GivenThereIsAnUpstreamUrlPath("productservice/products/{productId}/"))
GivenThereIsAUrlPathMatch(new UrlPathMatch(true, templateVariables, "api/products/{productId}/")); .And(x => x.GivenThereIsAUrlPathMatch(new UrlPathMatch(true, templateVariables, "api/products/{productId}/")))
WhenIReplaceTheTemplateVariables(); .When(x => x.WhenIReplaceTheTemplateVariables())
ThenTheUpstreamUrlPathIsReturned("productservice/products/1/"); .Then(x => x.ThenTheUpstreamUrlPathIsReturned("productservice/products/1/"))
.BDDfy();
} }
[Fact] [Fact]
@ -76,10 +83,11 @@ namespace Ocelot.UnitTests
new TemplateVariableNameAndValue("{productId}", "1") new TemplateVariableNameAndValue("{productId}", "1")
}; };
GivenThereIsAnUpstreamUrlPath("productservice/products/{productId}/variants"); this.Given(x => x.GivenThereIsAnUpstreamUrlPath("productservice/products/{productId}/variants"))
GivenThereIsAUrlPathMatch(new UrlPathMatch(true, templateVariables, "api/products/{productId}/")); .And(x => x.GivenThereIsAUrlPathMatch(new UrlPathMatch(true, templateVariables, "api/products/{productId}/")))
WhenIReplaceTheTemplateVariables(); .When(x => x.WhenIReplaceTheTemplateVariables())
ThenTheUpstreamUrlPathIsReturned("productservice/products/1/variants"); .Then(x => x.ThenTheUpstreamUrlPathIsReturned("productservice/products/1/variants"))
.BDDfy();
} }
[Fact] [Fact]
@ -91,10 +99,11 @@ namespace Ocelot.UnitTests
new TemplateVariableNameAndValue("{variantId}", "12") new TemplateVariableNameAndValue("{variantId}", "12")
}; };
GivenThereIsAnUpstreamUrlPath("productservice/products/{productId}/variants/{variantId}"); this.Given(x => x.GivenThereIsAnUpstreamUrlPath("productservice/products/{productId}/variants/{variantId}"))
GivenThereIsAUrlPathMatch(new UrlPathMatch(true, templateVariables, "api/products/{productId}/{variantId}")); .And(x => x.GivenThereIsAUrlPathMatch(new UrlPathMatch(true, templateVariables, "api/products/{productId}/{variantId}")))
WhenIReplaceTheTemplateVariables(); .When(x => x.WhenIReplaceTheTemplateVariables())
ThenTheUpstreamUrlPathIsReturned("productservice/products/1/variants/12"); .Then(x => x.ThenTheUpstreamUrlPathIsReturned("productservice/products/1/variants/12"))
.BDDfy();
} }
[Fact] [Fact]
@ -107,10 +116,11 @@ namespace Ocelot.UnitTests
new TemplateVariableNameAndValue("{categoryId}", "34") new TemplateVariableNameAndValue("{categoryId}", "34")
}; };
GivenThereIsAnUpstreamUrlPath("productservice/category/{categoryId}/products/{productId}/variants/{variantId}"); this.Given(x => x.GivenThereIsAnUpstreamUrlPath("productservice/category/{categoryId}/products/{productId}/variants/{variantId}"))
GivenThereIsAUrlPathMatch(new UrlPathMatch(true, templateVariables, "api/products/{categoryId}/{productId}/{variantId}")); .And(x => x.GivenThereIsAUrlPathMatch(new UrlPathMatch(true, templateVariables, "api/products/{categoryId}/{productId}/{variantId}")))
WhenIReplaceTheTemplateVariables(); .When(x => x.WhenIReplaceTheTemplateVariables())
ThenTheUpstreamUrlPathIsReturned("productservice/category/34/products/1/variants/12"); .Then(x => x.ThenTheUpstreamUrlPathIsReturned("productservice/category/34/products/1/variants/12"))
.BDDfy();
} }
private void GivenThereIsAnUpstreamUrlPath(string upstreamUrlPath) private void GivenThereIsAnUpstreamUrlPath(string upstreamUrlPath)

View File

@ -6,6 +6,8 @@ using Xunit;
namespace Ocelot.UnitTests namespace Ocelot.UnitTests
{ {
using TestStack.BDDfy;
public class UrlPathTemplateMapRepositoryTests public class UrlPathTemplateMapRepositoryTests
{ {
private string _upstreamUrlPath; private string _upstreamUrlPath;
@ -23,42 +25,47 @@ namespace Ocelot.UnitTests
[Fact] [Fact]
public void can_add_url_path() public void can_add_url_path()
{ {
GivenIHaveAnUpstreamUrlPath("/api/products/products/{productId}"); this.Given(x => x.GivenIHaveAnUpstreamUrlPath("/api/products/products/{productId}"))
GivenIWantToRouteRequestsToMyUpstreamUrlPath("/api/products/{productId}"); .And(x => x.GivenIWantToRouteRequestsToMyUpstreamUrlPath("/api/products/{productId}"))
WhenIAddTheConfiguration(); .When(x => x.WhenIAddTheConfiguration())
ThenTheResponseIsSuccesful(); .Then(x => x.ThenTheResponseIsSuccesful())
.BDDfy();
} }
[Fact] [Fact]
public void can_get_url_path() public void can_get_url_path()
{ {
GivenIHaveSetUpADownstreamUrlPathAndAnUpstreamUrlPath("/api2", "http://www.someapi.com/api2"); this.Given(x => x.GivenIHaveSetUpADownstreamUrlPathAndAnUpstreamUrlPath("/api2", "http://www.someapi.com/api2"))
WhenIRetrieveTheUrlPathByDownstreamUrl(); .When(x => x.WhenIRetrieveTheUrlPathByDownstreamUrl())
ThenTheUrlPathIsReturned(); .Then(x => x.ThenTheUrlPathIsReturned())
.BDDfy();
} }
[Fact] [Fact]
public void can_get_all_urls() public void can_get_all_urls()
{ {
GivenIHaveSetUpADownstreamUrlPathAndAnUpstreamUrlPath("/api2", "http://www.someapi.com/api2"); this.Given(x => x.GivenIHaveSetUpADownstreamUrlPathAndAnUpstreamUrlPath("/api2", "http://www.someapi.com/api2"))
WhenIRetrieveTheUrls(); .When(x => x.WhenIRetrieveTheUrls())
ThenTheUrlsAreReturned(); .Then(x => x.ThenTheUrlsAreReturned())
.BDDfy();
} }
[Fact] [Fact]
public void should_return_error_response_when_url_path_already_used() public void should_return_error_response_when_url_path_already_used()
{ {
GivenIHaveSetUpADownstreamUrlPathAndAnUpstreamUrlPath("/api2", "http://www.someapi.com/api2"); this.Given(x => x.GivenIHaveSetUpADownstreamUrlPathAndAnUpstreamUrlPath("/api2", "http://www.someapi.com/api2"))
WhenITryToUseTheSameDownstreamUrl(); .When(x => x.WhenITryToUseTheSameDownstreamUrl())
ThenTheDownstreamUrlAlreadyBeenUsed(); .Then(x => x.ThenTheDownstreamUrlAlreadyBeenUsed())
.BDDfy();
} }
[Fact] [Fact]
public void should_return_error_response_if_key_doesnt_exist() public void should_return_error_response_if_key_doesnt_exist()
{ {
GivenIWantToRouteRequestsToMyUpstreamUrlPath("/api"); this.Given(x => x.GivenIWantToRouteRequestsToMyUpstreamUrlPath("/api"))
WhenIRetrieveTheUrlPathByDownstreamUrl(); .When(x => x.WhenIRetrieveTheUrlPathByDownstreamUrl())
ThenTheKeyDoesNotExist(); .Then(x => x.ThenTheKeyDoesNotExist())
.BDDfy();
} }
private void WhenITryToUseTheSameDownstreamUrl() private void WhenITryToUseTheSameDownstreamUrl()

View File

@ -1,4 +1,3 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Ocelot.Library.Infrastructure.UrlPathMatcher; using Ocelot.Library.Infrastructure.UrlPathMatcher;
@ -7,9 +6,11 @@ using Xunit;
namespace Ocelot.UnitTests namespace Ocelot.UnitTests
{ {
using TestStack.BDDfy;
public class UrlPathToUrlPathTemplateMatcherTests public class UrlPathToUrlPathTemplateMatcherTests
{ {
private IUrlPathToUrlPathTemplateMatcher _urlMapper; private readonly IUrlPathToUrlPathTemplateMatcher _urlMapper;
private string _downstreamPath; private string _downstreamPath;
private string _downstreamPathTemplate; private string _downstreamPathTemplate;
private UrlPathMatch _result; private UrlPathMatch _result;
@ -21,56 +22,61 @@ namespace Ocelot.UnitTests
[Fact] [Fact]
public void can_match_down_stream_url() public void can_match_down_stream_url()
{ {
GivenIHaveADownstreamPath(""); this.Given(x => x.GivenIHaveADownstreamPath(""))
GivenIHaveAnDownstreamPathTemplate(""); .And(x => x.GivenIHaveAnDownstreamPathTemplate(""))
WhenIMatchThePaths(); .When(x => x.WhenIMatchThePaths())
ThenTheResultIsTrue(); .And(x => x.ThenTheResultIsTrue())
ThenTheTemplatesDictionaryIs(new List<TemplateVariableNameAndValue>()); .And(x => x.ThenTheTemplatesDictionaryIs(new List<TemplateVariableNameAndValue>()))
ThenTheUrlPathTemplateIs(""); .And(x => x.ThenTheUrlPathTemplateIs(""))
.BDDfy();
} }
[Fact] [Fact]
public void can_match_down_stream_url_with_no_slash() public void can_match_down_stream_url_with_no_slash()
{ {
GivenIHaveADownstreamPath("api"); this.Given(x => x.GivenIHaveADownstreamPath("api"))
GivenIHaveAnDownstreamPathTemplate("api"); .Given(x => x.GivenIHaveAnDownstreamPathTemplate("api"))
WhenIMatchThePaths(); .When(x => x.WhenIMatchThePaths())
ThenTheResultIsTrue(); .Then(x => x.ThenTheResultIsTrue())
ThenTheTemplatesDictionaryIs(new List<TemplateVariableNameAndValue>()); .And(x => x.ThenTheTemplatesDictionaryIs(new List<TemplateVariableNameAndValue>()))
ThenTheUrlPathTemplateIs("api"); .And(x => x.ThenTheUrlPathTemplateIs("api"))
.BDDfy();
} }
[Fact] [Fact]
public void can_match_down_stream_url_with_one_slash() public void can_match_down_stream_url_with_one_slash()
{ {
GivenIHaveADownstreamPath("api/"); this.Given(x => x.GivenIHaveADownstreamPath("api/"))
GivenIHaveAnDownstreamPathTemplate("api/"); .Given(x => x.GivenIHaveAnDownstreamPathTemplate("api/"))
WhenIMatchThePaths(); .When(x => x.WhenIMatchThePaths())
ThenTheResultIsTrue(); .Then(x => x.ThenTheResultIsTrue())
ThenTheTemplatesDictionaryIs(new List<TemplateVariableNameAndValue>()); .And(x => x.ThenTheTemplatesDictionaryIs(new List<TemplateVariableNameAndValue>()))
ThenTheUrlPathTemplateIs("api/"); .And(x => x.ThenTheUrlPathTemplateIs("api/"))
.BDDfy();
} }
[Fact] [Fact]
public void can_match_down_stream_url_with_downstream_template() public void can_match_down_stream_url_with_downstream_template()
{ {
GivenIHaveADownstreamPath("api/product/products/"); this.Given(x => x.GivenIHaveADownstreamPath("api/product/products/"))
GivenIHaveAnDownstreamPathTemplate("api/product/products/"); .Given(x => x.GivenIHaveAnDownstreamPathTemplate("api/product/products/"))
WhenIMatchThePaths(); .When(x => x.WhenIMatchThePaths())
ThenTheResultIsTrue(); .Then(x => x.ThenTheResultIsTrue())
ThenTheTemplatesDictionaryIs(new List<TemplateVariableNameAndValue>()); .And(x => x.ThenTheTemplatesDictionaryIs(new List<TemplateVariableNameAndValue>()))
ThenTheUrlPathTemplateIs("api/product/products/"); .And(x => x.ThenTheUrlPathTemplateIs("api/product/products/"))
.BDDfy();
} }
[Fact] [Fact]
public void can_match_down_stream_url_with_downstream_template_with_one_query_string_parameter() public void can_match_down_stream_url_with_downstream_template_with_one_query_string_parameter()
{ {
GivenIHaveADownstreamPath("api/product/products/?soldout=false"); this.Given(x => x.GivenIHaveADownstreamPath("api/product/products/?soldout=false"))
GivenIHaveAnDownstreamPathTemplate("api/product/products/"); .Given(x => x.GivenIHaveAnDownstreamPathTemplate("api/product/products/"))
WhenIMatchThePaths(); .When(x => x.WhenIMatchThePaths())
ThenTheResultIsTrue(); .Then(x => x.ThenTheResultIsTrue())
ThenTheTemplatesDictionaryIs(new List<TemplateVariableNameAndValue>()); .And(x => x.ThenTheTemplatesDictionaryIs(new List<TemplateVariableNameAndValue>()))
ThenTheUrlPathTemplateIs("api/product/products/"); .And(x => x.ThenTheUrlPathTemplateIs("api/product/products/"))
.BDDfy();
} }
[Fact] [Fact]
@ -81,12 +87,13 @@ namespace Ocelot.UnitTests
new TemplateVariableNameAndValue("{productId}", "1") new TemplateVariableNameAndValue("{productId}", "1")
}; };
GivenIHaveADownstreamPath("api/product/products/1/variants/?soldout=false"); this.Given(x => x.GivenIHaveADownstreamPath("api/product/products/1/variants/?soldout=false"))
GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/variants/"); .Given(x => x.GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/variants/"))
WhenIMatchThePaths(); .When(x => x.WhenIMatchThePaths())
ThenTheResultIsTrue(); .Then(x => x.ThenTheResultIsTrue())
ThenTheTemplatesDictionaryIs(expectedTemplates); .And(x => x.ThenTheTemplatesDictionaryIs(expectedTemplates))
ThenTheUrlPathTemplateIs("api/product/products/{productId}/variants/"); .And(x => x.ThenTheUrlPathTemplateIs("api/product/products/{productId}/variants/"))
.BDDfy();
} }
[Fact] [Fact]
@ -97,13 +104,13 @@ namespace Ocelot.UnitTests
new TemplateVariableNameAndValue("{productId}", "1") new TemplateVariableNameAndValue("{productId}", "1")
}; };
GivenIHaveADownstreamPath("api/product/products/1"); this.Given(x => x.GivenIHaveADownstreamPath("api/product/products/1"))
GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}"); .Given(x => x.GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}"))
WhenIMatchThePaths(); .When(x => x.WhenIMatchThePaths())
ThenTheResultIsTrue(); .Then(x => x.ThenTheResultIsTrue())
ThenTheTemplatesDictionaryIs(expectedTemplates); .And(x => x.ThenTheTemplatesDictionaryIs(expectedTemplates))
ThenTheUrlPathTemplateIs("api/product/products/{productId}"); .And(x => x.ThenTheUrlPathTemplateIs("api/product/products/{productId}"))
.BDDfy();
} }
[Fact] [Fact]
@ -115,13 +122,13 @@ namespace Ocelot.UnitTests
new TemplateVariableNameAndValue("{categoryId}", "2") new TemplateVariableNameAndValue("{categoryId}", "2")
}; };
GivenIHaveADownstreamPath("api/product/products/1/2"); this.Given(x => x.GivenIHaveADownstreamPath("api/product/products/1/2"))
GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/{categoryId}"); .Given(x => x.GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/{categoryId}"))
WhenIMatchThePaths(); .When(x => x.WhenIMatchThePaths())
ThenTheResultIsTrue(); .Then(x => x.ThenTheResultIsTrue())
ThenTheTemplatesDictionaryIs(expectedTemplates); .And(x => x.ThenTheTemplatesDictionaryIs(expectedTemplates))
ThenTheUrlPathTemplateIs("api/product/products/{productId}/{categoryId}"); .And(x => x.ThenTheUrlPathTemplateIs("api/product/products/{productId}/{categoryId}"))
.BDDfy();
} }
[Fact] [Fact]
@ -133,13 +140,13 @@ namespace Ocelot.UnitTests
new TemplateVariableNameAndValue("{categoryId}", "2") new TemplateVariableNameAndValue("{categoryId}", "2")
}; };
GivenIHaveADownstreamPath("api/product/products/1/categories/2"); this.Given(x => x.GivenIHaveADownstreamPath("api/product/products/1/categories/2"))
GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/categories/{categoryId}"); .And(x => x.GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/categories/{categoryId}"))
WhenIMatchThePaths(); .When(x => x.WhenIMatchThePaths())
ThenTheResultIsTrue(); .Then(x => x.ThenTheResultIsTrue())
ThenTheTemplatesDictionaryIs(expectedTemplates); .And(x => x.ThenTheTemplatesDictionaryIs(expectedTemplates))
ThenTheUrlPathTemplateIs("api/product/products/{productId}/categories/{categoryId}"); .And(x => x.ThenTheUrlPathTemplateIs("api/product/products/{productId}/categories/{categoryId}"))
.BDDfy();
} }
[Fact] [Fact]
@ -152,13 +159,13 @@ namespace Ocelot.UnitTests
new TemplateVariableNameAndValue("{variantId}", "123") new TemplateVariableNameAndValue("{variantId}", "123")
}; };
GivenIHaveADownstreamPath("api/product/products/1/categories/2/variant/123"); this.Given(x => x.GivenIHaveADownstreamPath("api/product/products/1/categories/2/variant/123"))
GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/categories/{categoryId}/variant/{variantId}"); .And(x => x.GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/categories/{categoryId}/variant/{variantId}"))
WhenIMatchThePaths(); .When(x => x.WhenIMatchThePaths())
ThenTheResultIsTrue(); .Then(x => x.ThenTheResultIsTrue())
ThenTheTemplatesDictionaryIs(expectedTemplates); .And(x => x.ThenTheTemplatesDictionaryIs(expectedTemplates))
ThenTheUrlPathTemplateIs("api/product/products/{productId}/categories/{categoryId}/variant/{variantId}"); .And(x => x.ThenTheUrlPathTemplateIs("api/product/products/{productId}/categories/{categoryId}/variant/{variantId}"))
.BDDfy();
} }
[Fact] [Fact]
@ -170,13 +177,13 @@ namespace Ocelot.UnitTests
new TemplateVariableNameAndValue("{categoryId}", "2") new TemplateVariableNameAndValue("{categoryId}", "2")
}; };
GivenIHaveADownstreamPath("api/product/products/1/categories/2/variant/"); this.Given(x => x.GivenIHaveADownstreamPath("api/product/products/1/categories/2/variant/"))
GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/categories/{categoryId}/variant/"); .And(x => x.GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/categories/{categoryId}/variant/"))
WhenIMatchThePaths(); .When(x => x.WhenIMatchThePaths())
ThenTheResultIsTrue(); .Then(x => x.ThenTheResultIsTrue())
ThenTheTemplatesDictionaryIs(expectedTemplates); .And(x => x.ThenTheTemplatesDictionaryIs(expectedTemplates))
ThenTheUrlPathTemplateIs("api/product/products/{productId}/categories/{categoryId}/variant/"); .And(x => x.ThenTheUrlPathTemplateIs("api/product/products/{productId}/categories/{categoryId}/variant/"))
.BDDfy();
} }
private void ThenTheTemplatesDictionaryIs(List<TemplateVariableNameAndValue> expectedResults) private void ThenTheTemplatesDictionaryIs(List<TemplateVariableNameAndValue> expectedResults)

View File

@ -1,4 +1,4 @@
{ {
"version": "1.0.0-*", "version": "1.0.0-*",
"testRunner": "xunit", "testRunner": "xunit",
@ -22,7 +22,8 @@
"Ocelot.Library": "1.0.0-*", "Ocelot.Library": "1.0.0-*",
"xunit": "2.1.0", "xunit": "2.1.0",
"dotnet-test-xunit": "2.2.0-preview2-build1029", "dotnet-test-xunit": "2.2.0-preview2-build1029",
"Shouldly": "2.8.0" "Shouldly": "2.8.0",
"TestStack.BDDfy": "4.3.1"
}, },
"frameworks": { "frameworks": {