more simplification is that a word

This commit is contained in:
TomPallister
2016-09-07 20:40:56 +01:00
parent 15d7cafa1c
commit 71b7e7743e
18 changed files with 56 additions and 262 deletions

View File

@ -41,12 +41,12 @@ namespace Ocelot.AcceptanceTests
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879"))
.And(x => x.GivenThereIsAConfiguration(new Configuration
{
Routes = new List<Route>
ReRoutes = new List<ReRoute>
{
new Route
new ReRoute
{
Downstream = "http://localhost:51879/",
Upstream = "/heee"
DownstreamTemplate = "http://localhost:51879/",
UpstreamTemplate = "/"
}
}
}))

View File

@ -1,3 +1,3 @@
Routes:
- Downstream: http://localhost:51879/
Upstream: /heee
ReRoutes:
- DownstreamTemplate: http://localhost:51879/
UpstreamTemplate: /

View File

@ -10,7 +10,6 @@ namespace Ocelot.UnitTests
public class UpstreamUrlPathTemplateVariableReplacerTests
{
private string _downstreamUrlTemplate;
private UrlMatch _urlMatch;
private string _result;
private readonly IDownstreamUrlTemplateVariableReplacer _downstreamUrlPathReplacer;
@ -23,18 +22,25 @@ namespace Ocelot.UnitTests
[Fact]
public void can_replace_no_template_variables()
{
this.Given(x => x.GivenThereIsADownstreamUrl(""))
.And(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, new List<TemplateVariableNameAndValue>(), "")))
this.Given(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, new List<TemplateVariableNameAndValue>(), "")))
.When(x => x.WhenIReplaceTheTemplateVariables())
.Then(x => x.ThenTheDownstreamUrlPathIsReturned(""))
.BDDfy();
}
[Fact]
public void can_replace_no_template_variables_with_slash()
{
this.Given(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, new List<TemplateVariableNameAndValue>(), "/")))
.When(x => x.WhenIReplaceTheTemplateVariables())
.Then(x => x.ThenTheDownstreamUrlPathIsReturned("/"))
.BDDfy();
}
[Fact]
public void can_replace_url_no_slash()
{
this.Given(x => x.GivenThereIsADownstreamUrl("api"))
.And(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, new List<TemplateVariableNameAndValue>(), "api")))
this.Given(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, new List<TemplateVariableNameAndValue>(), "api")))
.When(x => x.WhenIReplaceTheTemplateVariables())
.Then(x => x.ThenTheDownstreamUrlPathIsReturned("api"))
.BDDfy();
@ -43,8 +49,7 @@ namespace Ocelot.UnitTests
[Fact]
public void can_replace_url_one_slash()
{
this.Given(x => x.GivenThereIsADownstreamUrl("api/"))
.And(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, new List<TemplateVariableNameAndValue>(), "api/")))
this.Given(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, new List<TemplateVariableNameAndValue>(), "api/")))
.When(x => x.WhenIReplaceTheTemplateVariables())
.Then(x => x.ThenTheDownstreamUrlPathIsReturned("api/"))
.BDDfy();
@ -53,8 +58,7 @@ namespace Ocelot.UnitTests
[Fact]
public void can_replace_url_multiple_slash()
{
this.Given(x => x.GivenThereIsADownstreamUrl("api/product/products/"))
.And(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, new List<TemplateVariableNameAndValue>(), "api/product/products/")))
this.Given(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, new List<TemplateVariableNameAndValue>(), "api/product/products/")))
.When(x => x.WhenIReplaceTheTemplateVariables())
.Then(x => x.ThenTheDownstreamUrlPathIsReturned("api/product/products/"))
.BDDfy();
@ -68,8 +72,7 @@ namespace Ocelot.UnitTests
new TemplateVariableNameAndValue("{productId}", "1")
};
this.Given(x => x.GivenThereIsADownstreamUrl("productservice/products/{productId}/"))
.And(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, templateVariables, "api/products/{productId}/")))
this.Given(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, templateVariables, "productservice/products/{productId}/")))
.When(x => x.WhenIReplaceTheTemplateVariables())
.Then(x => x.ThenTheDownstreamUrlPathIsReturned("productservice/products/1/"))
.BDDfy();
@ -83,8 +86,7 @@ namespace Ocelot.UnitTests
new TemplateVariableNameAndValue("{productId}", "1")
};
this.Given(x => x.GivenThereIsADownstreamUrl("productservice/products/{productId}/variants"))
.And(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, templateVariables, "api/products/{productId}/")))
this.Given(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, templateVariables, "productservice/products/{productId}/variants")))
.When(x => x.WhenIReplaceTheTemplateVariables())
.Then(x => x.ThenTheDownstreamUrlPathIsReturned("productservice/products/1/variants"))
.BDDfy();
@ -99,8 +101,7 @@ namespace Ocelot.UnitTests
new TemplateVariableNameAndValue("{variantId}", "12")
};
this.Given(x => x.GivenThereIsADownstreamUrl("productservice/products/{productId}/variants/{variantId}"))
.And(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, templateVariables, "api/products/{productId}/{variantId}")))
this.Given(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, templateVariables, "productservice/products/{productId}/variants/{variantId}")))
.When(x => x.WhenIReplaceTheTemplateVariables())
.Then(x => x.ThenTheDownstreamUrlPathIsReturned("productservice/products/1/variants/12"))
.BDDfy();
@ -116,18 +117,12 @@ namespace Ocelot.UnitTests
new TemplateVariableNameAndValue("{categoryId}", "34")
};
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}")))
this.Given(x => x.GivenThereIsAUrlMatch(new UrlMatch(true, templateVariables, "productservice/category/{categoryId}/products/{productId}/variants/{variantId}")))
.When(x => x.WhenIReplaceTheTemplateVariables())
.Then(x => x.ThenTheDownstreamUrlPathIsReturned("productservice/category/34/products/1/variants/12"))
.BDDfy();
}
private void GivenThereIsADownstreamUrl(string downstreamUrlTemplate)
{
_downstreamUrlTemplate = downstreamUrlTemplate;
}
private void GivenThereIsAUrlMatch(UrlMatch urlMatch)
{
_urlMatch = urlMatch;
@ -135,7 +130,7 @@ namespace Ocelot.UnitTests
private void WhenIReplaceTheTemplateVariables()
{
_result = _downstreamUrlPathReplacer.ReplaceTemplateVariable(_downstreamUrlTemplate, _urlMatch);
_result = _downstreamUrlPathReplacer.ReplaceTemplateVariable(_urlMatch);
}
private void ThenTheDownstreamUrlPathIsReturned(string expected)

View File

@ -1,101 +0,0 @@
using System.Collections.Generic;
using Ocelot.Library.Infrastructure.Responses;
using Ocelot.Library.Infrastructure.UrlTemplateRepository;
using Shouldly;
using Xunit;
namespace Ocelot.UnitTests
{
using TestStack.BDDfy;
public class UrlPathTemplateMapRepositoryTests
{
private string _upstreamUrlPathTemplate;
private string _downstreamUrlTemplate;
private IUrlTemplateMapRepository _repository;
private Response _response;
private Response<List<UrlTemplateMap>> _listResponse;
public UrlPathTemplateMapRepositoryTests()
{
_repository = new InMemoryUrlTemplateMapRepository();
}
[Fact]
public void can_add_url_path()
{
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_all_urls()
{
this.Given(x => x.GivenIHaveSetUpADownstreamUrlTemplateAndAnUpstreamUrlPathTemplate("/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()
{
this.Given(x => x.GivenIHaveSetUpADownstreamUrlTemplateAndAnUpstreamUrlPathTemplate("/api2", "http://www.someapi.com/api2"))
.When(x => x.WhenITryToUseTheSameDownstreamUrl())
.Then(x => x.ThenTheDownstreamUrlAlreadyBeenUsed())
.BDDfy();
}
private void WhenITryToUseTheSameDownstreamUrl()
{
WhenIAddTheConfiguration();
}
private void ThenTheDownstreamUrlAlreadyBeenUsed()
{
_response.ShouldNotBeNull();
_response.ShouldBeOfType<ErrorResponse>();
_response.Errors[0].Message.ShouldBe("This key has already been used");
}
private void WhenIRetrieveTheUrls()
{
_listResponse = _repository.All;
}
private void ThenTheUrlsAreReturned()
{
_listResponse.Data.Count.ShouldBeGreaterThan(0);
}
private void GivenIHaveSetUpADownstreamUrlTemplateAndAnUpstreamUrlPathTemplate(string downstreamUrlTemplate, string upstreamUrlPathTemplate)
{
GivenIHaveAnUpstreamUrlPathTemplate(upstreamUrlPathTemplate);
GivenADownstreamUrlTemplate(downstreamUrlTemplate);
WhenIAddTheConfiguration();
}
private void GivenIHaveAnUpstreamUrlPathTemplate(string upstreamUrlPathTemplate)
{
_upstreamUrlPathTemplate = upstreamUrlPathTemplate;
}
private void GivenADownstreamUrlTemplate(string downstreamUrlTemplate)
{
_downstreamUrlTemplate = downstreamUrlTemplate;
}
private void WhenIAddTheConfiguration()
{
_response = _repository.AddUrlTemplateMap(new UrlTemplateMap(_downstreamUrlTemplate, _upstreamUrlPathTemplate));
}
private void ThenTheResponseIsSuccesful()
{
_response.ShouldBeOfType<OkResponse>();
}
}
}