Esempio n. 1
0
        public void Open_should_raise_the_correct_events_upon_failure(
            [Values(false, true)]
            bool async)
        {
            Action act;

            if (async)
            {
                var result = new TaskCompletionSource <ConnectionDescription>();
                result.SetException(new SocketException());
                _connectionInitializer.InitializeConnectionAsync(null, CancellationToken.None)
                .ReturnsForAnyArgs(result.Task);

                act = () => _subject.OpenAsync(CancellationToken.None).GetAwaiter().GetResult();
            }
            else
            {
                _connectionInitializer.InitializeConnection(null, CancellationToken.None)
                .ReturnsForAnyArgs(_ => { throw new SocketException(); });

                act = () => _subject.Open(CancellationToken.None);
            }

            act.ShouldThrow <MongoConnectionException>()
            .WithInnerException <SocketException>()
            .And.ConnectionId.Should().Be(_subject.ConnectionId);

            _capturedEvents.Next().Should().BeOfType <ConnectionOpeningEvent>();
            _capturedEvents.Next().Should().BeOfType <ConnectionOpeningFailedEvent>();
            _capturedEvents.Any().Should().BeFalse();
        }
Esempio n. 2
0
        public void Setup()
        {
            _capturedEvents = new EventCapturer();
            _streamFactory  = Substitute.For <IStreamFactory>();

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

            _connectionInitializer = Substitute.For <IConnectionInitializer>();
            _connectionInitializer.InitializeConnection(null, CancellationToken.None)
            .ReturnsForAnyArgs(new ConnectionDescription(
                                   new ConnectionId(serverId),
                                   new IsMasterResult(new BsonDocument()),
                                   new BuildInfoResult(new BsonDocument("version", "2.6.3"))));
            _connectionInitializer.InitializeConnectionAsync(null, CancellationToken.None)
            .ReturnsForAnyArgs(Task.FromResult(new ConnectionDescription(
                                                   new ConnectionId(serverId),
                                                   new IsMasterResult(new BsonDocument()),
                                                   new BuildInfoResult(new BsonDocument("version", "2.6.3")))));

            _subject = new BinaryConnection(
                serverId: serverId,
                endPoint: _endPoint,
                settings: new ConnectionSettings(),
                streamFactory: _streamFactory,
                connectionInitializer: _connectionInitializer,
                eventSubscriber: _capturedEvents);
        }
        public void Setup()
        {
            _capturedEvents = new EventCapturer();
            _streamFactory = Substitute.For<IStreamFactory>();

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

            _connectionInitializer = Substitute.For<IConnectionInitializer>();
            _connectionInitializer.InitializeConnection(null, CancellationToken.None)
                .ReturnsForAnyArgs(new ConnectionDescription(
                    new ConnectionId(serverId),
                    new IsMasterResult(new BsonDocument()),
                    new BuildInfoResult(new BsonDocument("version", "2.6.3"))));
            _connectionInitializer.InitializeConnectionAsync(null, CancellationToken.None)
                .ReturnsForAnyArgs(Task.FromResult(new ConnectionDescription(
                    new ConnectionId(serverId),
                    new IsMasterResult(new BsonDocument()),
                    new BuildInfoResult(new BsonDocument("version", "2.6.3")))));

            _subject = new BinaryConnection(
                serverId: serverId,
                endPoint: _endPoint,
                settings: new ConnectionSettings(),
                streamFactory: _streamFactory,
                connectionInitializer: _connectionInitializer,
                eventSubscriber: _capturedEvents);
        }