Ejemplo n.º 1
0
        public void should_follow_ordering_order_specifics_and_globals()
        {
            var qosOptions = new QoSOptionsBuilder()
                             .WithTimeoutValue(1)
                             .WithDurationOfBreak(1)
                             .WithExceptionsAllowedBeforeBreaking(1)
                             .Build();

            var route = new DownstreamRouteBuilder()
                        .WithQosOptions(qosOptions)
                        .WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true, true, int.MaxValue))
                        .WithDelegatingHandlers(new List <string>
            {
                "FakeDelegatingHandlerTwo",
                "FakeDelegatingHandler",
                "FakeDelegatingHandlerFour"
            })
                        .WithLoadBalancerKey("")
                        .Build();

            this.Given(x => GivenTheFollowingRequest(route))
            .And(x => GivenTheQosFactoryReturns(new FakeQoSHandler()))
            .And(x => GivenTheTracingFactoryReturns())
            .And(x => GivenTheServiceProviderReturnsGlobalDelegatingHandlers <FakeDelegatingHandlerFour, FakeDelegatingHandlerThree>())
            .And(x => GivenTheServiceProviderReturnsSpecificDelegatingHandlers <FakeDelegatingHandler, FakeDelegatingHandlerTwo>())
            .When(x => WhenIGet())
            .Then(x => ThenThereIsDelegatesInProvider(6))
            .And(x => ThenHandlerAtPositionIs <FakeDelegatingHandlerThree>(0)) //first because global not in config
            .And(x => ThenHandlerAtPositionIs <FakeDelegatingHandlerTwo>(1))   //first from config
            .And(x => ThenHandlerAtPositionIs <FakeDelegatingHandler>(2))      //second from config
            .And(x => ThenHandlerAtPositionIs <FakeDelegatingHandlerFour>(3))  //third from config (global)
            .And(x => ThenHandlerAtPositionIs <FakeTracingHandler>(4))
            .And(x => ThenHandlerAtPositionIs <FakeQoSHandler>(5))
            .BDDfy();
        }
Ejemplo n.º 2
0
        public void http_client_request_times_out()
        {
            var qosOptions = new QoSOptionsBuilder()
                             .Build();

            var reRoute = new DownstreamReRouteBuilder()
                          .WithQosOptions(qosOptions)
                          .WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false, true))
                          .WithLoadBalancerKey("")
                          .WithQosOptions(new QoSOptionsBuilder().WithTimeoutValue(1).Build())
                          .Build();

            var context = new DownstreamContext(new DefaultHttpContext())
            {
                DownstreamReRoute = reRoute,
                DownstreamRequest = new DownstreamRequest(new HttpRequestMessage()
                {
                    RequestUri = new Uri("http://localhost:60080")
                }),
            };

            this.Given(_ => GivenTheRequestIs(context))
            .And(_ => GivenTheHouseReturnsTimeoutHandler())
            .When(_ => WhenIGetResponse())
            .Then(_ => ThenTheResponseIsCalledError())
            .And(_ => ThenTheErrorIsTimeout())
            .BDDfy();
        }
Ejemplo n.º 3
0
        public void should_log_error_and_return_no_qos_provider_delegate_when_qos_factory_returns_null()
        {
            var qosOptions = new QoSOptionsBuilder()
                             .WithTimeoutValue(1)
                             .WithDurationOfBreak(1)
                             .WithExceptionsAllowedBeforeBreaking(1)
                             .Build();

            var route = new DownstreamRouteBuilder()
                        .WithQosOptions(qosOptions)
                        .WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true, true, int.MaxValue))
                        .WithLoadBalancerKey("")
                        .Build();

            this.Given(x => GivenTheFollowingRequest(route))
            .And(x => GivenTheQosFactoryReturnsNull())
            .And(x => GivenTheTracingFactoryReturns())
            .And(x => GivenTheServiceProviderReturnsGlobalDelegatingHandlers <FakeDelegatingHandler, FakeDelegatingHandlerTwo>())
            .And(x => GivenTheServiceProviderReturnsSpecificDelegatingHandlers <FakeDelegatingHandler, FakeDelegatingHandlerTwo>())
            .When(x => WhenIGet())
            .Then(x => ThenThereIsDelegatesInProvider(4))
            .And(x => ThenHandlerAtPositionIs <FakeDelegatingHandler>(0))
            .And(x => ThenHandlerAtPositionIs <FakeDelegatingHandlerTwo>(1))
            .And(x => ThenHandlerAtPositionIs <FakeTracingHandler>(2))
            .And(x => ThenHandlerAtPositionIs <NoQosDelegatingHandler>(3))
            .And(_ => ThenTheWarningIsLogged())
            .BDDfy();
        }
