public void should_return_correct_route_for_http_verb_setting_multiple_upstream_http_method()
        {
            var serviceProviderConfig = new ServiceProviderConfigurationBuilder().Build();

            this.Given(x => x.GivenThereIsAnUpstreamUrlPath("someUpstreamPath"))
            .And(
                x =>
                x.GivenTheTemplateVariableAndNameFinderReturns(
                    new OkResponse <List <PlaceholderNameAndValue> >(new List <PlaceholderNameAndValue>())))
            .And(x => x.GivenTheConfigurationIs(new List <ReRoute>
            {
                new ReRouteBuilder()
                .WithDownstreamReRoute(new DownstreamReRouteBuilder()
                                       .WithDownstreamPathTemplate("someDownstreamPath")
                                       .WithUpstreamPathTemplate("someUpstreamPath")
                                       .WithUpstreamHttpMethod(new List <string> {
                    "Get", "Post"
                })
                                       .WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1))
                                       .Build())
                .WithUpstreamPathTemplate("someUpstreamPath")
                .WithUpstreamHttpMethod(new List <string> {
                    "Get", "Post"
                })
                .WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1))
                .Build()
            }, string.Empty, serviceProviderConfig
                                                ))
            .And(x => x.GivenTheUrlMatcherReturns(new OkResponse <UrlMatch>(new UrlMatch(true))))
            .And(x => x.GivenTheUpstreamHttpMethodIs("Post"))
            .When(x => x.WhenICallTheFinder())
            .Then(
                x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List <PlaceholderNameAndValue>(),
                                                                      new ReRouteBuilder()
                                                                      .WithDownstreamReRoute(new DownstreamReRouteBuilder()
                                                                                             .WithDownstreamPathTemplate("someDownstreamPath")
                                                                                             .WithUpstreamHttpMethod(new List <string> {
                "Post"
            })
                                                                                             .WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1))
                                                                                             .Build())
                                                                      .WithUpstreamHttpMethod(new List <string> {
                "Post"
            })
                                                                      .WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1))
                                                                      .Build()
                                                                      )))
            .BDDfy();
        }
        public void should_return_consul_service_provider()
        {
            var reRoute = new ReRouteBuilder()
                          .WithServiceName("product")
                          .WithUseServiceDiscovery(true)
                          .Build();

            var serviceConfig = new ServiceProviderConfigurationBuilder()
                                .Build();

            this.Given(x => x.GivenTheReRoute(serviceConfig, reRoute))
            .When(x => x.WhenIGetTheServiceProvider())
            .Then(x => x.ThenTheServiceProviderIs <ConsulServiceDiscoveryProvider>())
            .BDDfy();
        }
示例#3
0
        public IOcelotBuilder AddStoreOcelotConfigurationInConsul()
        {
            var serviceDiscoveryPort = _configurationRoot.GetValue("GlobalConfiguration:ServiceDiscoveryProvider:Port", 0);
            var serviceDiscoveryHost = _configurationRoot.GetValue("GlobalConfiguration:ServiceDiscoveryProvider:Host", string.Empty);

            var config = new ServiceProviderConfigurationBuilder()
                         .WithServiceDiscoveryProviderPort(serviceDiscoveryPort)
                         .WithServiceDiscoveryProviderHost(serviceDiscoveryHost)
                         .Build();

            _services.AddSingleton <ServiceProviderConfiguration>(config);
            _services.AddSingleton <ConsulFileConfigurationPoller>();
            _services.AddSingleton <IFileConfigurationRepository, ConsulFileConfigurationRepository>();
            return(this);
        }
示例#4
0
        public void should_get()
        {
            var config   = new ServiceProviderConfigurationBuilder().WithType("eureka").Build();
            var client   = new Mock <IDiscoveryClient>();
            var services = new ServiceCollection();

            services.AddSingleton <IDiscoveryClient>(client.Object);
            var sp    = services.BuildServiceProvider();
            var route = new DownstreamRouteBuilder()
                        .WithServiceName("")
                        .Build();
            var provider = EurekaProviderFactory.Get(sp, config, route);

            provider.ShouldBeOfType <Eureka>();
        }
