From e969e9ff0b999a700df9110b8a25d6b2f4ba1cf4 Mon Sep 17 00:00:00 2001 From: TomPallister Date: Tue, 18 Feb 2020 20:45:28 +0000 Subject: [PATCH] unit tests passing --- .../Builder/DownstreamReRouteBuilder.cs | 2 +- .../Configuration/Creator/ReRoutesCreator.cs | 2 +- .../Configuration/VersionCreatorTests.cs | 36 ++++++++++++++----- .../Request/Mapper/RequestMapperTests.cs | 20 ++++++++++- 4 files changed, 49 insertions(+), 11 deletions(-) diff --git a/src/Ocelot/Configuration/Builder/DownstreamReRouteBuilder.cs b/src/Ocelot/Configuration/Builder/DownstreamReRouteBuilder.cs index 09f5c59a..71049795 100644 --- a/src/Ocelot/Configuration/Builder/DownstreamReRouteBuilder.cs +++ b/src/Ocelot/Configuration/Builder/DownstreamReRouteBuilder.cs @@ -257,7 +257,7 @@ namespace Ocelot.Configuration.Builder return this; } - public DownstreamReRouteBuilder WithHttpVersion(Version downstreamHttpVersion) + public DownstreamReRouteBuilder WithDownstreamHttpVersion(Version downstreamHttpVersion) { _downstreamHttpVersion = downstreamHttpVersion; return this; diff --git a/src/Ocelot/Configuration/Creator/ReRoutesCreator.cs b/src/Ocelot/Configuration/Creator/ReRoutesCreator.cs index ad896ac9..e307b6d3 100644 --- a/src/Ocelot/Configuration/Creator/ReRoutesCreator.cs +++ b/src/Ocelot/Configuration/Creator/ReRoutesCreator.cs @@ -143,7 +143,7 @@ namespace Ocelot.Configuration.Creator .WithAddHeadersToUpstream(hAndRs.AddHeadersToUpstream) .WithDangerousAcceptAnyServerCertificateValidator(fileReRoute.DangerousAcceptAnyServerCertificateValidator) .WithSecurityOptions(securityOptions) - .WithHttpVersion(downstreamHttpVersion) + .WithDownstreamHttpVersion(downstreamHttpVersion) .WithDownStreamHttpMethod(fileReRoute.DownstreamHttpMethod) .Build(); diff --git a/test/Ocelot.UnitTests/Configuration/VersionCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/VersionCreatorTests.cs index 346f62e7..f5119ec8 100644 --- a/test/Ocelot.UnitTests/Configuration/VersionCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/VersionCreatorTests.cs @@ -1,12 +1,16 @@ namespace Ocelot.UnitTests.Configuration { + using System; using Ocelot.Configuration.Creator; using Shouldly; + using TestStack.BDDfy; using Xunit; public class VersionCreatorTests { private readonly VersionCreator _creator; + private string _input; + private Version _result; public VersionCreatorTests() { @@ -16,19 +20,35 @@ [Fact] public void should_create_version_based_on_input() { - var input = "2.0"; - var result = _creator.Create(input); - result.Major.ShouldBe(2); - result.Minor.ShouldBe(0); + this.Given(_ => GivenTheInput("2.0")) + .When(_ => WhenICreate()) + .Then(_ => ThenTheResultIs(2, 0)) + .BDDfy(); } [Fact] public void should_default_to_version_one_point_one() { - var input = ""; - var result = _creator.Create(input); - result.Major.ShouldBe(1); - result.Minor.ShouldBe(1); + this.Given(_ => GivenTheInput("")) + .When(_ => WhenICreate()) + .Then(_ => ThenTheResultIs(1, 1)) + .BDDfy(); + } + + private void GivenTheInput(string input) + { + _input = input; + } + + private void WhenICreate() + { + _result = _creator.Create(_input); + } + + private void ThenTheResultIs(int major, int minor) + { + _result.Major.ShouldBe(major); + _result.Minor.ShouldBe(minor); } } } diff --git a/test/Ocelot.UnitTests/Request/Mapper/RequestMapperTests.cs b/test/Ocelot.UnitTests/Request/Mapper/RequestMapperTests.cs index 77091fc6..501e290c 100644 --- a/test/Ocelot.UnitTests/Request/Mapper/RequestMapperTests.cs +++ b/test/Ocelot.UnitTests/Request/Mapper/RequestMapperTests.cs @@ -51,6 +51,7 @@ .And(_ => GivenTheInputRequestHasHost(host)) .And(_ => GivenTheInputRequestHasPath(path)) .And(_ => GivenTheInputRequestHasQueryString(queryString)) + .And(_ => GivenTheDownstreamReRoute()) .When(_ => WhenMapped()) .Then(_ => ThenNoErrorIsReturned()) .And(_ => ThenTheMappedRequestHasUri(expectedUri)) @@ -80,6 +81,7 @@ { this.Given(_ => GivenTheInputRequestHasMethod(method)) .And(_ => GivenTheInputRequestHasAValidUri()) + .And(_ => GivenTheDownstreamReRoute()) .When(_ => WhenMapped()) .Then(_ => ThenNoErrorIsReturned()) .And(_ => ThenTheMappedRequestHasMethod(method)) @@ -107,6 +109,7 @@ this.Given(_ => GivenTheInputRequestHasHeaders()) .And(_ => GivenTheInputRequestHasMethod("GET")) .And(_ => GivenTheInputRequestHasAValidUri()) + .And(_ => GivenTheDownstreamReRoute()) .When(_ => WhenMapped()) .Then(_ => ThenNoErrorIsReturned()) .And(_ => ThenTheMappedRequestHasEachHeader()) @@ -119,6 +122,7 @@ this.Given(_ => GivenTheInputRequestHasNoHeaders()) .And(_ => GivenTheInputRequestHasMethod("GET")) .And(_ => GivenTheInputRequestHasAValidUri()) + .And(_ => GivenTheDownstreamReRoute()) .When(_ => WhenMapped()) .Then(_ => ThenNoErrorIsReturned()) .And(_ => ThenTheMappedRequestHasNoHeaders()) @@ -131,6 +135,7 @@ this.Given(_ => GivenTheInputRequestHasContent("This is my content")) .And(_ => GivenTheInputRequestHasMethod("GET")) .And(_ => GivenTheInputRequestHasAValidUri()) + .And(_ => GivenTheDownstreamReRoute()) .When(_ => WhenMapped()) .Then(_ => ThenNoErrorIsReturned()) .And(_ => ThenTheMappedRequestHasContent("This is my content")) @@ -143,6 +148,7 @@ this.Given(_ => GivenTheInputRequestHasNullContent()) .And(_ => GivenTheInputRequestHasMethod("GET")) .And(_ => GivenTheInputRequestHasAValidUri()) + .And(_ => GivenTheDownstreamReRoute()) .When(_ => WhenMapped()) .Then(_ => ThenNoErrorIsReturned()) .And(_ => ThenTheMappedRequestHasNoContent()) @@ -155,6 +161,7 @@ this.Given(_ => GivenTheInputRequestHasNoContentType()) .And(_ => GivenTheInputRequestHasMethod("GET")) .And(_ => GivenTheInputRequestHasAValidUri()) + .And(_ => GivenTheDownstreamReRoute()) .When(_ => WhenMapped()) .Then(_ => ThenNoErrorIsReturned()) .And(_ => ThenTheMappedRequestHasNoContent()) @@ -167,6 +174,7 @@ this.Given(_ => GivenTheInputRequestHasNoContentLength()) .And(_ => GivenTheInputRequestHasMethod("GET")) .And(_ => GivenTheInputRequestHasAValidUri()) + .And(_ => GivenTheDownstreamReRoute()) .When(_ => WhenMapped()) .Then(_ => ThenNoErrorIsReturned()) .And(_ => ThenTheMappedRequestHasNoContent()) @@ -192,6 +200,7 @@ .And(_ => GivenTheContentMD5Is(md5bytes)) .And(_ => GivenTheInputRequestHasMethod("GET")) .And(_ => GivenTheInputRequestHasAValidUri()) + .And(_ => GivenTheDownstreamReRoute()) .When(_ => WhenMapped()) .Then(_ => ThenNoErrorIsReturned()) .And(_ => ThenTheMappedRequestHasContentTypeHeader("application/json")) @@ -213,6 +222,7 @@ .And(_ => GivenTheContentTypeIs("application/json")) .And(_ => GivenTheInputRequestHasMethod("POST")) .And(_ => GivenTheInputRequestHasAValidUri()) + .And(_ => GivenTheDownstreamReRoute()) .When(_ => WhenMapped()) .Then(_ => ThenNoErrorIsReturned()) .And(_ => ThenTheMappedRequestHasContentTypeHeader("application/json")) @@ -223,7 +233,15 @@ private void GivenTheDownstreamReRouteMethodIs(string input) { - _downstreamReRoute = new DownstreamReRouteBuilder().WithDownStreamHttpMethod(input).Build(); + _downstreamReRoute = new DownstreamReRouteBuilder() + .WithDownStreamHttpMethod(input) + .WithDownstreamHttpVersion(new Version("1.1")).Build(); + } + + private void GivenTheDownstreamReRoute() + { + _downstreamReRoute = new DownstreamReRouteBuilder() + .WithDownstreamHttpVersion(new Version("1.1")).Build(); } private void GivenTheInputRequestHasNoContentLength()