Ejemplo n.º 4
0
        public void should_store_qos_providers_by_key()
        {
            var qosOptions = new QoSOptionsBuilder()
                             .WithKey("test")
                             .Build();

            var qosOptionsTwo = new QoSOptionsBuilder()
                                .WithKey("testTwo")
                                .Build();

            var reRoute = new DownstreamReRouteBuilder()
                          .WithQosOptions(qosOptions)
                          .Build();

            var reRouteTwo = new DownstreamReRouteBuilder()
                             .WithQosOptions(qosOptionsTwo)
                             .Build();

            this.Given(x => x.GivenThereIsAQoSProvider(reRoute, new FakeQoSProvider()))
            .And(x => x.GivenThereIsAQoSProvider(reRouteTwo, new FakePollyQoSProvider()))
            .When(x => x.WhenWeGetTheQoSProvider(reRoute))
            .Then(x => x.ThenTheQoSProviderIs <FakeQoSProvider>())
            .When(x => x.WhenWeGetTheQoSProvider(reRouteTwo))
            .Then(x => x.ThenTheQoSProviderIs <FakePollyQoSProvider>())
            .BDDfy();
        }
Ejemplo n.º 5
0
        public void should_call_request_correctly()
        {
            var qosOptions = new QoSOptionsBuilder()
                             .Build();

            var reRoute = new DownstreamReRouteBuilder()
                          .WithQosOptions(qosOptions)
                          .WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false, true))
                          .WithLoadBalancerKey("")
                          .WithQosOptions(new QoSOptionsBuilder().Build())
                          .Build();

            var context = new DownstreamContext(new DefaultHttpContext())
            {
                DownstreamReRoute = reRoute,
                DownstreamRequest = new DownstreamRequest(new HttpRequestMessage()
                {
                    RequestUri = new Uri("http://www.bbc.co.uk")
                }),
            };

            this.Given(x => x.GivenTheRequestIs(context))
            .And(x => GivenTheHouseReturnsOkHandler())
            .When(x => x.WhenIGetResponse())
            .Then(x => x.ThenTheResponseIsCalledCorrectly())
            .BDDfy();
        }
Ejemplo n.º 6
0
        public void should_call_delegating_handlers_in_order()
        {
            var qosOptions = new QoSOptionsBuilder()
                             .Build();

            var reRoute = new DownstreamReRouteBuilder()
                          .WithQosOptions(qosOptions)
                          .WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false, true))
                          .WithLoadBalancerKey("")
                          .WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithOriginalValue("").Build())
                          .WithQosOptions(new QoSOptionsBuilder().Build())
                          .Build();

            var fakeOne = new FakeDelegatingHandler();
            var fakeTwo = new FakeDelegatingHandler();

            var handlers = new List <Func <DelegatingHandler> >()
            {
                () => fakeOne,
                () => fakeTwo
            };

            this.Given(x => GivenTheFactoryReturns(handlers))
            .And(x => GivenARequest(reRoute))
            .And(x => WhenIBuild())
            .When(x => WhenICallTheClient())
            .Then(x => ThenTheFakeAreHandledInOrder(fakeOne, fakeTwo))
            .And(x => ThenSomethingIsReturned())
            .BDDfy();
        }
