mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 20:10:50 +08:00 
			
		
		
		
	unit tests passing
This commit is contained in:
		@@ -257,7 +257,7 @@ namespace Ocelot.Configuration.Builder
 | 
			
		||||
            return this;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public DownstreamReRouteBuilder WithHttpVersion(Version downstreamHttpVersion)
 | 
			
		||||
        public DownstreamReRouteBuilder WithDownstreamHttpVersion(Version downstreamHttpVersion)
 | 
			
		||||
        {
 | 
			
		||||
            _downstreamHttpVersion = downstreamHttpVersion;
 | 
			
		||||
            return this;
 | 
			
		||||
 
 | 
			
		||||
@@ -143,7 +143,7 @@ namespace Ocelot.Configuration.Creator
 | 
			
		||||
                .WithAddHeadersToUpstream(hAndRs.AddHeadersToUpstream)
 | 
			
		||||
                .WithDangerousAcceptAnyServerCertificateValidator(fileReRoute.DangerousAcceptAnyServerCertificateValidator)
 | 
			
		||||
                .WithSecurityOptions(securityOptions)
 | 
			
		||||
                .WithHttpVersion(downstreamHttpVersion)
 | 
			
		||||
                .WithDownstreamHttpVersion(downstreamHttpVersion)
 | 
			
		||||
                .WithDownStreamHttpMethod(fileReRoute.DownstreamHttpMethod)
 | 
			
		||||
                .Build();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user