示例#5
0
        public void should_not_append_slash_to_upstream_url_path()
        {
            var serviceProviderConfig = new ServiceProviderConfigurationBuilder().Build();

            this.Given(x => x.GivenThereIsAnUpstreamUrlPath("matchInUrlMatcher"))
            .And(x => x.GivenTheTemplateVariableAndNameFinderReturns(
                     new OkResponse <List <PlaceholderNameAndValue> >(
                         new List <PlaceholderNameAndValue>())))
            .And(x => x.GivenTheConfigurationIs(new List <ReRoute>
            {
                new ReRouteBuilder()
                .WithDownstreamReRoute(new DownstreamReRouteBuilder()
                                       .WithDownstreamPathTemplate("someDownstreamPath")
                                       .WithUpstreamHttpMethod(new List <string> {
                    "Get"
                })
                                       .WithUpstreamPathTemplate(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
                                       .Build())
                .WithUpstreamHttpMethod(new List <string> {
                    "Get"
                })
                .WithUpstreamPathTemplate(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
                .Build()
            }, string.Empty, serviceProviderConfig
                                                ))
            .And(x => x.GivenTheUrlMatcherReturns(new OkResponse <UrlMatch>(new UrlMatch(true))))
            .And(x => x.GivenTheUpstreamHttpMethodIs("Get"))
            .When(x => x.WhenICallTheFinder())
            .Then(
                x => x.ThenTheFollowingIsReturned(new DownstreamRoute(
                                                      new List <PlaceholderNameAndValue>(),
                                                      new ReRouteBuilder()
                                                      .WithDownstreamReRoute(new DownstreamReRouteBuilder()
                                                                             .WithDownstreamPathTemplate("someDownstreamPath")
                                                                             .WithUpstreamHttpMethod(new List <string> {
                "Get"
            })
                                                                             .WithUpstreamPathTemplate(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
                                                                             .Build())
                                                      .WithUpstreamHttpMethod(new List <string> {
                "Get"
            })
                                                      .WithUpstreamPathTemplate(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
                                                      .Build()
                                                      )))
            .And(x => x.ThenTheUrlMatcherIsCalledCorrectly("matchInUrlMatcher"))
            .BDDfy();
        }
示例#6
0
        public void should_call_delegate()
        {
            var reRoute = new DownstreamReRouteBuilder()
                          .WithServiceName("product")
                          .WithUseServiceDiscovery(true)
                          .Build();

            var serviceConfig = new ServiceProviderConfigurationBuilder()
                                .Build();

            this.Given(x => x.GivenTheReRoute(serviceConfig, reRoute))
            .And(x => GivenAFakeDelegate())
            .When(x => x.WhenIGetTheServiceProvider())
            .Then(x => x.ThenTheDelegateIsCalled())
            .BDDfy();
        }
示例#7
0
        public void should_return_service_fabric_provider()
        {
            var reRoute = new DownstreamReRouteBuilder()
                          .WithServiceName("product")
                          .WithUseServiceDiscovery(true)
                          .Build();

            var serviceConfig = new ServiceProviderConfigurationBuilder()
                                .WithType("ServiceFabric")
                                .Build();

            this.Given(x => x.GivenTheReRoute(serviceConfig, reRoute))
            .When(x => x.WhenIGetTheServiceProvider())
            .Then(x => x.ThenTheServiceProviderIs <ServiceFabricServiceDiscoveryProvider>())
            .BDDfy();
        }
        public void should_return_route_when_host_matches_but_null_host_on_same_path_first()
        {
            var serviceProviderConfig = new ServiceProviderConfigurationBuilder().Build();

            this.Given(x => x.GivenThereIsAnUpstreamUrlPath("matchInUrlMatcher/"))
            .And(x => GivenTheUpstreamHostIs("MATCH"))
            .And(x => x.GivenTheTemplateVariableAndNameFinderReturns(
                     new OkResponse <List <PlaceholderNameAndValue> >(
                         new List <PlaceholderNameAndValue>())))
            .And(x => x.GivenTheConfigurationIs(new List <ReRoute>
            {
                new ReRouteBuilder()
                .WithDownstreamPathTemplate("THENULLPATH")
                .WithUpstreamPathTemplate("someUpstreamPath")
                .WithUpstreamHttpMethod(new List <string> {
                    "Get"
                })
                .WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1))
                .Build(),
                new ReRouteBuilder()
                .WithDownstreamPathTemplate("someDownstreamPath")
                .WithUpstreamPathTemplate("someUpstreamPath")
                .WithUpstreamHttpMethod(new List <string> {
                    "Get"
                })
                .WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1))
                .WithUpstreamHost("MATCH")
                .Build()
            }, string.Empty, serviceProviderConfig
                                                ))
            .And(x => x.GivenTheUrlMatcherReturns(new OkResponse <UrlMatch>(new UrlMatch(true))))
            .And(x => x.GivenTheUpstreamHttpMethodIs("Get"))
            .When(x => x.WhenICallTheFinder())
            .Then(
                x => x.ThenTheFollowingIsReturned(new DownstreamRoute(
                                                      new List <PlaceholderNameAndValue>(),
                                                      new ReRouteBuilder()
                                                      .WithDownstreamPathTemplate("someDownstreamPath")
                                                      .WithUpstreamHttpMethod(new List <string> {
                "Get"
            })
                                                      .WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1))
                                                      .Build()
                                                      )))
            .And(x => x.ThenTheUrlMatcherIsCalledCorrectly(2))
            .BDDfy();
        }
        public void should_return_polling_consul_service_provider()
        {
            var reRoute = new DownstreamReRouteBuilder()
                          .WithServiceName("product")
                          .WithUseServiceDiscovery(true)
                          .Build();

            var serviceConfig = new ServiceProviderConfigurationBuilder()
                                .WithType("PollConsul")
                                .WithPollingInterval(100000)
                                .Build();

            this.Given(x => x.GivenTheReRoute(serviceConfig, reRoute))
            .When(x => x.WhenIGetTheServiceProvider())
            .Then(x => x.ThenTheServiceProviderIs <PollingConsulServiceDiscoveryProvider>())
            .BDDfy();
        }