Ejemplo n.º 7
0
        public void should_call_request_unable_to_complete_request()
        {
            var qosOptions = new QoSOptionsBuilder()
                             .Build();

            var reRoute = new DownstreamReRouteBuilder()
                          .WithQosOptions(qosOptions)
                          .WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false, true))
                          .WithLoadBalancerKey("")
                          .WithQosOptions(new QoSOptionsBuilder().Build())
                          .Build();

            var context = new DownstreamContext(new DefaultHttpContext())
            {
                DownstreamReRoute = reRoute,
                DownstreamRequest = new DownstreamRequest(new HttpRequestMessage()
                {
                    RequestUri = new Uri("http://localhost:60080")
                }),
            };

            this.Given(x => x.GivenTheRequestIs(context))
            .When(x => x.WhenIGetResponse())
            .Then(x => x.ThenTheResponseIsCalledError())
            .BDDfy();
        }
Ejemplo n.º 8
0
        public void should_follow_ordering_add_specifics()
        {
            var qosOptions = new QoSOptionsBuilder()
                             .WithTimeoutValue(1)
                             .WithDurationOfBreak(1)
                             .WithExceptionsAllowedBeforeBreaking(1)
                             .Build();

            var reRoute = new DownstreamReRouteBuilder()
                          .WithQosOptions(qosOptions)
                          .WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true, true))
                          .WithDelegatingHandlers(new List <string>
            {
                "FakeDelegatingHandler",
                "FakeDelegatingHandlerTwo"
            })
                          .WithLoadBalancerKey("")
                          .Build();

            this.Given(x => GivenTheFollowingRequest(reRoute))
            .And(x => GivenTheTracingFactoryReturns())
            .And(x => GivenTheQosProviderHouseReturns(new OkResponse <IQoSProvider>(It.IsAny <PollyQoSProvider>())))
            .And(x => GivenTheServiceProviderReturnsGlobalDelegatingHandlers <FakeDelegatingHandlerThree, FakeDelegatingHandlerFour>())
            .And(x => GivenTheServiceProviderReturnsSpecificDelegatingHandlers <FakeDelegatingHandler, FakeDelegatingHandlerTwo>())
            .When(x => WhenIGet())
            .Then(x => ThenThereIsDelegatesInProvider(6))
            .And(x => ThenHandlerAtPositionIs <FakeDelegatingHandlerThree>(0))
            .And(x => ThenHandlerAtPositionIs <FakeDelegatingHandlerFour>(1))
            .And(x => ThenHandlerAtPositionIs <FakeDelegatingHandler>(2))
            .And(x => ThenHandlerAtPositionIs <FakeDelegatingHandlerTwo>(3))
            .And(x => ThenHandlerAtPositionIs <FakeTracingHandler>(4))
            .And(x => ThenHandlerAtPositionIs <PollyCircuitBreakingDelegatingHandler>(5))
            .BDDfy();
        }
Ejemplo n.º 9
0
        public void should_re_use_cookies_from_container()
        {
            var qosOptions = new QoSOptionsBuilder()
                             .Build();

            var reRoute = new DownstreamReRouteBuilder()
                          .WithQosOptions(qosOptions)
                          .WithHttpHandlerOptions(new HttpHandlerOptions(false, true, false, true))
                          .WithLoadBalancerKey("")
                          .WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithOriginalValue("").Build())
                          .WithQosOptions(new QoSOptionsBuilder().Build())
                          .Build();

            this.Given(_ => GivenADownstreamService())
            .And(_ => GivenARequest(reRoute))
            .And(_ => GivenTheFactoryReturnsNothing())
            .And(_ => WhenIBuild())
            .And(_ => WhenICallTheClient("http://localhost:5003"))
            .And(_ => ThenTheCookieIsSet())
            .And(_ => GivenTheClientIsCached())
            .And(_ => WhenIBuild())
            .When(_ => WhenICallTheClient("http://localhost:5003"))
            .Then(_ => ThenTheResponseIsOk())
            .BDDfy();
        }
