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("") .WithUpstreamTemplatePattern(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 should_call_scoped_data_repository_correctly() { var config = new OcelotConfiguration(null, null, new ServiceProviderConfigurationBuilder().Build(), ""); var downstreamReRoute = new DownstreamReRouteBuilder() .WithDownstreamPathTemplate("any old string") .WithUpstreamHttpMethod(new List <string> { "Get" }) .Build(); this.Given(x => x.GivenTheDownStreamRouteFinderReturns( new DownstreamRoute( new List <PlaceholderNameAndValue>(), new ReRouteBuilder() .WithDownstreamReRoute(downstreamReRoute) .WithUpstreamHttpMethod(new List <string> { "Get" }) .Build()))) .And(x => GivenTheFollowingConfig(config)) .When(x => x.WhenICallTheMiddleware()) .Then(x => x.ThenTheScopedDataRepositoryIsCalledCorrectly()) .BDDfy(); }
public void should_create_downstream_route_with_rate_limit_options() { var rateLimitOptions = new RateLimitOptionsBuilder() .WithEnableRateLimiting(true) .WithClientIdHeader("test") .Build(); var downstreamReRoute = new DownstreamReRouteBuilder() .WithServiceName("auth") .WithRateLimitOptions(rateLimitOptions) .Build(); var reRoute = new ReRouteBuilder() .WithDownstreamReRoute(downstreamReRoute) .Build(); var reRoutes = new List <ReRoute> { reRoute }; var configuration = new InternalConfiguration(reRoutes, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions); this.Given(_ => GivenTheConfiguration(configuration)) .When(_ => WhenICreate()) .Then(_ => ThenTheDownstreamRouteIsCreated()) .And(_ => WithRateLimitOptions(rateLimitOptions)) .BDDfy(); }
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("") .WithUpstreamTemplatePattern(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(); }
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)) .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(); }
public void should_call_request_correctly() { var qosOptions = new QoSOptionsBuilder() .Build(); var reRoute = new DownstreamReRouteBuilder() .WithQosOptions(qosOptions) .WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false)) .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(); }
public void http_client_request_times_out() { var qosOptions = new QoSOptionsBuilder() .Build(); var reRoute = new DownstreamReRouteBuilder() .WithQosOptions(qosOptions) .WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false)) .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(); }
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("") .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(); }
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 reRoute = new DownstreamReRouteBuilder() .WithQosOptions(qosOptions) .WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true, true)) .WithLoadBalancerKey("") .Build(); this.Given(x => GivenTheFollowingRequest(reRoute)) .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(); }
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(); }
public void issue_473_should_not_remove_additional_query_string() { var downstreamReRoute = new DownstreamReRouteBuilder() .WithDownstreamPathTemplate("/Authorized/{action}?server={server}") .WithUpstreamHttpMethod(new List <string> { "Post", "Get" }) .WithDownstreamScheme("http") .WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithOriginalValue("/uc/Authorized/{server}/{action}").Build()) .Build(); var config = new ServiceProviderConfigurationBuilder() .Build(); this.Given(x => x.GivenTheDownStreamRouteIs( new DownstreamRoute( new List <PlaceholderNameAndValue> { new PlaceholderNameAndValue("{action}", "1"), new PlaceholderNameAndValue("{server}", "2") }, new ReRouteBuilder() .WithDownstreamReRoute(downstreamReRoute) .WithUpstreamHttpMethod(new List <string> { "Post", "Get" }) .Build()))) .And(x => x.GivenTheDownstreamRequestUriIs("http://localhost:5000/uc/Authorized/2/1/refresh?refreshToken=2288356cfb1338fdc5ff4ca558ec785118dfe1ff2864340937da8226863ff66d")) .And(x => GivenTheServiceProviderConfigIs(config)) .And(x => x.GivenTheUrlReplacerWillReturn("/Authorized/1?server=2")) .When(x => x.WhenICallTheMiddleware()) .Then(x => x.ThenTheDownstreamRequestUriIs("http://localhost:5000/Authorized/1?refreshToken=2288356cfb1338fdc5ff4ca558ec785118dfe1ff2864340937da8226863ff66d&server=2")) .And(x => ThenTheQueryStringIs("?refreshToken=2288356cfb1338fdc5ff4ca558ec785118dfe1ff2864340937da8226863ff66d&server=2")) .BDDfy(); }
public void should_call_middleware_and_ratelimiting() { var upstreamTemplate = new UpstreamPathTemplateBuilder().Build(); var downstreamReRoute = new DownstreamReRouteBuilder() .WithEnableRateLimiting(true) .WithRateLimitOptions(new RateLimitOptions(true, "ClientId", new List <string>(), false, "", "", new RateLimitRule("1s", 100, 3), 429)) .WithUpstreamHttpMethod(new List <string> { "Get" }) .WithUpstreamPathTemplate(upstreamTemplate) .Build(); var reRoute = new ReRouteBuilder() .WithDownstreamReRoute(downstreamReRoute) .WithUpstreamHttpMethod(new List <string> { "Get" }) .Build(); var downstreamRoute = new DownstreamRoute(new List <Ocelot.DownstreamRouteFinder.UrlMatcher.PlaceholderNameAndValue>(), reRoute); this.Given(x => x.GivenTheDownStreamRouteIs(downstreamRoute)) .When(x => x.WhenICallTheMiddlewareMultipleTime(2)) .Then(x => x.ThenresponseStatusCodeIs200()) .When(x => x.WhenICallTheMiddlewareMultipleTime(3)) .Then(x => x.ThenresponseStatusCodeIs429()) .BDDfy(); }
public void should_follow_ordering_order_specifics_and_globals() { 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> { "FakeDelegatingHandlerTwo", "FakeDelegatingHandler", "FakeDelegatingHandlerFour" }) .WithLoadBalancerKey("") .Build(); this.Given(x => GivenTheFollowingRequest(reRoute)) .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(); }
public void should_follow_ordering_dont_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)) .WithLoadBalancerKey("") .Build(); this.Given(x => GivenTheFollowingRequest(reRoute)) .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_replace_query_string() { var downstreamReRoute = new DownstreamReRouteBuilder() .WithDownstreamPathTemplate("/api/units/{subscriptionId}/{unitId}/updates") .WithUpstreamHttpMethod(new List <string> { "Get" }) .WithDownstreamScheme("https") .Build(); var config = new ServiceProviderConfigurationBuilder() .Build(); this.Given(x => x.GivenTheDownStreamRouteIs( new DownstreamRoute( new List <PlaceholderNameAndValue> { new PlaceholderNameAndValue("{subscriptionId}", "1"), new PlaceholderNameAndValue("{unitId}", "2") }, new ReRouteBuilder() .WithDownstreamReRoute(downstreamReRoute) .WithUpstreamHttpMethod(new List <string> { "Get" }) .Build()))) .And(x => x.GivenTheDownstreamRequestUriIs("http://localhost:5000/api/subscriptions/1/updates?unitId=2")) .And(x => GivenTheServiceProviderConfigIs(config)) .And(x => x.GivenTheUrlReplacerWillReturn("api/units/1/2/updates")) .When(x => x.WhenICallTheMiddleware()) .Then(x => x.ThenTheDownstreamRequestUriIs("https://localhost:5000/api/units/1/2/updates")) .And(x => ThenTheQueryStringIs("")) .BDDfy(); }
public void should_replace_scheme_and_path() { var downstreamReRoute = new DownstreamReRouteBuilder() .WithDownstreamPathTemplate("any old string") .WithUpstreamHttpMethod(new List <string> { "Get" }) .WithDownstreamScheme("https") .Build(); var config = new ServiceProviderConfigurationBuilder() .Build(); this.Given(x => x.GivenTheDownStreamRouteIs( new DownstreamRoute( new List <PlaceholderNameAndValue>(), new ReRouteBuilder() .WithDownstreamReRoute(downstreamReRoute) .WithUpstreamHttpMethod(new List <string> { "Get" }) .Build()))) .And(x => x.GivenTheDownstreamRequestUriIs("http://my.url/abc?q=123")) .And(x => GivenTheServiceProviderConfigIs(config)) .And(x => x.GivenTheUrlReplacerWillReturn("/api/products/1")) .When(x => x.WhenICallTheMiddleware()) .Then(x => x.ThenTheDownstreamRequestUriIs("https://my.url:80/api/products/1?q=123")) .And(x => ThenTheQueryStringIs("?q=123")) .BDDfy(); }
public void should_create_service_fabric_url() { var downstreamReRoute = new DownstreamReRouteBuilder() .WithDownstreamScheme("http") .WithServiceName("Ocelot/OcelotApp") .WithUseServiceDiscovery(true) .Build(); var downstreamRoute = new DownstreamRoute( new List <PlaceholderNameAndValue>(), new ReRouteBuilder() .WithDownstreamReRoute(downstreamReRoute) .Build()); var config = new ServiceProviderConfigurationBuilder() .WithType("ServiceFabric") .WithHost("localhost") .WithPort(19081) .Build(); this.Given(x => x.GivenTheDownStreamRouteIs(downstreamRoute)) .And(x => GivenTheServiceProviderConfigIs(config)) .And(x => x.GivenTheDownstreamRequestUriIs("http://localhost:19081")) .And(x => x.GivenTheUrlReplacerWillReturn("/api/products/1")) .When(x => x.WhenICallTheMiddleware()) .Then(x => x.ThenTheDownstreamRequestUriIs("http://localhost:19081/Ocelot/OcelotApp/api/products/1?cmd=instance")) .BDDfy(); }
public void should_store_load_balancer_on_first_request() { var reRoute = new DownstreamReRouteBuilder().WithReRouteKey("test").Build(); this.Given(x => x.GivenThereIsALoadBalancer(reRoute, new FakeLoadBalancer())) .Then(x => x.ThenItIsAdded()) .BDDfy(); }
public IPSecurityPolicyTests() { _downstreamContext = new DownstreamContext(new DefaultHttpContext()); _downstreamContext.DownstreamRequest = new DownstreamRequest(new HttpRequestMessage(HttpMethod.Get, "http://test.com")); _downstreamContext.HttpContext.Connection.RemoteIpAddress = Dns.GetHostAddresses("192.168.1.1")[0]; _downstreamReRouteBuilder = new DownstreamReRouteBuilder(); _ipSecurityPolicy = new IPSecurityPolicy(); }
public void should_return_error_if_exception() { var reRoute = new DownstreamReRouteBuilder().Build(); this.When(x => x.WhenWeGetTheLoadBalancer(reRoute)) .Then(x => x.ThenAnErrorIsReturned()) .BDDfy(); }
public void should_return_error_if_no_qos_provider_with_key() { var reRoute = new DownstreamReRouteBuilder().Build(); this.When(x => x.WhenWeGetTheQoSProvider(reRoute)) .Then(x => x.ThenAnErrorIsReturned()) .BDDfy(); }
public void should_store_qos_provider_on_first_request() { var reRoute = new DownstreamReRouteBuilder().WithReRouteKey("test").Build(); this.Given(x => x.GivenThereIsAQoSProvider(reRoute, new FakeQoSProvider())) .Then(x => x.ThenItIsAdded()) .BDDfy(); }
public void should_return_error() { var downstreamReRoute = new DownstreamReRouteBuilder().Build(); var handler = _factory.Get(downstreamReRoute); handler.IsError.ShouldBeTrue(); handler.Errors[0].ShouldBeOfType <UnableToFindQoSProviderError>(); }
public void should_not_store_load_balancer_on_second_request() { var reRoute = new DownstreamReRouteBuilder().WithLoadBalancer("FakeLoadBalancer").WithReRouteKey("test").Build(); this.Given(x => x.GivenThereIsALoadBalancer(reRoute, new FakeLoadBalancer())) .When(x => x.WhenWeGetTheLoadBalancer(reRoute)) .Then(x => x.ThenItIsReturned()) .BDDfy(); }
public void should_use_service_discovery_for_downstream_service_host() { var reRouteOptions = new ReRouteOptionsBuilder() .Build(); var downstreamReRoute = new DownstreamReRouteBuilder() .WithDownstreamPathTemplate("/products/{productId}") .WithUpstreamPathTemplate("/api/products/{productId}") .WithUpstreamHttpMethod(new List <string> { "Get" }) .WithUseServiceDiscovery(true) .WithServiceName("ProductService") .WithLoadBalancerKey("/api/products/{productId}|Get") .Build(); this.Given(x => x.GivenTheConfigIs(new FileConfiguration { ReRoutes = new List <FileReRoute> { new FileReRoute { UpstreamPathTemplate = "/api/products/{productId}", DownstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = new List <string> { "Get" }, ReRouteIsCaseSensitive = false, ServiceName = "ProductService" } }, GlobalConfiguration = new FileGlobalConfiguration { ServiceDiscoveryProvider = new FileServiceDiscoveryProvider { Host = "127.0.0.1" } } })) .And(x => x.GivenTheConfigIsValid()) .And(x => GivenTheDownstreamAddresses()) .And(x => GivenTheHeaderFindAndReplaceCreatorReturns()) .And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions)) .When(x => x.WhenICreateTheConfig()) .Then(x => x.ThenTheReRoutesAre(new List <ReRoute> { new ReRouteBuilder() .WithDownstreamReRoute(downstreamReRoute) .WithUpstreamPathTemplate("/api/products/{productId}") .WithUpstreamHttpMethod(new List <string> { "Get" }) .Build() })) .BDDfy(); }
public void should_use_downstream_host() { var reRouteOptions = new ReRouteOptionsBuilder() .Build(); var downstreamReRoute = new DownstreamReRouteBuilder() .WithDownstreamAddresses(new List <DownstreamHostAndPort>() { new DownstreamHostAndPort("127.0.0.1", 80) }) .WithDownstreamPathTemplate("/products/{productId}") .WithUpstreamPathTemplate("/api/products/{productId}") .WithUpstreamHttpMethod(new List <string> { "Get" }) .WithLoadBalancerKey("/api/products/{productId}|Get") .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" }, } }, })) .And(x => x.GivenTheConfigIsValid()) .And(x => GivenTheDownstreamAddresses()) .And(x => GivenTheHeaderFindAndReplaceCreatorReturns()) .And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions)) .When(x => x.WhenICreateTheConfig()) .Then(x => x.ThenTheReRoutesAre(new List <ReRoute> { new ReRouteBuilder() .WithDownstreamReRoute(downstreamReRoute) .WithUpstreamPathTemplate("/api/products/{productId}") .WithUpstreamHttpMethod(new List <string> { "Get" }) .Build() })) .BDDfy(); }
public void should_return_result_of_specified_creator_func() { var reRoute = new DownstreamReRouteBuilder() .Build(); this.Given(x => x.GivenAReRoute(reRoute)) .When(x => x.WhenIGetTheLoadBalancer()) .Then(x => x.ThenTheLoadBalancerIsReturned <FakeLoadBalancer>()) .BDDfy(); }
public void should_return_ConsulServiceDiscoveryProvider() { var reRoute = new DownstreamReRouteBuilder() .WithServiceName("") .Build(); var provider = ConsulProviderFactory.Get(_provider, new ServiceProviderConfiguration("", "", 1, "", "", 1), reRoute); provider.ShouldBeOfType <Consul>(); }
public void should_return_instance_of_expected_load_balancer_type() { var reRoute = new DownstreamReRouteBuilder() .Build(); this.Given(x => x.GivenAReRoute(reRoute)) .When(x => x.WhenIGetTheLoadBalancer()) .Then(x => x.ThenTheLoadBalancerIsReturned <NoLoadBalancer>()) .BDDfy(); }
public void should_return_error_if_any_downstreams_have_errored() { var billDownstreamReRoute = new DownstreamReRouteBuilder().WithKey("Bill").Build(); var georgeDownstreamReRoute = new DownstreamReRouteBuilder().WithKey("George").Build(); var downstreamReRoutes = new List <DownstreamReRoute> { billDownstreamReRoute, georgeDownstreamReRoute }; var reRoute = new ReRouteBuilder() .WithDownstreamReRoutes(downstreamReRoutes) .Build(); var billDownstreamContext = new DownstreamContext(new DefaultHttpContext()) { DownstreamResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("Bill says hi") }, DownstreamReRoute = billDownstreamReRoute }; var georgeDownstreamContext = new DownstreamContext(new DefaultHttpContext()) { DownstreamResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("Error") }, DownstreamReRoute = georgeDownstreamReRoute, Errors = new List <Error>() { new AnyError() } }; var downstreamContexts = new List <DownstreamContext> { billDownstreamContext, georgeDownstreamContext }; var expected = "Error"; this.Given(x => GivenTheUpstreamContext(new DownstreamContext(new DefaultHttpContext()))) .And(x => GivenTheReRoute(reRoute)) .And(x => GivenTheDownstreamContext(downstreamContexts)) .When(x => WhenIAggregate()) .Then(x => ThenTheContentIs(expected)) .And(x => ThenTheErrorIsMapped()) .BDDfy(); }