示例#10
0
        public void should_return_provider_because_type_matches_reflected_type_from_delegate()
        {
            var route = new DownstreamRouteBuilder()
                        .WithServiceName("product")
                        .WithUseServiceDiscovery(true)
                        .Build();

            var serviceConfig = new ServiceProviderConfigurationBuilder()
                                .WithType(nameof(Fake))
                                .Build();

            this.Given(x => x.GivenTheRoute(serviceConfig, route))
            .And(x => GivenAFakeDelegate())
            .When(x => x.WhenIGetTheServiceProvider())
            .Then(x => x.ThenTheDelegateIsCalled())
            .BDDfy();
        }
        public void should_build()
        {
            var serviceProviderConfig = new ServiceProviderConfigurationBuilder().WithType("eureka").Build();
            var client     = new Mock <IDiscoveryClient>();
            var configRepo = new Mock <IInternalConfigurationRepository>();

            configRepo.Setup(x => x.Get())
            .Returns(new OkResponse <IInternalConfiguration>(new InternalConfiguration(null, null, serviceProviderConfig, null, null, null, null, null, null)));
            var services = new ServiceCollection();

            services.AddSingleton <IInternalConfigurationRepository>(configRepo.Object);
            services.AddSingleton <IDiscoveryClient>(client.Object);
            var sp       = services.BuildServiceProvider();
            var provider = EurekaMiddlewareConfigurationProvider.Get(new ApplicationBuilder(sp));

            provider.ShouldBeOfType <Task>();
        }
        public void should_not_return_provider_because_type_doesnt_match_reflected_type_from_delegate()
        {
            var reRoute = new DownstreamReRouteBuilder()
                          .WithServiceName("product")
                          .WithUseServiceDiscovery(true)
                          .Build();

            var serviceConfig = new ServiceProviderConfigurationBuilder()
                                .WithType("Wookie")
                                .Build();

            this.Given(x => x.GivenTheReRoute(serviceConfig, reRoute))
            .And(x => GivenAFakeDelegate())
            .When(x => x.WhenIGetTheServiceProvider())
            .Then(x => x.ThenTheResultIsError())
            .BDDfy();
        }