Ejemplo n.º 10
0
        public void should_get_from_cache_with_different_query_string()
        {
            var qosOptions = new QoSOptionsBuilder()
                             .Build();

            var reRoute = new DownstreamReRouteBuilder()
                          .WithQosOptions(qosOptions)
                          .WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false, true))
                          .WithLoadBalancerKey("")
                          .WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithOriginalValue("").Build())
                          .WithQosOptions(new QoSOptionsBuilder().Build())
                          .Build();

            this.Given(x => GivenARealCache())
            .And(x => GivenTheFactoryReturns())
            .And(x => GivenARequest(reRoute, "http://wwww.someawesomewebsite.com/woot?badman=1"))
            .And(x => WhenIBuildTheFirstTime())
            .And(x => WhenISave())
            .And(x => WhenIBuildAgain())
            .And(x => GivenARequest(reRoute, "http://wwww.someawesomewebsite.com/woot?badman=2"))
            .And(x => WhenISave())
            .When(x => WhenIBuildAgain())
            .Then(x => ThenTheHttpClientIsFromTheCache())
            .BDDfy();
        }
        public void http_client_request_times_out()
        {
            var upstreamTemplate = new UpstreamPathTemplateBuilder().WithOriginalValue("").Build();

            var qosOptions = new QoSOptionsBuilder()
                             .Build();

            var route = new DownstreamRouteBuilder()
                        .WithQosOptions(qosOptions)
                        .WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false, true, int.MaxValue))
                        .WithLoadBalancerKey("")
                        .WithUpstreamPathTemplate(upstreamTemplate)
                        .WithQosOptions(new QoSOptionsBuilder().WithTimeoutValue(1).Build())
                        .Build();

            var httpContext = new DefaultHttpContext();

            httpContext.Items.UpsertDownstreamRoute(route);
            httpContext.Items.UpsertDownstreamRequest(new DownstreamRequest(new HttpRequestMessage()
            {
                RequestUri = new Uri("http://localhost:60080")
            }));

            this.Given(_ => GivenTheRequestIs(httpContext))
            .And(_ => GivenTheHouseReturnsTimeoutHandler())
            .When(_ => WhenIGetResponse())
            .Then(_ => ThenTheResponseIsCalledError())
            .And(_ => ThenTheErrorIsTimeout())
            .BDDfy();
        }
        public void should_call_request_correctly()
        {
            var upstreamTemplate = new UpstreamPathTemplateBuilder().WithOriginalValue("").Build();

            var qosOptions = new QoSOptionsBuilder()
                             .Build();

            var route = new DownstreamRouteBuilder()
                        .WithQosOptions(qosOptions)
                        .WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false, true, int.MaxValue))
                        .WithLoadBalancerKey("")
                        .WithUpstreamPathTemplate(upstreamTemplate)
                        .WithQosOptions(new QoSOptionsBuilder().Build())
                        .Build();

            var httpContext = new DefaultHttpContext();

            httpContext.Items.UpsertDownstreamRoute(route);
            httpContext.Items.UpsertDownstreamRequest(new DownstreamRequest(new HttpRequestMessage()
            {
                RequestUri = new Uri("http://www.bbc.co.uk")
            }));

            this.Given(x => x.GivenTheRequestIs(httpContext))
            .And(x => GivenTheHouseReturnsOkHandler())
            .When(x => x.WhenIGetResponse())
            .Then(x => x.ThenTheResponseIsCalledCorrectly())
            .BDDfy();
        }
