Ejemplo n.º 1
0
        // methods
        public ICluster BuildCluster()
        {
            IStreamFactory streamFactory = new TcpStreamFactory(_tcpStreamSettings);
            // TODO: SSL gets handled here specifically...

            streamFactory = _streamFactoryWrapper(streamFactory);

            var connectionFactory = new BinaryConnectionFactory(
                _connectionSettings,
                streamFactory,
                _connectionListener);

            var connectionPoolFactory = new ExclusiveConnectionPoolFactory(
                _connectionPoolSettings,
                connectionFactory,
                _connectionPoolListener);

            var serverFactory = new ServerFactory(
                _serverSettings,
                connectionPoolFactory,
                connectionFactory,
                _serverListener);

            var clusterFactory = new ClusterFactory(
                _clusterSettings,
                serverFactory,
                _clusterListener);

            return clusterFactory.CreateCluster();
        }
        public void CreateConnection_should_throw_an_ArgumentNullException_when_serverId_is_null()
        {
            var streamFactory = Substitute.For<IStreamFactory>();
            var eventSubscriber = Substitute.For<IEventSubscriber>();
            var subject = new BinaryConnectionFactory(
                new ConnectionSettings(),
                streamFactory,
                eventSubscriber);

            Action act = () => subject.CreateConnection(null, new DnsEndPoint("localhost", 27017));
            act.ShouldThrow<ArgumentNullException>();
        }
        public void CreateConnection_should_throw_an_ArgumentNullException_when_serverId_is_null()
        {
            var streamFactory   = new Mock <IStreamFactory>().Object;
            var eventSubscriber = new Mock <IEventSubscriber>().Object;
            var subject         = new BinaryConnectionFactory(
                new ConnectionSettings(),
                streamFactory,
                eventSubscriber);

            Action act = () => subject.CreateConnection(null, new DnsEndPoint("localhost", 27017));

            act.ShouldThrow <ArgumentNullException>();
        }
        public void CreateConnection_should_throw_an_ArgumentNullException_when_serverId_is_null()
        {
            var streamFactory = Substitute.For <IStreamFactory>();
            var listener      = Substitute.For <IConnectionListener>();
            var subject       = new BinaryConnectionFactory(
                new ConnectionSettings(),
                streamFactory,
                listener);

            Action act = () => subject.CreateConnection(null, new DnsEndPoint("localhost", 27017));

            act.ShouldThrow <ArgumentNullException>();
        }
        public void CreateConnection_should_throw_an_ArgumentNullException_when_endPoint_is_null()
        {
            var streamFactory = new Mock<IStreamFactory>().Object;
            var eventSubscriber = new Mock<IEventSubscriber>().Object;
            var subject = new BinaryConnectionFactory(
                new ConnectionSettings(),
                streamFactory,
                eventSubscriber);

            var serverId = new ServerId(new ClusterId(), new DnsEndPoint("localhost", 27017));

            Action act = () => subject.CreateConnection(serverId, null);
            act.ShouldThrow<ArgumentNullException>();
        }
        public void CreateConnection_should_return_a_BinaryConnection()
        {
            var streamFactory = Substitute.For<IStreamFactory>();
            var listener = Substitute.For<IConnectionListener>();
            var subject = new BinaryConnectionFactory(
                new ConnectionSettings(),
                streamFactory,
                listener);

            var serverId = new ServerId(new ClusterId(), new DnsEndPoint("localhost", 27017));

            var connection = subject.CreateConnection(serverId, serverId.EndPoint);
            connection.Should().NotBeNull();
            connection.Should().BeOfType<BinaryConnection>();
        }