示例#13
0
        public void should_not_return_route_when_host_doesnt_match()
        {
            var serviceProviderConfig = new ServiceProviderConfigurationBuilder().Build();

            this.Given(x => x.GivenThereIsAnUpstreamUrlPath("matchInUrlMatcher/"))
            .And(x => GivenTheUpstreamHostIs("DONTMATCH"))
            .And(x => x.GivenTheTemplateVariableAndNameFinderReturns(new OkResponse <List <PlaceholderNameAndValue> >(new List <PlaceholderNameAndValue>())))
            .And(x => x.GivenTheConfigurationIs(new List <ReRoute>
            {
                new ReRouteBuilder()
                .WithDownstreamReRoute(new DownstreamReRouteBuilder()
                                       .WithDownstreamPathTemplate("someDownstreamPath")
                                       .WithUpstreamHttpMethod(new List <string> {
                    "Get"
                })
                                       .WithUpstreamPathTemplate(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
                                       .Build())
                .WithUpstreamHttpMethod(new List <string> {
                    "Get"
                })
                .WithUpstreamPathTemplate(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
                .WithUpstreamHost("MATCH")
                .Build(),
                new ReRouteBuilder()
                .WithDownstreamReRoute(new DownstreamReRouteBuilder()
                                       .WithDownstreamPathTemplate("someDownstreamPath")
                                       .WithUpstreamHttpMethod(new List <string> {
                })                                                            // empty list of methods
                                       .WithUpstreamPathTemplate(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
                                       .Build())
                .WithUpstreamHttpMethod(new List <string> {
                })                                                        // empty list of methods
                .WithUpstreamPathTemplate(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
                .WithUpstreamHost("MATCH")
                .Build()
            }, string.Empty, serviceProviderConfig
                                                ))
            .And(x => x.GivenTheUrlMatcherReturns(new OkResponse <UrlMatch>(new UrlMatch(true))))
            .And(x => x.GivenTheUpstreamHttpMethodIs("Get"))
            .When(x => x.WhenICallTheFinder())
            .Then(x => x.ThenAnErrorResponseIsReturned())
            .And(x => x.ThenTheUrlMatcherIsNotCalled())
            .BDDfy();
        }
示例#14
0
        public void should_set_pipeline_error_if_cannot_get_load_balancer()
        {
            var downstreamRoute = new DownstreamReRouteBuilder()
                                  .WithUpstreamHttpMethod(new List <string> {
                "Get"
            })
                                  .Build();

            var serviceProviderConfig = new ServiceProviderConfigurationBuilder()
                                        .Build();

            this.Given(x => x.GivenTheDownStreamUrlIs("http://my.url/abc?q=123"))
            .And(x => GivenTheConfigurationIs(serviceProviderConfig))
            .And(x => x.GivenTheDownStreamRouteIs(downstreamRoute, new List <Ocelot.DownstreamRouteFinder.UrlMatcher.PlaceholderNameAndValue>()))
            .And(x => x.GivenTheLoadBalancerHouseReturnsAnError())
            .When(x => x.WhenICallTheMiddleware())
            .Then(x => x.ThenAnErrorStatingLoadBalancerCouldNotBeFoundIsSetOnPipeline())
            .BDDfy();
        }
        public void should_return_list_of_configuration_services()
        {
            var serviceConfig = new ServiceProviderConfigurationBuilder()
                                .Build();

            var downstreamAddresses = new List <DownstreamHostAndPort>()
            {
                new DownstreamHostAndPort("asdf.com", 80),
                new DownstreamHostAndPort("abc.com", 80)
            };

            var reRoute = new ReRouteBuilder().WithDownstreamAddresses(downstreamAddresses).Build();

            this.Given(x => x.GivenTheReRoute(serviceConfig, reRoute))
            .When(x => x.WhenIGetTheServiceProvider())
            .Then(x => x.ThenTheServiceProviderIs <ConfigurationServiceProvider>())
            .Then(x => ThenTheFollowingServicesAreReturned(downstreamAddresses))
            .BDDfy();
        }
示例#16
0
        public void should_call_scoped_data_repository_correctly()
        {
            var downstreamRoute = new DownstreamReRouteBuilder()
                                  .WithUpstreamHttpMethod(new List <string> {
                "Get"
            })
                                  .Build();

            var serviceProviderConfig = new ServiceProviderConfigurationBuilder()
                                        .Build();

            this.Given(x => x.GivenTheDownStreamUrlIs("http://my.url/abc?q=123"))
            .And(x => GivenTheConfigurationIs(serviceProviderConfig))
            .And(x => x.GivenTheDownStreamRouteIs(downstreamRoute, new List <Ocelot.DownstreamRouteFinder.UrlMatcher.PlaceholderNameAndValue>()))
            .And(x => x.GivenTheLoadBalancerHouseReturns())
            .And(x => x.GivenTheLoadBalancerReturns())
            .When(x => x.WhenICallTheMiddleware())
            .Then(x => x.ThenTheDownstreamUrlIsReplacedWith("http://127.0.0.1:80/abc?q=123"))
            .BDDfy();
        }
        public void should_set_scheme()
        {
            var downstreamRoute = new DownstreamRouteBuilder()
                                  .WithUpstreamHttpMethod(new List <string> {
                "Get"
            })
                                  .Build();

            var serviceProviderConfig = new ServiceProviderConfigurationBuilder()
                                        .Build();

            this.Given(x => x.GivenTheDownStreamUrlIs("http://my.url/abc?q=123"))
            .And(x => GivenTheConfigurationIs(serviceProviderConfig))
            .And(x => x.GivenTheDownStreamRouteIs(downstreamRoute, new List <Ocelot.DownstreamRouteFinder.UrlMatcher.PlaceholderNameAndValue>()))
            .And(x => x.GivenTheLoadBalancerHouseReturns())
            .And(x => x.GivenTheLoadBalancerReturnsOk())
            .When(x => x.WhenICallTheMiddleware())
            .Then(x => x.ThenAnHostAndPortIsSetOnPipeline())
            .BDDfy();
        }
        public void should_call_service_provider_config_creator()
        {
            var serviceProviderConfig = new ServiceProviderConfigurationBuilder().Build();

            this.Given(x => x.GivenTheConfigIs(new FileConfiguration
            {
                GlobalConfiguration = new FileGlobalConfiguration
                {
                    ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
                    {
                        Host = "localhost",
                        Port = 8500,
                    }
                }
            }))
            .And(x => x.GivenTheFollowingIsReturned(serviceProviderConfig))
            .And(x => x.GivenTheConfigIsValid())
            .When(x => x.WhenICreateTheConfig())
            .Then(x => x.ThenTheServiceProviderCreatorIsCalledCorrectly())
            .BDDfy();
        }
        public void should_not_return_route()
        {            
            var serviceProviderConfig = new ServiceProviderConfigurationBuilder().Build();

            this.Given(x => x.GivenThereIsAnUpstreamUrlPath("dontMatchPath/"))
                 .And(x => x.GivenTheConfigurationIs(new List<ReRoute>
                     {
                        new ReRouteBuilder()
                        .WithDownstreamPathTemplate("somPath")
                        .WithUpstreamPathTemplate("somePath")
                        .WithUpstreamHttpMethod(new List<string> { "Get" })
                        .WithUpstreamTemplatePattern("somePath")
                        .Build(),   
                     }, string.Empty, serviceProviderConfig
                 ))
                 .And(x => x.GivenTheUrlMatcherReturns(new OkResponse<UrlMatch>(new UrlMatch(false))))
                 .And(x => x.GivenTheUpstreamHttpMethodIs("Get"))
                 .When(x => x.WhenICallTheFinder())
                 .Then(
                     x => x.ThenAnErrorResponseIsReturned())
                 .And(x => x.ThenTheUrlMatcherIsCalledCorrectly())
                 .BDDfy();
        }
        public void should_return_route_if_upstream_path_and_upstream_template_are_the_same()
        {
            var serviceProviderConfig = new ServiceProviderConfigurationBuilder().Build();

            this.Given(x => x.GivenThereIsAnUpstreamUrlPath("someUpstreamPath"))
            .And(
                x =>
                x.GivenTheTemplateVariableAndNameFinderReturns(
                    new OkResponse <List <PlaceholderNameAndValue> >(new List <PlaceholderNameAndValue>())))
            .And(x => x.GivenTheConfigurationIs(new List <ReRoute>
            {
                new ReRouteBuilder()
                .WithDownstreamPathTemplate("someDownstreamPath")
                .WithUpstreamPathTemplate("someUpstreamPath")
                .WithUpstreamHttpMethod(new List <string> {
                    "Get"
                })
                .WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1))
                .Build()
            }, string.Empty, serviceProviderConfig
                                                ))
            .And(x => x.GivenTheUrlMatcherReturns(new OkResponse <UrlMatch>(new UrlMatch(true))))
            .And(x => x.GivenTheUpstreamHttpMethodIs("Get"))
            .When(x => x.WhenICallTheFinder())
            .Then(
                x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List <PlaceholderNameAndValue>(),
                                                                      new ReRouteBuilder()
                                                                      .WithDownstreamPathTemplate("someDownstreamPath")
                                                                      .WithUpstreamHttpMethod(new List <string> {
                "Get"
            })
                                                                      .WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1))
                                                                      .Build()
                                                                      )))
            .And(x => x.ThenTheUrlMatcherIsNotCalled())
            .BDDfy();
        }