Ejemplo n.º 13
0
        public void should_build()
        {
            var loggerFactory = new Mock <IOcelotLoggerFactory>();
            var services      = new ServiceCollection();
            var options       = new QoSOptionsBuilder()
                                .WithTimeoutValue(100)
                                .WithExceptionsAllowedBeforeBreaking(1)
                                .WithDurationOfBreak(200)
                                .Build();
            var reRoute = new DownstreamReRouteBuilder().WithQosOptions(options)
                          .Build();

            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .Build();

            services
            .AddOcelot(configuration)
            .AddPolly();
            var provider = services.BuildServiceProvider();

            var handler = provider.GetService <QosDelegatingHandlerDelegate>();

            handler.ShouldNotBeNull();

            var delgatingHandler = handler(reRoute, loggerFactory.Object);

            delgatingHandler.ShouldNotBeNull();
        }
Ejemplo n.º 14
0
        public void should_follow_ordering_dont_add_specifics()
        {
            var qosOptions = new QoSOptionsBuilder()
                             .WithTimeoutValue(1)
                             .WithDurationOfBreak(1)
                             .WithExceptionsAllowedBeforeBreaking(1)
                             .Build();

            var route = new DownstreamRouteBuilder()
                        .WithQosOptions(qosOptions)
                        .WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true, true, int.MaxValue))
                        .WithLoadBalancerKey("")
                        .Build();

            this.Given(x => GivenTheFollowingRequest(route))
            .And(x => GivenTheQosFactoryReturns(new FakeQoSHandler()))
            .And(x => GivenTheTracingFactoryReturns())
            .And(x => GivenTheServiceProviderReturnsGlobalDelegatingHandlers <FakeDelegatingHandler, FakeDelegatingHandlerTwo>())
            .And(x => GivenTheServiceProviderReturnsSpecificDelegatingHandlers <FakeDelegatingHandler, FakeDelegatingHandlerTwo>())
            .When(x => WhenIGet())
            .Then(x => ThenThereIsDelegatesInProvider(4))
            .And(x => ThenHandlerAtPositionIs <FakeDelegatingHandler>(0))
            .And(x => ThenHandlerAtPositionIs <FakeDelegatingHandlerTwo>(1))
            .And(x => ThenHandlerAtPositionIs <FakeTracingHandler>(2))
            .And(x => ThenHandlerAtPositionIs <FakeQoSHandler>(3))
            .BDDfy();
        }
        public void should_call_request_unable_to_complete_request()
        {
            var upstreamTemplate = new UpstreamPathTemplateBuilder().WithOriginalValue("").Build();

            var qosOptions = new QoSOptionsBuilder()
                             .Build();

            var route = new DownstreamRouteBuilder()
                        .WithQosOptions(qosOptions)
                        .WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false, true, int.MaxValue))
                        .WithLoadBalancerKey("")
                        .WithUpstreamPathTemplate(upstreamTemplate)
                        .WithQosOptions(new QoSOptionsBuilder().Build())
                        .Build();

            var httpContext = new DefaultHttpContext();

            httpContext.Items.UpsertDownstreamRoute(route);
            httpContext.Items.UpsertDownstreamRequest(new DownstreamRequest(new HttpRequestMessage()
            {
                RequestUri = new Uri("http://localhost:60080")
            }));

            this.Given(x => x.GivenTheRequestIs(httpContext))
            .When(x => x.WhenIGetResponse())
            .Then(x => x.ThenTheResponseIsCalledError())
            .BDDfy();
        }