Ejemplo n.º 7
0
        public void CreateConnection_should_throw_an_ArgumentNullException_when_endPoint_is_null()
        {
            var streamFactory   = Substitute.For <IStreamFactory>();
            var eventSubscriber = Substitute.For <IEventSubscriber>();
            var subject         = new BinaryConnectionFactory(
                new ConnectionSettings(),
                streamFactory,
                eventSubscriber);

            var serverId = new ServerId(new ClusterId(), new DnsEndPoint("localhost", 27017));

            Action act = () => subject.CreateConnection(serverId, null);

            act.ShouldThrow <ArgumentNullException>();
        }
        public void CreateConnection_should_return_a_BinaryConnection()
        {
            var streamFactory   = new Mock <IStreamFactory>().Object;
            var eventSubscriber = new Mock <IEventSubscriber>().Object;
            var subject         = new BinaryConnectionFactory(
                new ConnectionSettings(),
                streamFactory,
                eventSubscriber);

            var serverId = new ServerId(new ClusterId(), new DnsEndPoint("localhost", 27017));

            var connection = subject.CreateConnection(serverId, serverId.EndPoint);

            connection.Should().NotBeNull();
            connection.Should().BeOfType <BinaryConnection>();
        }
        public void CreateConnection_should_return_a_BinaryConnection()
        {
            var streamFactory = Substitute.For <IStreamFactory>();
            var listener      = Substitute.For <IConnectionListener>();
            var subject       = new BinaryConnectionFactory(
                new ConnectionSettings(),
                streamFactory,
                listener);

            var serverId = new ServerId(new ClusterId(), new DnsEndPoint("localhost", 27017));

            var connection = subject.CreateConnection(serverId, serverId.EndPoint);

            connection.Should().NotBeNull();
            connection.Should().BeOfType <BinaryConnection>();
        }
Ejemplo n.º 10
0
        // methods
        private ICluster CreateCluster(ClusterKey clusterKey)
        {
            var clusterSettings = CreateClusterSettings(clusterKey);
            var serverSettings = CreateServerSettings(clusterKey);
            var connectionSettings = CreateConnectionSettings(clusterKey);
            var connectionPoolSettings = CreateConnectionPoolSettings(clusterKey);

            var listener = EmptyListener.Instance;
            var streamFactory = CreateStreamFactory(clusterKey);
            var connectionFactory = new BinaryConnectionFactory(connectionSettings, streamFactory, listener);
            var connectionPoolFactory = new ExclusiveConnectionPoolFactory(connectionPoolSettings, connectionFactory, listener);
            var serverFactory = new ServerFactory(serverSettings, connectionPoolFactory, connectionFactory, listener);
            var clusterFactory = new ClusterFactory(clusterSettings, serverFactory, listener);

            var cluster = clusterFactory.CreateCluster();
            cluster.Initialize();

            return cluster;
        }
 internal static IStreamFactory _streamFactory(this BinaryConnectionFactory obj) => (IStreamFactory)Reflector.GetFieldValue(obj, nameof(_streamFactory));
 internal static ConnectionSettings _settings(this BinaryConnectionFactory obj) => (ConnectionSettings)Reflector.GetFieldValue(obj, nameof(_settings));
        public void CreateConnection_should_throw_an_ArgumentNullException_when_endPoint_is_null()
        {
            var streamFactory = Substitute.For<IStreamFactory>();
            var listener = Substitute.For<IConnectionListener>();
            var subject = new BinaryConnectionFactory(
                new ConnectionSettings(),
                streamFactory,
                listener);

            var serverId = new ServerId(new ClusterId(), new DnsEndPoint("localhost", 27017));

            Action act = () => subject.CreateConnection(serverId, null);
            act.ShouldThrow<ArgumentNullException>();
        }
        public void CreateConnection_should_return_a_BinaryConnection()
        {
            var streamFactory = new Mock<IStreamFactory>().Object;
            var eventSubscriber = new Mock<IEventSubscriber>().Object;
            var subject = new BinaryConnectionFactory(
                new ConnectionSettings(),
                streamFactory,
                eventSubscriber);

            var serverId = new ServerId(new ClusterId(), new DnsEndPoint("localhost", 27017));

            var connection = subject.CreateConnection(serverId, serverId.EndPoint);
            connection.Should().NotBeNull();
            connection.Should().BeOfType<BinaryConnection>();
        }