public void ShouldGetANewClusterView()
                {
                    // Given
                    var uri = new Uri("bolt+routing://123:456");
                    // a cluster view which knows a read/write uri
                    var clusterView = NewClusterView(new[] { uri }, new Uri[0], new Uri[0]);

                    var mockedConn     = new Mock <IPooledConnection>();
                    var mockedConnPool = new Mock <IConnectionPool>();

                    mockedConnPool.Setup(x => x.Acquire()).Returns(mockedConn.Object);
                    var dict = new ConcurrentDictionary <Uri, IConnectionPool>();

                    dict.TryAdd(uri, mockedConnPool.Object);

                    // a cluster pool which knows the conns with the uri server
                    var clusterConnPool = new ClusterConnectionPool(null, dict);
                    var balancer        = new RoundRobinLoadBalancer(clusterConnPool, clusterView);

                    // When
                    var anotherUri = new Uri("bolt+routing://123:789");
                    var result     = balancer.NewClusterView(connection
                                                             => NewClusterView(new [] { anotherUri }, new Uri[0], new Uri[0]));

                    // Then
                    result.All().Should().ContainInOrder(anotherUri);
                }
                public void ShouldRemoveTheServerIfRediscoveryThrowInvalidDiscoveryException()
                {
                    // Given
                    var uri  = new Uri("bolt+routing://123:456");
                    var uri2 = new Uri("bolt+routing://123:789");
                    // a cluster view which knows a read/write uri
                    var clusterView = NewClusterView(new[] { uri, uri2 }, new Uri[0], new Uri[0]);

                    var mockedConn     = new Mock <IPooledConnection>();
                    var mockedConnPool = new Mock <IConnectionPool>();

                    mockedConnPool.Setup(x => x.Acquire()).Returns(mockedConn.Object);
                    var dict = new ConcurrentDictionary <Uri, IConnectionPool>();

                    dict.TryAdd(uri, mockedConnPool.Object);
                    dict.TryAdd(uri2, mockedConnPool.Object);

                    // a cluster pool which knows the conns with the uri server
                    var clusterConnPool = new ClusterConnectionPool(null, dict);

                    var balancer = new RoundRobinLoadBalancer(clusterConnPool, clusterView);

                    // When
                    var error = Record.Exception(() => balancer.NewClusterView(connection =>
                    {
                        // never successfully rediscovery
                        throw new InvalidDiscoveryException("Invalid");
                    }));

                    // Then
                    clusterView.All().Should().BeEmpty();
                    error.Should().BeOfType <ServerUnavailableException>();
                }
                public void ShouldThrowServerUnavailableException()
                {
                    // Given
                    var clusterView = NewClusterView(new Uri[0], new Uri[0], new Uri[0]);
                    var balancer    = new RoundRobinLoadBalancer(null, clusterView);

                    // When
                    var error = Record.Exception(() => balancer.NewClusterView());

                    // Then
                    error.Should().BeOfType <ServerUnavailableException>();
                    error.Message.Should().Contain("Failed to connect to any routing server.");
                }