some tidying up and a bit of refactoring...not too happy about how the proxy is working at the moment! May need a rethink!

This commit is contained in:
TomPallister
2016-09-11 21:32:56 +01:00
parent 87702141e2
commit 72cec38c0e
16 changed files with 151 additions and 60 deletions

View File

@ -20,16 +20,19 @@ namespace Ocelot.AcceptanceTests
private TestServer _server;
private HttpClient _client;
private HttpResponseMessage _response;
private readonly string _configurationPath;
public OcelotTests()
{
_configurationPath = "./bin/Debug/netcoreapp1.0/configuration.yaml";
_fakeService = new FakeService();
}
[Fact]
public void should_return_response_404()
{
this.Given(x => x.GivenTheApiGatewayIsRunning())
this.Given(x => x.GivenThereIsAConfiguration(new Configuration()))
.And(x => x.GivenTheApiGatewayIsRunning())
.When(x => x.WhenIRequestTheUrlOnTheApiGateway("/"))
.Then(x => x.ThenTheStatusCodeShouldBe(HttpStatusCode.NotFound))
.BDDfy();
@ -72,12 +75,12 @@ namespace Ocelot.AcceptanceTests
{
var serializer = new Serializer();
if (File.Exists("./configuration.yaml"))
if (File.Exists(_configurationPath))
{
File.Delete("./configuration.yaml");
File.Delete(_configurationPath);
}
using (TextWriter writer = File.CreateText("./configuration.yaml"))
using (TextWriter writer = File.CreateText(_configurationPath))
{
serializer.Serialize(writer, configuration);
}

View File

@ -58,6 +58,7 @@ namespace Ocelot.UnitTests
}))
.When(x => x.WhenIValidateTheConfiguration())
.Then(x => x.ThenTheResultIsNotValid())
.And(x => x.ThenTheErrorIs<DownstreamTemplateAlreadyUsedError>())
.BDDfy();
}
@ -73,12 +74,17 @@ namespace Ocelot.UnitTests
private void ThenTheResultIsValid()
{
_result.IsError.ShouldBeFalse();
_result.Data.IsError.ShouldBeFalse();
}
private void ThenTheResultIsNotValid()
{
_result.IsError.ShouldBeTrue();
_result.Data.IsError.ShouldBeTrue();
}
private void ThenTheErrorIs<T>()
{
_result.Data.Errors[0].ShouldBeOfType<T>();
}
}
}

View File

@ -35,21 +35,21 @@ namespace Ocelot.UnitTests
[Fact]
public void should_return_route()
{
this.Given(x => x.GivenThereIsAnUpstreamUrlPath("somePath"))
this.Given(x => x.GivenThereIsAnUpstreamUrlPath("someUpstreamPath"))
.And(x => x.GivenTheConfigurationIs(new Configuration {
ReRoutes = new List<ReRoute>
{
new ReRoute()
{
UpstreamTemplate = "somePath",
DownstreamTemplate = "somPath"
UpstreamTemplate = "someUpstreamPath",
DownstreamTemplate = "someDownstreamPath"
}
}
}))
.And(x => x.GivenTheUrlMatcherReturns(new UrlMatch(true, new List<TemplateVariableNameAndValue>(), "somePath")))
.And(x => x.GivenTheUrlMatcherReturns(new UrlMatch(true, new List<TemplateVariableNameAndValue>(), "someDownstreamPath")))
.When(x => x.WhenICallTheFinder())
.Then(
x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List<TemplateVariableNameAndValue>(), "somePath")))
x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List<TemplateVariableNameAndValue>(), "someDownstreamPath")))
.And(x => x.ThenTheUrlMatcherIsCalledCorrectly())
.BDDfy();
}
@ -117,6 +117,7 @@ namespace Ocelot.UnitTests
private void ThenTheFollowingIsReturned(DownstreamRoute expected)
{
_result.Data.DownstreamUrlTemplate.ShouldBe(expected.DownstreamUrlTemplate);
for (int i = 0; i < _result.Data.TemplateVariableNameAndValues.Count; i++)
{
_result.Data.TemplateVariableNameAndValues[i].TemplateVariableName.ShouldBe(

View File

@ -131,7 +131,7 @@ namespace Ocelot.UnitTests
private void WhenIReplaceTheTemplateVariables()
{
_result = _downstreamUrlPathReplacer.ReplaceTemplateVariable(_downstreamRoute);
_result = _downstreamUrlPathReplacer.ReplaceTemplateVariables(_downstreamRoute);
}
private void ThenTheDownstreamUrlPathIsReturned(string expected)