示例#21
0
        public void should_create_service_provider_config()
        {
            var reRoute = new FileReRoute();

            var globalConfig = new FileGlobalConfiguration
            {
                ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
                {
                    Host = "127.0.0.1",
                    Port = 1234
                }
            };

            var expected = new ServiceProviderConfigurationBuilder()
                           .WithServiceDiscoveryProviderHost("127.0.0.1")
                           .WithServiceDiscoveryProviderPort(1234)
                           .Build();

            this.Given(x => x.GivenTheFollowingReRoute(reRoute))
            .And(x => x.GivenTheFollowingGlobalConfig(globalConfig))
            .When(x => x.WhenICreate())
            .Then(x => x.ThenTheConfigIs(expected))
            .BDDfy();
        }
        public void should_set_up_aggregate_re_route()
        {
            var configuration = new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        DownstreamPathTemplate = "/",
                        DownstreamScheme       = "http",
                        DownstreamHostAndPorts = new List <FileHostAndPort>
                        {
                            new FileHostAndPort
                            {
                                Host = "localhost",
                                Port = 51878,
                            }
                        },
                        UpstreamPathTemplate = "/laura",
                        UpstreamHttpMethod   = new List <string> {
                            "Get"
                        },
                        Key          = "Laura",
                        UpstreamHost = "localhost"
                    },
                    new FileReRoute
                    {
                        DownstreamPathTemplate = "/",
                        DownstreamScheme       = "http",
                        DownstreamHostAndPorts = new List <FileHostAndPort>
                        {
                            new FileHostAndPort
                            {
                                Host = "localhost",
                                Port = 51880,
                            }
                        },
                        UpstreamPathTemplate = "/tom",
                        UpstreamHttpMethod   = new List <string> {
                            "Get"
                        },
                        Key          = "Tom",
                        UpstreamHost = "localhost",
                    }
                },
                Aggregates = new List <FileAggregateReRoute>
                {
                    new FileAggregateReRoute
                    {
                        UpstreamPathTemplate = "/",
                        UpstreamHost         = "localhost",
                        ReRouteKeys          = new List <string>
                        {
                            "Tom",
                            "Laura"
                        },
                        Aggregator = "asdf"
                    }
                }
            };

            var serviceProviderConfig = new ServiceProviderConfigurationBuilder().Build();

            var expected = new List <ReRoute>();

            var lauraDownstreamReRoute = new DownstreamReRouteBuilder()
                                         .WithUpstreamHost("localhost")
                                         .WithKey("Laura")
                                         .WithDownstreamPathTemplate("/")
                                         .WithDownstreamScheme("http")
                                         .WithUpstreamHttpMethod(new List <string>()
            {
                "Get"
            })
                                         .WithDownstreamAddresses(new List <DownstreamHostAndPort>()
            {
                new DownstreamHostAndPort("localhost", 51878)
            })
                                         .WithLoadBalancerKey("/laura|Get")
                                         .Build();

            var lauraReRoute = new ReRouteBuilder()
                               .WithUpstreamHttpMethod(new List <string>()
            {
                "Get"
            })
                               .WithUpstreamHost("localhost")
                               .WithUpstreamPathTemplate("/laura")
                               .WithDownstreamReRoute(lauraDownstreamReRoute)
                               .Build();

            expected.Add(lauraReRoute);

            var tomDownstreamReRoute = new DownstreamReRouteBuilder()
                                       .WithUpstreamHost("localhost")
                                       .WithKey("Tom")
                                       .WithDownstreamPathTemplate("/")
                                       .WithDownstreamScheme("http")
                                       .WithUpstreamHttpMethod(new List <string>()
            {
                "Get"
            })
                                       .WithDownstreamAddresses(new List <DownstreamHostAndPort>()
            {
                new DownstreamHostAndPort("localhost", 51878)
            })
                                       .WithLoadBalancerKey("/tom|Get")
                                       .Build();

            var tomReRoute = new ReRouteBuilder()
                             .WithUpstreamHttpMethod(new List <string>()
            {
                "Get"
            })
                             .WithUpstreamHost("localhost")
                             .WithUpstreamPathTemplate("/tom")
                             .WithDownstreamReRoute(tomDownstreamReRoute)
                             .Build();

            expected.Add(tomReRoute);

            var aggregateReReRoute = new ReRouteBuilder()
                                     .WithUpstreamPathTemplate("/")
                                     .WithUpstreamHost("localhost")
                                     .WithDownstreamReRoute(lauraDownstreamReRoute)
                                     .WithDownstreamReRoute(tomDownstreamReRoute)
                                     .WithUpstreamHttpMethod(new List <string>()
            {
                "Get"
            })
                                     .Build();

            expected.Add(aggregateReReRoute);

            this.Given(x => x.GivenTheConfigIs(configuration))
            .And(x => x.GivenTheFollowingOptionsAreReturned(new ReRouteOptionsBuilder().Build()))
            .And(x => x.GivenTheFollowingIsReturned(serviceProviderConfig))
            .And(x => GivenTheDownstreamAddresses())
            .And(x => GivenTheHeaderFindAndReplaceCreatorReturns())
            .And(x => x.GivenTheConfigIsValid())
            .When(x => x.WhenICreateTheConfig())
            .Then(x => x.ThenTheServiceProviderCreatorIsCalledCorrectly())
            .Then(x => x.ThenTheReRoutesAre(expected))
            .BDDfy();
        }