simplifying stuff after i realised i added loads of crap i dont need

This commit is contained in:
Tom Gardham-Pallister
2016-08-27 14:13:45 +01:00
parent 267ad5e98b
commit c4e0bae4ce
36 changed files with 302 additions and 668 deletions

View File

@ -11,14 +11,14 @@ namespace Ocelot.AcceptanceTests
using System.Net;
using TestStack.BDDfy;
public class RouterTests : IDisposable
public class OcelotTests : IDisposable
{
private readonly FakeService _fakeService;
private readonly TestServer _server;
private readonly HttpClient _client;
private HttpResponseMessage _response;
public RouterTests()
public OcelotTests()
{
_server = new TestServer(new WebHostBuilder()
.UseStartup<Startup>());
@ -36,6 +36,15 @@ namespace Ocelot.AcceptanceTests
.BDDfy();
}
[Fact]
public void should_return_response_200()
{
this.When(x => x.WhenIRequestTheUrl("/"))
.Then(x => x.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
.And(x => x.ThenTheResponseBodyShouldBe("Hello from Laura"))
.BDDfy();
}
private void WhenIRequestTheUrl(string url)
{
_response = _client.GetAsync("/").Result;
@ -46,6 +55,11 @@ namespace Ocelot.AcceptanceTests
_response.StatusCode.ShouldBe(expectedHttpStatusCode);
}
private void ThenTheResponseBodyShouldBe(string expectedBody)
{
_response.Content.ReadAsStringAsync().Result.ShouldBe(expectedBody);
}
public void Dispose()
{
_fakeService.Stop();

View File

@ -1,117 +0,0 @@
using Ocelot.Library.Infrastructure.Responses;
using Ocelot.Library.Infrastructure.HostUrlRepository;
using Shouldly;
using Xunit;
namespace Ocelot.UnitTests
{
using TestStack.BDDfy;
public class HostUrlMapRepositoryTests
{
private string _upstreamBaseUrl;
private string _downstreamBaseUrl;
private readonly IHostUrlMapRepository _repository;
private Response _response;
private Response<HostUrlMap> _getRouteResponse;
public HostUrlMapRepositoryTests()
{
_repository = new InMemoryHostUrlMapRepository();
}
[Fact]
public void can_add_route()
{
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()
{
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()
{
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()
{
this.Given(x => x.GivenIWantToRouteRequestsFromMyDownstreamBaseUrl("api"))
.When(x => x.WhenIRetrieveTheRouteByKey())
.Then(x => x.ThenTheKeyDoesNotExist())
.BDDfy();
}
private void WhenITryToUseTheSameKey()
{
WhenIAddTheConfiguration();
}
private void ThenTheKeyHasAlreadyBeenUsed()
{
_response.ShouldNotBeNull();
_response.ShouldBeOfType<ErrorResponse>();
_response.Errors[0].Message.ShouldBe("This key has already been used");
}
private void ThenTheKeyDoesNotExist()
{
_getRouteResponse.ShouldNotBeNull();
_getRouteResponse.ShouldBeOfType<ErrorResponse<HostUrlMap>>();
_getRouteResponse.Errors[0].Message.ShouldBe("This key does not exist");
}
private void WhenIRetrieveTheRouteByKey()
{
_getRouteResponse = _repository.GetBaseUrlMap(_downstreamBaseUrl);
}
private void ThenTheRouteIsReturned()
{
_getRouteResponse.Data.UrlPathTemplate.ShouldBe(_downstreamBaseUrl);
_getRouteResponse.Data.UpstreamHostUrl.ShouldBe(_upstreamBaseUrl);
}
private void GivenIHaveSetUpAnApiKeyAndUpstreamUrl(string apiKey, string upstreamUrl)
{
GivenIHaveAnUpstreamBaseUrl(upstreamUrl);
GivenIWantToRouteRequestsFromMyDownstreamBaseUrl(apiKey);
WhenIAddTheConfiguration();
}
private void GivenIHaveAnUpstreamBaseUrl(string upstreamApiUrl)
{
_upstreamBaseUrl = upstreamApiUrl;
}
private void GivenIWantToRouteRequestsFromMyDownstreamBaseUrl(string downstreamBaseUrl)
{
_downstreamBaseUrl = downstreamBaseUrl;
}
private void WhenIAddTheConfiguration()
{
_response = _repository.AddBaseUrlMap(new HostUrlMap(_downstreamBaseUrl, _upstreamBaseUrl));
}
private void ThenTheResponseIsSuccesful()
{
_response.ShouldBeOfType<OkResponse>();
}
}
}

View File

@ -1,68 +0,0 @@
using Ocelot.Library.Infrastructure.HostUrlRepository;
using Ocelot.Library.Infrastructure.UrlFinder;
using Ocelot.Library.Infrastructure.Responses;
using Xunit;
using Shouldly;
using TestStack.BDDfy;
namespace Ocelot.UnitTests
{
public class UpstreamBaseUrlFinderTests
{
private readonly IUpstreamHostUrlFinder _upstreamBaseUrlFinder;
private readonly IHostUrlMapRepository _hostUrlMapRepository;
private string _downstreamBaseUrl;
private Response<string> _result;
public UpstreamBaseUrlFinderTests()
{
_hostUrlMapRepository = new InMemoryHostUrlMapRepository();
_upstreamBaseUrlFinder = new UpstreamHostUrlFinder(_hostUrlMapRepository);
}
[Fact]
public void can_find_base_url()
{
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()
{
this.Given(x => x.GivenTheDownstreamBaseUrlIs("api.tom.com"))
.When(x => x.WhenIFindTheMatchingUpstreamBaseUrl())
.Then(x => x.ThenAnErrorIsReturned())
.BDDfy();
}
private void ThenAnErrorIsReturned()
{
_result.Errors.Count.ShouldBe(1);
}
private void GivenTheBaseUrlMapExists(HostUrlMap baseUrlMap)
{
_hostUrlMapRepository.AddBaseUrlMap(baseUrlMap);
}
private void GivenTheDownstreamBaseUrlIs(string downstreamBaseUrl)
{
_downstreamBaseUrl = downstreamBaseUrl;
}
private void WhenIFindTheMatchingUpstreamBaseUrl()
{
_result = _upstreamBaseUrlFinder.FindUpstreamHostUrl(_downstreamBaseUrl);
}
private void ThenTheFollowingIsReturned(string expectedBaseUrl)
{
_result.Data.ShouldBe(expectedBaseUrl);
}
}
}

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
using Ocelot.Library.Infrastructure.UrlPathMatcher;
using Ocelot.Library.Infrastructure.UrlPathReplacer;
using Ocelot.Library.Infrastructure.UrlMatcher;
using Ocelot.Library.Infrastructure.UrlTemplateReplacer;
using Shouldly;
using Xunit;
@ -10,53 +10,53 @@ namespace Ocelot.UnitTests
public class UpstreamUrlPathTemplateVariableReplacerTests
{
private string _upstreamUrlPath;
private UrlPathMatch _urlPathMatch;
private string _downstreamUrlTemplate;
private UrlMatch _urlMatch;
private string _result;
private readonly IUpstreamUrlPathTemplateVariableReplacer _upstreamUrlPathReplacer;
private readonly IDownstreamUrlTemplateVariableReplacer _downstreamUrlPathReplacer;
public UpstreamUrlPathTemplateVariableReplacerTests()
{
_upstreamUrlPathReplacer = new UpstreamUrlPathTemplateVariableReplacer();
_downstreamUrlPathReplacer = new DownstreamUrlTemplateVariableReplacer();
}
[Fact]
public void can_replace_no_template_variables()
{
this.Given(x => x.GivenThereIsAnUpstreamUrlPath(""))
.And(x => x.GivenThereIsAUrlPathMatch(new UrlPathMatch(true, new List<TemplateVariableNameAndValue>(), "")))
this.Given(x => x.GivenThereIsADownstreamUrl(""))
.And(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, new List<TemplateVariableNameAndValue>(), "")))
.When(x => x.WhenIReplaceTheTemplateVariables())
.Then(x => x.ThenTheUpstreamUrlPathIsReturned(""))
.Then(x => x.ThenTheDownstreamUrlPathIsReturned(""))
.BDDfy();
}
[Fact]
public void can_replace_url_no_slash()
{
this.Given(x => x.GivenThereIsAnUpstreamUrlPath("api"))
.And(x => x.GivenThereIsAUrlPathMatch(new UrlPathMatch(true, new List<TemplateVariableNameAndValue>(), "api")))
this.Given(x => x.GivenThereIsADownstreamUrl("api"))
.And(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, new List<TemplateVariableNameAndValue>(), "api")))
.When(x => x.WhenIReplaceTheTemplateVariables())
.Then(x => x.ThenTheUpstreamUrlPathIsReturned("api"))
.Then(x => x.ThenTheDownstreamUrlPathIsReturned("api"))
.BDDfy();
}
[Fact]
public void can_replace_url_one_slash()
{
this.Given(x => x.GivenThereIsAnUpstreamUrlPath("api/"))
.And(x => x.GivenThereIsAUrlPathMatch(new UrlPathMatch(true, new List<TemplateVariableNameAndValue>(), "api/")))
this.Given(x => x.GivenThereIsADownstreamUrl("api/"))
.And(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, new List<TemplateVariableNameAndValue>(), "api/")))
.When(x => x.WhenIReplaceTheTemplateVariables())
.Then(x => x.ThenTheUpstreamUrlPathIsReturned("api/"))
.Then(x => x.ThenTheDownstreamUrlPathIsReturned("api/"))
.BDDfy();
}
[Fact]
public void can_replace_url_multiple_slash()
{
this.Given(x => x.GivenThereIsAnUpstreamUrlPath("api/product/products/"))
.And(x => x.GivenThereIsAUrlPathMatch(new UrlPathMatch(true, new List<TemplateVariableNameAndValue>(), "api/product/products/")))
this.Given(x => x.GivenThereIsADownstreamUrl("api/product/products/"))
.And(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, new List<TemplateVariableNameAndValue>(), "api/product/products/")))
.When(x => x.WhenIReplaceTheTemplateVariables())
.Then(x => x.ThenTheUpstreamUrlPathIsReturned("api/product/products/"))
.Then(x => x.ThenTheDownstreamUrlPathIsReturned("api/product/products/"))
.BDDfy();
}
@ -68,10 +68,10 @@ namespace Ocelot.UnitTests
new TemplateVariableNameAndValue("{productId}", "1")
};
this.Given(x => x.GivenThereIsAnUpstreamUrlPath("productservice/products/{productId}/"))
.And(x => x.GivenThereIsAUrlPathMatch(new UrlPathMatch(true, templateVariables, "api/products/{productId}/")))
this.Given(x => x.GivenThereIsADownstreamUrl("productservice/products/{productId}/"))
.And(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, templateVariables, "api/products/{productId}/")))
.When(x => x.WhenIReplaceTheTemplateVariables())
.Then(x => x.ThenTheUpstreamUrlPathIsReturned("productservice/products/1/"))
.Then(x => x.ThenTheDownstreamUrlPathIsReturned("productservice/products/1/"))
.BDDfy();
}
@ -83,10 +83,10 @@ namespace Ocelot.UnitTests
new TemplateVariableNameAndValue("{productId}", "1")
};
this.Given(x => x.GivenThereIsAnUpstreamUrlPath("productservice/products/{productId}/variants"))
.And(x => x.GivenThereIsAUrlPathMatch(new UrlPathMatch(true, templateVariables, "api/products/{productId}/")))
this.Given(x => x.GivenThereIsADownstreamUrl("productservice/products/{productId}/variants"))
.And(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, templateVariables, "api/products/{productId}/")))
.When(x => x.WhenIReplaceTheTemplateVariables())
.Then(x => x.ThenTheUpstreamUrlPathIsReturned("productservice/products/1/variants"))
.Then(x => x.ThenTheDownstreamUrlPathIsReturned("productservice/products/1/variants"))
.BDDfy();
}
@ -99,10 +99,10 @@ namespace Ocelot.UnitTests
new TemplateVariableNameAndValue("{variantId}", "12")
};
this.Given(x => x.GivenThereIsAnUpstreamUrlPath("productservice/products/{productId}/variants/{variantId}"))
.And(x => x.GivenThereIsAUrlPathMatch(new UrlPathMatch(true, templateVariables, "api/products/{productId}/{variantId}")))
this.Given(x => x.GivenThereIsADownstreamUrl("productservice/products/{productId}/variants/{variantId}"))
.And(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, templateVariables, "api/products/{productId}/{variantId}")))
.When(x => x.WhenIReplaceTheTemplateVariables())
.Then(x => x.ThenTheUpstreamUrlPathIsReturned("productservice/products/1/variants/12"))
.Then(x => x.ThenTheDownstreamUrlPathIsReturned("productservice/products/1/variants/12"))
.BDDfy();
}
@ -116,29 +116,29 @@ namespace Ocelot.UnitTests
new TemplateVariableNameAndValue("{categoryId}", "34")
};
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}")))
this.Given(x => x.GivenThereIsADownstreamUrl("productservice/category/{categoryId}/products/{productId}/variants/{variantId}"))
.And(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, templateVariables, "api/products/{categoryId}/{productId}/{variantId}")))
.When(x => x.WhenIReplaceTheTemplateVariables())
.Then(x => x.ThenTheUpstreamUrlPathIsReturned("productservice/category/34/products/1/variants/12"))
.Then(x => x.ThenTheDownstreamUrlPathIsReturned("productservice/category/34/products/1/variants/12"))
.BDDfy();
}
private void GivenThereIsAnUpstreamUrlPath(string upstreamUrlPath)
private void GivenThereIsADownstreamUrl(string downstreamUrlTemplate)
{
_upstreamUrlPath = upstreamUrlPath;
_downstreamUrlTemplate = downstreamUrlTemplate;
}
private void GivenThereIsAUrlPathMatch(UrlPathMatch urlPathMatch)
private void GivenThereIsAUrlMatch(UrlMatch urlMatch)
{
_urlPathMatch = urlPathMatch;
_urlMatch = urlMatch;
}
private void WhenIReplaceTheTemplateVariables()
{
_result = _upstreamUrlPathReplacer.ReplaceTemplateVariable(_upstreamUrlPath, _urlPathMatch);
_result = _downstreamUrlPathReplacer.ReplaceTemplateVariable(_downstreamUrlTemplate, _urlMatch);
}
private void ThenTheUpstreamUrlPathIsReturned(string expected)
private void ThenTheDownstreamUrlPathIsReturned(string expected)
{
_result.ShouldBe(expected);
}

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
using Ocelot.Library.Infrastructure.Responses;
using Ocelot.Library.Infrastructure.UrlPathTemplateRepository;
using Ocelot.Library.Infrastructure.UrlTemplateRepository;
using Shouldly;
using Xunit;
@ -10,41 +10,31 @@ namespace Ocelot.UnitTests
public class UrlPathTemplateMapRepositoryTests
{
private string _upstreamUrlPath;
private string _downstreamUrlPath;
private IUrlPathTemplateMapRepository _repository;
private string _upstreamUrlPathTemplate;
private string _downstreamUrlTemplate;
private IUrlTemplateMapRepository _repository;
private Response _response;
private Response<UrlPathTemplateMap> _getResponse;
private Response<List<UrlPathTemplateMap>> _listResponse;
private Response<List<UrlTemplateMap>> _listResponse;
public UrlPathTemplateMapRepositoryTests()
{
_repository = new InMemoryUrlPathTemplateMapRepository();
_repository = new InMemoryUrlTemplateMapRepository();
}
[Fact]
public void can_add_url_path()
{
this.Given(x => x.GivenIHaveAnUpstreamUrlPath("/api/products/products/{productId}"))
.And(x => x.GivenIWantToRouteRequestsToMyUpstreamUrlPath("/api/products/{productId}"))
this.Given(x => x.GivenIHaveAnUpstreamUrlPathTemplate("/api/products/products/{productId}"))
.And(x => x.GivenADownstreamUrlTemplate("/api/products/{productId}"))
.When(x => x.WhenIAddTheConfiguration())
.Then(x => x.ThenTheResponseIsSuccesful())
.BDDfy();
}
[Fact]
public void can_get_url_path()
{
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()
{
this.Given(x => x.GivenIHaveSetUpADownstreamUrlPathAndAnUpstreamUrlPath("/api2", "http://www.someapi.com/api2"))
this.Given(x => x.GivenIHaveSetUpADownstreamUrlTemplateAndAnUpstreamUrlPathTemplate("/api2", "http://www.someapi.com/api2"))
.When(x => x.WhenIRetrieveTheUrls())
.Then(x => x.ThenTheUrlsAreReturned())
.BDDfy();
@ -53,21 +43,12 @@ namespace Ocelot.UnitTests
[Fact]
public void should_return_error_response_when_url_path_already_used()
{
this.Given(x => x.GivenIHaveSetUpADownstreamUrlPathAndAnUpstreamUrlPath("/api2", "http://www.someapi.com/api2"))
this.Given(x => x.GivenIHaveSetUpADownstreamUrlTemplateAndAnUpstreamUrlPathTemplate("/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()
{
this.Given(x => x.GivenIWantToRouteRequestsToMyUpstreamUrlPath("/api"))
.When(x => x.WhenIRetrieveTheUrlPathByDownstreamUrl())
.Then(x => x.ThenTheKeyDoesNotExist())
.BDDfy();
}
private void WhenITryToUseTheSameDownstreamUrl()
{
WhenIAddTheConfiguration();
@ -80,54 +61,36 @@ namespace Ocelot.UnitTests
_response.Errors[0].Message.ShouldBe("This key has already been used");
}
private void ThenTheKeyDoesNotExist()
{
_getResponse.ShouldNotBeNull();
_getResponse.ShouldBeOfType<ErrorResponse<UrlPathTemplateMap>>();
_getResponse.Errors[0].Message.ShouldBe("This key does not exist");
}
private void WhenIRetrieveTheUrlPathByDownstreamUrl()
{
_getResponse = _repository.GetUrlPathTemplateMap(_downstreamUrlPath);
}
private void WhenIRetrieveTheUrls()
private void WhenIRetrieveTheUrls()
{
_listResponse = _repository.All;
}
private void ThenTheUrlPathIsReturned()
{
_getResponse.Data.DownstreamUrlPathTemplate.ShouldBe(_downstreamUrlPath);
_getResponse.Data.UpstreamUrlPathTemplate.ShouldBe(_upstreamUrlPath);
}
private void ThenTheUrlsAreReturned()
{
_listResponse.Data.Count.ShouldBeGreaterThan(0);
}
private void GivenIHaveSetUpADownstreamUrlPathAndAnUpstreamUrlPath(string downstream, string upstreamApiUrl)
private void GivenIHaveSetUpADownstreamUrlTemplateAndAnUpstreamUrlPathTemplate(string downstreamUrlTemplate, string upstreamUrlPathTemplate)
{
GivenIHaveAnUpstreamUrlPath(upstreamApiUrl);
GivenIWantToRouteRequestsToMyUpstreamUrlPath(downstream);
GivenIHaveAnUpstreamUrlPathTemplate(upstreamUrlPathTemplate);
GivenADownstreamUrlTemplate(downstreamUrlTemplate);
WhenIAddTheConfiguration();
}
private void GivenIHaveAnUpstreamUrlPath(string upstreamApiUrl)
private void GivenIHaveAnUpstreamUrlPathTemplate(string upstreamUrlPathTemplate)
{
_upstreamUrlPath = upstreamApiUrl;
_upstreamUrlPathTemplate = upstreamUrlPathTemplate;
}
private void GivenIWantToRouteRequestsToMyUpstreamUrlPath(string apiKey)
private void GivenADownstreamUrlTemplate(string downstreamUrlTemplate)
{
_downstreamUrlPath = apiKey;
_downstreamUrlTemplate = downstreamUrlTemplate;
}
private void WhenIAddTheConfiguration()
{
_response = _repository.AddUrlPathTemplateMap(new UrlPathTemplateMap(_downstreamUrlPath, _upstreamUrlPath));
_response = _repository.AddUrlTemplateMap(new UrlTemplateMap(_downstreamUrlTemplate, _upstreamUrlPathTemplate));
}
private void ThenTheResponseIsSuccesful()

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using Ocelot.Library.Infrastructure.UrlPathMatcher;
using Ocelot.Library.Infrastructure.UrlMatcher;
using Shouldly;
using Xunit;
@ -8,26 +8,26 @@ namespace Ocelot.UnitTests
{
using TestStack.BDDfy;
public class UrlPathToUrlPathTemplateMatcherTests
public class UrlPathToUrlTemplateMatcherTests
{
private readonly IUrlPathToUrlPathTemplateMatcher _urlMapper;
private string _downstreamPath;
private readonly IUrlPathToUrlTemplateMatcher _urlMatcher;
private string _downstreamUrlPath;
private string _downstreamPathTemplate;
private UrlPathMatch _result;
public UrlPathToUrlPathTemplateMatcherTests()
private UrlMatch _result;
public UrlPathToUrlTemplateMatcherTests()
{
_urlMapper = new UrlPathToUrlPathTemplateMatcher();
_urlMatcher = new UrlPathToUrlTemplateMatcher();
}
[Fact]
public void can_match_down_stream_url()
{
this.Given(x => x.GivenIHaveADownstreamPath(""))
.And(x => x.GivenIHaveAnDownstreamPathTemplate(""))
.And(x => x.GivenIHaveAnDownstreamUrlTemplate(""))
.When(x => x.WhenIMatchThePaths())
.And(x => x.ThenTheResultIsTrue())
.And(x => x.ThenTheTemplatesDictionaryIs(new List<TemplateVariableNameAndValue>()))
.And(x => x.ThenTheUrlPathTemplateIs(""))
.And(x => x.ThenTheTemplatesVariablesAre(new List<TemplateVariableNameAndValue>()))
.And(x => x.ThenTheDownstreamUrlTemplateIs(""))
.BDDfy();
}
@ -35,23 +35,23 @@ namespace Ocelot.UnitTests
public void can_match_down_stream_url_with_no_slash()
{
this.Given(x => x.GivenIHaveADownstreamPath("api"))
.Given(x => x.GivenIHaveAnDownstreamPathTemplate("api"))
.Given(x => x.GivenIHaveAnDownstreamUrlTemplate("api"))
.When(x => x.WhenIMatchThePaths())
.Then(x => x.ThenTheResultIsTrue())
.And(x => x.ThenTheTemplatesDictionaryIs(new List<TemplateVariableNameAndValue>()))
.And(x => x.ThenTheUrlPathTemplateIs("api"))
.And(x => x.ThenTheTemplatesVariablesAre(new List<TemplateVariableNameAndValue>()))
.And(x => x.ThenTheDownstreamUrlTemplateIs("api"))
.BDDfy();
}
[Fact]
[Fact]
public void can_match_down_stream_url_with_one_slash()
{
this.Given(x => x.GivenIHaveADownstreamPath("api/"))
.Given(x => x.GivenIHaveAnDownstreamPathTemplate("api/"))
.Given(x => x.GivenIHaveAnDownstreamUrlTemplate("api/"))
.When(x => x.WhenIMatchThePaths())
.Then(x => x.ThenTheResultIsTrue())
.And(x => x.ThenTheTemplatesDictionaryIs(new List<TemplateVariableNameAndValue>()))
.And(x => x.ThenTheUrlPathTemplateIs("api/"))
.And(x => x.ThenTheTemplatesVariablesAre(new List<TemplateVariableNameAndValue>()))
.And(x => x.ThenTheDownstreamUrlTemplateIs("api/"))
.BDDfy();
}
@ -59,11 +59,11 @@ namespace Ocelot.UnitTests
public void can_match_down_stream_url_with_downstream_template()
{
this.Given(x => x.GivenIHaveADownstreamPath("api/product/products/"))
.Given(x => x.GivenIHaveAnDownstreamPathTemplate("api/product/products/"))
.Given(x => x.GivenIHaveAnDownstreamUrlTemplate("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/"))
.And(x => x.ThenTheTemplatesVariablesAre(new List<TemplateVariableNameAndValue>()))
.And(x => x.ThenTheDownstreamUrlTemplateIs("api/product/products/"))
.BDDfy();
}
@ -71,11 +71,11 @@ namespace Ocelot.UnitTests
public void can_match_down_stream_url_with_downstream_template_with_one_query_string_parameter()
{
this.Given(x => x.GivenIHaveADownstreamPath("api/product/products/?soldout=false"))
.Given(x => x.GivenIHaveAnDownstreamPathTemplate("api/product/products/"))
.Given(x => x.GivenIHaveAnDownstreamUrlTemplate("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/"))
.And(x => x.ThenTheTemplatesVariablesAre(new List<TemplateVariableNameAndValue>()))
.And(x => x.ThenTheDownstreamUrlTemplateIs("api/product/products/"))
.BDDfy();
}
@ -88,11 +88,11 @@ namespace Ocelot.UnitTests
};
this.Given(x => x.GivenIHaveADownstreamPath("api/product/products/1/variants/?soldout=false"))
.Given(x => x.GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/variants/"))
.Given(x => x.GivenIHaveAnDownstreamUrlTemplate("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/"))
.And(x => x.ThenTheTemplatesVariablesAre(expectedTemplates))
.And(x => x.ThenTheDownstreamUrlTemplateIs("api/product/products/{productId}/variants/"))
.BDDfy();
}
@ -105,11 +105,11 @@ namespace Ocelot.UnitTests
};
this.Given(x => x.GivenIHaveADownstreamPath("api/product/products/1"))
.Given(x => x.GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}"))
.Given(x => x.GivenIHaveAnDownstreamUrlTemplate("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}"))
.And(x => x.ThenTheTemplatesVariablesAre(expectedTemplates))
.And(x => x.ThenTheDownstreamUrlTemplateIs("api/product/products/{productId}"))
.BDDfy();
}
@ -123,11 +123,11 @@ namespace Ocelot.UnitTests
};
this.Given(x => x.GivenIHaveADownstreamPath("api/product/products/1/2"))
.Given(x => x.GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/{categoryId}"))
.Given(x => x.GivenIHaveAnDownstreamUrlTemplate("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}"))
.And(x => x.ThenTheTemplatesVariablesAre(expectedTemplates))
.And(x => x.ThenTheDownstreamUrlTemplateIs("api/product/products/{productId}/{categoryId}"))
.BDDfy();
}
@ -141,11 +141,11 @@ namespace Ocelot.UnitTests
};
this.Given(x => x.GivenIHaveADownstreamPath("api/product/products/1/categories/2"))
.And(x => x.GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/categories/{categoryId}"))
.And(x => x.GivenIHaveAnDownstreamUrlTemplate("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}"))
.And(x => x.ThenTheTemplatesVariablesAre(expectedTemplates))
.And(x => x.ThenTheDownstreamUrlTemplateIs("api/product/products/{productId}/categories/{categoryId}"))
.BDDfy();
}
@ -160,11 +160,11 @@ namespace Ocelot.UnitTests
};
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}"))
.And(x => x.GivenIHaveAnDownstreamUrlTemplate("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}"))
.And(x => x.ThenTheTemplatesVariablesAre(expectedTemplates))
.And(x => x.ThenTheDownstreamUrlTemplateIs("api/product/products/{productId}/categories/{categoryId}/variant/{variantId}"))
.BDDfy();
}
@ -178,15 +178,15 @@ namespace Ocelot.UnitTests
};
this.Given(x => x.GivenIHaveADownstreamPath("api/product/products/1/categories/2/variant/"))
.And(x => x.GivenIHaveAnDownstreamPathTemplate("api/product/products/{productId}/categories/{categoryId}/variant/"))
.And(x => x.GivenIHaveAnDownstreamUrlTemplate("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/"))
.And(x => x.ThenTheTemplatesVariablesAre(expectedTemplates))
.And(x => x.ThenTheDownstreamUrlTemplateIs("api/product/products/{productId}/categories/{categoryId}/variant/"))
.BDDfy();
}
private void ThenTheTemplatesDictionaryIs(List<TemplateVariableNameAndValue> expectedResults)
private void ThenTheTemplatesVariablesAre(List<TemplateVariableNameAndValue> expectedResults)
{
foreach (var expectedResult in expectedResults)
{
@ -196,23 +196,23 @@ namespace Ocelot.UnitTests
}
}
private void ThenTheUrlPathTemplateIs(string expectedUrlPathTemplate)
private void ThenTheDownstreamUrlTemplateIs(string expectedDownstreamUrlTemplate)
{
_result.DownstreamUrlPathTemplate.ShouldBe(expectedUrlPathTemplate);
_result.DownstreamUrlTemplate.ShouldBe(expectedDownstreamUrlTemplate);
}
private void GivenIHaveADownstreamPath(string downstreamPath)
{
_downstreamPath = downstreamPath;
_downstreamUrlPath = downstreamPath;
}
private void GivenIHaveAnDownstreamPathTemplate(string downstreamTemplate)
private void GivenIHaveAnDownstreamUrlTemplate(string downstreamUrlTemplate)
{
_downstreamPathTemplate = downstreamTemplate;
_downstreamPathTemplate = downstreamUrlTemplate;
}
private void WhenIMatchThePaths()
{
_result = _urlMapper.Match(_downstreamPath, _downstreamPathTemplate);
_result = _urlMatcher.Match(_downstreamUrlPath, _downstreamPathTemplate);
}
private void ThenTheResultIsTrue()