Ejemplo n.º 16
0
        public void should_get_new_qos_provider_if_reroute_qos_provider_has_changed()
        {
            var useQoSOptions = new QoSOptionsBuilder()
                                .WithTimeoutValue(1)
                                .WithKey("test")
                                .WithDurationOfBreak(1)
                                .WithExceptionsAllowedBeforeBreaking(1)
                                .Build();

            var dontUseQoSOptions = new QoSOptionsBuilder()
                                    .WithKey("test")
                                    .Build();

            var reRoute = new DownstreamReRouteBuilder()
                          .WithQosOptions(dontUseQoSOptions)
                          .Build();

            var reRouteTwo = new DownstreamReRouteBuilder()
                             .WithQosOptions(useQoSOptions)
                             .Build();

            this.Given(x => x.GivenThereIsAQoSProvider(reRoute, new FakeQoSProvider()))
            .When(x => x.WhenWeGetTheQoSProvider(reRoute))
            .Then(x => x.ThenTheQoSProviderIs <FakeQoSProvider>())
            .When(x => x.WhenIGetTheReRouteWithTheSameKeyButDifferentQosProvider(reRouteTwo))
            .Then(x => x.ThenTheQoSProviderIs <FakePollyQoSProvider>())
            .BDDfy();
        }
Ejemplo n.º 17
0
        public void should_return_error_if_no_qos_provider_with_key()
        {
            var qosOptions = new QoSOptionsBuilder()
                             .Build();

            var reRoute = new DownstreamReRouteBuilder()
                          .WithQosOptions(qosOptions)
                          .Build();

            this.When(x => x.WhenWeGetTheQoSProvider(reRoute))
            .Then(x => x.ThenAnErrorIsReturned())
            .BDDfy();
        }
Ejemplo n.º 18
0
        public void should_store_qos_provider_on_first_request()
        {
            var qosOptions = new QoSOptionsBuilder()
                             .WithKey("test")
                             .Build();

            var reRoute = new DownstreamReRouteBuilder()
                          .WithQosOptions(qosOptions)
                          .Build();

            this.Given(x => x.GivenThereIsAQoSProvider(reRoute, new FakeQoSProvider()))
            .Then(x => x.ThenItIsAdded())
            .BDDfy();
        }
Ejemplo n.º 19
0
        public void should_build()
        {
            var options = new QoSOptionsBuilder()
                          .WithTimeoutValue(100)
                          .WithExceptionsAllowedBeforeBreaking(1)
                          .WithDurationOfBreak(200)
                          .Build();
            var route = new DownstreamRouteBuilder().WithQosOptions(options)
                        .Build();
            var factory          = new Mock <IOcelotLoggerFactory>();
            var pollyQoSProvider = new PollyQoSProvider(route, factory.Object);

            pollyQoSProvider.CircuitBreaker.ShouldNotBeNull();
        }
Ejemplo n.º 20
0
        public void should_create_downstream_route_with_qos()
        {
            var qoSOptions = new QoSOptionsBuilder()
                             .WithExceptionsAllowedBeforeBreaking(1)
                             .WithTimeoutValue(1)
                             .Build();

            var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", qoSOptions, _handlerOptions);

            this.Given(_ => GivenTheConfiguration(configuration))
            .And(_ => GivenTheQosCreatorReturns(qoSOptions))
            .When(_ => WhenICreate())
            .Then(_ => ThenTheQosOptionsAreSet(qoSOptions))
            .BDDfy();
        }
Ejemplo n.º 21
0
        public void should_return_provider_with_no_delegates()
        {
            var qosOptions = new QoSOptionsBuilder()
                             .Build();

            var route = new DownstreamRouteBuilder()
                        .WithQosOptions(qosOptions)
                        .WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false, true, int.MaxValue)).WithLoadBalancerKey("").Build();

            this.Given(x => GivenTheFollowingRequest(route))
            .And(x => GivenTheServiceProviderReturnsNothing())
            .When(x => WhenIGet())
            .Then(x => ThenNoDelegatesAreInTheProvider())
            .BDDfy();
        }
        public void should_call_qos_options_creator()
        {
            var expected = new QoSOptionsBuilder()
                           .WithDurationOfBreak(1)
                           .WithExceptionsAllowedBeforeBreaking(1)
                           .WithTimeoutValue(1)
                           .Build();

            var serviceOptions = new ReRouteOptionsBuilder()
                                 .WithIsQos(true)
                                 .Build();

            this.Given(x => x.GivenTheConfigIs(new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        DownstreamHostAndPorts = new List <FileHostAndPort>
                        {
                            new FileHostAndPort
                            {
                                Host = "127.0.0.1",
                            }
                        },
                        UpstreamPathTemplate   = "/api/products/{productId}",
                        DownstreamPathTemplate = "/products/{productId}",
                        UpstreamHttpMethod     = new List <string> {
                            "Get"
                        },
                        QoSOptions = new FileQoSOptions
                        {
                            TimeoutValue    = 1,
                            DurationOfBreak = 1,
                            ExceptionsAllowedBeforeBreaking = 1
                        }
                    }
                },
            }))
            .And(x => x.GivenTheConfigIsValid())
            .And(x => GivenTheDownstreamAddresses())
            .And(x => GivenTheHeaderFindAndReplaceCreatorReturns())
            .And(x => x.GivenTheFollowingOptionsAreReturned(serviceOptions))
            .And(x => x.GivenTheQosOptionsCreatorReturns(expected))
            .When(x => x.WhenICreateTheConfig())
            .Then(x => x.ThenTheQosOptionsAre(expected))
            .BDDfy();
        }
