Exemplo n.º 1
0
        public void CanUseBaseRoute()
        {
            var balancer = new RoundRobinBalancer <Uri>();

            balancer.Resources.Add(new Uri("https://127.0.0.1/api/round-robin"));
            balancer.Resources.Add(new Uri("http://[::1]/round-robin"));
            balancer.Resources.Add(new Uri("https://www.google.com/api/foo/bar/baz"));
            var bindingMap = new BindingMap {
                { "round-robin", balancer }
            };

            var startUri = new Uri("http://round-robin/more-complex/query?foo=bar&baz=1");

            bindingMap.TryRebindUri(startUri, out var newUri).Should().BeTrue();
            newUri.Should()
            .BeEquivalentTo(new Uri("https://127.0.0.1/api/round-robin/more-complex/query?foo=bar&baz=1"));
            bindingMap.TryRebindUri(startUri, out newUri).Should().BeTrue();
            newUri.Should().BeEquivalentTo(new Uri("http://[::1]/round-robin/more-complex/query?foo=bar&baz=1"));
            bindingMap.TryRebindUri(startUri, out newUri).Should().BeTrue();
            newUri.Should()
            .BeEquivalentTo(new Uri("https://www.google.com/api/foo/bar/baz/more-complex/query?foo=bar&baz=1"));
            bindingMap.TryRebindUri(startUri, out newUri).Should().BeTrue();
            newUri.Should()
            .BeEquivalentTo(new Uri("https://127.0.0.1/api/round-robin/more-complex/query?foo=bar&baz=1"));
        }
Exemplo n.º 2
0
        public void WillIgnoreUrisNotConfigured()
        {
            var bindingMap = new BindingMap();

            var startUri = new Uri("http://test/resource");

            bindingMap.TryRebindUri(startUri, out var newUri).Should().BeFalse();
            newUri.Should().BeEquivalentTo(startUri);
        }
Exemplo n.º 3
0
        public void UriIsRequired()
        {
            var    bindingMap = new BindingMap();
            Action action     = () => bindingMap.TryRebindUri(null, out _);

            action.Should()
            .Throw <ArgumentNullException>()
            .WithMessage("Value cannot be null.\nParameter name: *");
        }
Exemplo n.º 4
0
        public void WillUseLoadBalancerRulesAndRespectQueries()
        {
            var balancer = new RoundRobinBalancer <Uri>();

            balancer.Resources.Add(new Uri("https://127.0.0.1"));
            balancer.Resources.Add(new Uri("http://[::1]"));
            balancer.Resources.Add(new Uri("https://www.google.com"));
            var bindingMap = new BindingMap {
                { "round-robin", balancer }
            };

            var startUri = new Uri("http://round-robin/more-complex/query?foo=bar&baz=1");

            bindingMap.TryRebindUri(startUri, out var newUri).Should().BeTrue();
            newUri.Should().BeEquivalentTo(new Uri("https://127.0.0.1/more-complex/query?foo=bar&baz=1"));
            bindingMap.TryRebindUri(startUri, out newUri).Should().BeTrue();
            newUri.Should().BeEquivalentTo(new Uri("http://[::1]/more-complex/query?foo=bar&baz=1"));
            bindingMap.TryRebindUri(startUri, out newUri).Should().BeTrue();
            newUri.Should().BeEquivalentTo(new Uri("https://www.google.com/more-complex/query?foo=bar&baz=1"));
            bindingMap.TryRebindUri(startUri, out newUri).Should().BeTrue();
            newUri.Should().BeEquivalentTo(new Uri("https://127.0.0.1/more-complex/query?foo=bar&baz=1"));
        }
Exemplo n.º 5
0
        public void WillReplaceHostNameWhenConfigured()
        {
            var balancer = new RandomLoadBalancer <Uri>();

            balancer.Resources.Add(new Uri("https://127.0.0.1"));
            var bindingMap = new BindingMap {
                { "test", balancer }
            };

            var startUri = new Uri("http://test/resource");

            bindingMap.TryRebindUri(startUri, out var newUri).Should().BeTrue();
            newUri.Should().BeEquivalentTo(new Uri("https://127.0.0.1/resource"));
        }