Ejemplo n.º 23
0
        public void should_return_no_qos_provider()
        {
            var qosOptions = new QoSOptionsBuilder()
                             .Build();

            var reRoute = new DownstreamReRouteBuilder()
                          .WithQosOptions(qosOptions)
                          .WithUpstreamHttpMethod(new List <string> {
                "get"
            })
                          .Build();

            this.Given(x => x.GivenAReRoute(reRoute))
            .When(x => x.WhenIGetTheQoSProvider())
            .Then(x => x.ThenTheQoSProviderIsReturned <NoQoSProvider>())
            .BDDfy();
        }
Ejemplo n.º 24
0
        public void should_build_http_client()
        {
            var qosOptions = new QoSOptionsBuilder()
                             .Build();

            var reRoute = new DownstreamReRouteBuilder()
                          .WithQosOptions(qosOptions)
                          .WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false))
                          .WithLoadBalancerKey("")
                          .WithQosOptions(new QoSOptionsBuilder().Build())
                          .Build();

            this.Given(x => GivenTheFactoryReturns())
            .And(x => GivenARequest(reRoute))
            .When(x => WhenIBuild())
            .Then(x => ThenTheHttpClientShouldNotBeNull())
            .BDDfy();
        }
Ejemplo n.º 25
0
        public void should_return_provider_with_qos_delegate_when_timeout_value_set()
        {
            var qosOptions = new QoSOptionsBuilder()
                             .WithTimeoutValue(1)
                             .Build();

            var route = new DownstreamRouteBuilder()
                        .WithQosOptions(qosOptions)
                        .WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false, true, int.MaxValue)).WithLoadBalancerKey("").Build();

            this.Given(x => GivenTheFollowingRequest(route))
            .And(x => GivenTheQosFactoryReturns(new FakeQoSHandler()))
            .And(x => GivenTheServiceProviderReturnsNothing())
            .When(x => WhenIGet())
            .Then(x => ThenThereIsDelegatesInProvider(1))
            .And(x => ThenItIsQosHandler(0))
            .BDDfy();
        }
Ejemplo n.º 26
0
        public void should_build_http_client()
        {
            var qosOptions = new QoSOptionsBuilder()
                             .Build();

            var route = new DownstreamRouteBuilder()
                        .WithQosOptions(qosOptions)
                        .WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false, true, int.MaxValue))
                        .WithLoadBalancerKey("")
                        .WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithOriginalValue("").Build())
                        .WithQosOptions(new QoSOptionsBuilder().Build())
                        .Build();

            this.Given(x => GivenTheFactoryReturns())
            .And(x => GivenARequest(route))
            .When(x => WhenIBuild())
            .Then(x => ThenTheHttpClientShouldNotBeNull())
            .BDDfy();
        }
Ejemplo n.º 27
0
        public void should_return_error()
        {
            var qosOptions = new QoSOptionsBuilder()
                             .WithTimeoutValue(1)
                             .WithDurationOfBreak(1)
                             .WithExceptionsAllowedBeforeBreaking(1)
                             .Build();

            var reRoute = new DownstreamReRouteBuilder()
                          .WithQosOptions(qosOptions)
                          .WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false, true)).WithLoadBalancerKey("").Build();

            this.Given(x => GivenTheFollowingRequest(reRoute))
            .And(x => GivenTheQosProviderHouseReturns(new ErrorResponse <IQoSProvider>(It.IsAny <Error>())))
            .And(x => GivenTheServiceProviderReturnsNothing())
            .When(x => WhenIGet())
            .Then(x => ThenAnErrorIsReturned())
            .BDDfy();
        }
Ejemplo n.º 28
0
        public void should_return_polly_qos_provider()
        {
            var qosOptions = new QoSOptionsBuilder()
                             .WithTimeoutValue(100)
                             .WithDurationOfBreak(100)
                             .WithExceptionsAllowedBeforeBreaking(100)
                             .Build();

            var reRoute = new ReRouteBuilder()
                          .WithUpstreamHttpMethod("get")
                          .WithIsQos(true)
                          .WithQosOptions(qosOptions)
                          .Build();

            this.Given(x => x.GivenAReRoute(reRoute))
            .When(x => x.WhenIGetTheQoSProvider())
            .Then(x => x.ThenTheQoSProviderIsReturned <PollyQoSProvider>())
            .BDDfy();
        }
Ejemplo n.º 29
0
        public void should_log_if_ignoring_ssl_errors()
        {
            var qosOptions = new QoSOptionsBuilder()
                             .Build();

            var reRoute = new DownstreamReRouteBuilder()
                          .WithQosOptions(qosOptions)
                          .WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false))
                          .WithLoadBalancerKey("")
                          .WithQosOptions(new QoSOptionsBuilder().Build())
                          .WithDangerousAcceptAnyServerCertificateValidator(true)
                          .Build();

            this.Given(x => GivenTheFactoryReturns())
            .And(x => GivenARequest(reRoute))
            .When(x => WhenIBuild())
            .Then(x => ThenTheHttpClientShouldNotBeNull())
            .Then(x => ThenTheDangerousAcceptAnyServerCertificateValidatorWarningIsLogged())
            .BDDfy();
        }
Ejemplo n.º 30
0
        public void should_call_qos_options_creator()
        {
            var expected = new QoSOptionsBuilder()
                           .WithDurationOfBreak(1)
                           .WithExceptionsAllowedBeforeBreaking(1)
                           .WithTimeoutValue(1)
                           .Build();

            var serviceOptions = new ReRouteOptionsBuilder()
                                 .WithIsQos(true)
                                 .Build();

            this.Given(x => x.GivenTheConfigIs(new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        DownstreamHost         = "127.0.0.1",
                        UpstreamPathTemplate   = "/api/products/{productId}",
                        DownstreamPathTemplate = "/products/{productId}",
                        UpstreamHttpMethod     = "Get",
                        QoSOptions             = new FileQoSOptions
                        {
                            TimeoutValue    = 1,
                            DurationOfBreak = 1,
                            ExceptionsAllowedBeforeBreaking = 1
                        }
                    }
                },
            }))
            .And(x => x.GivenTheConfigIsValid())
            .And(x => x.GivenTheFollowingOptionsAreReturned(serviceOptions))
            .And(x => x.GivenTheQosProviderFactoryReturns())
            .And(x => x.GivenTheQosOptionsCreatorReturns(expected))
            .When(x => x.WhenICreateTheConfig())
            .Then(x => x.ThenTheQosOptionsAre(expected))
            .And(x => x.TheQosProviderFactoryIsCalledCorrectly())
            .And(x => x.ThenTheQosProviderHouseIsCalledCorrectly())
            .BDDfy();
        }