public BinaryConnectionTests() { _capturedEvents = new EventCapturer(); _mockStreamFactory = new Mock <IStreamFactory>(); _endPoint = new DnsEndPoint("localhost", 27017); var serverId = new ServerId(new ClusterId(), _endPoint); var connectionId = new ConnectionId(serverId); var helloResult = new HelloResult(new BsonDocument { { "ok", 1 }, { "maxMessageSizeBytes", 48000000 }, { "maxWireVersion", WireVersion.Server36 } }); _connectionDescription = new ConnectionDescription(connectionId, helloResult); _mockConnectionInitializer = new Mock <IConnectionInitializer>(); _mockConnectionInitializer .Setup(i => i.SendHello(It.IsAny <IConnection>(), CancellationToken.None)) .Returns(_connectionDescription); _mockConnectionInitializer .Setup(i => i.Authenticate(It.IsAny <IConnection>(), It.IsAny <ConnectionDescription>(), CancellationToken.None)) .Returns(_connectionDescription); _mockConnectionInitializer .Setup(i => i.SendHelloAsync(It.IsAny <IConnection>(), CancellationToken.None)) .ReturnsAsync(_connectionDescription); _mockConnectionInitializer .Setup(i => i.AuthenticateAsync(It.IsAny <IConnection>(), It.IsAny <ConnectionDescription>(), CancellationToken.None)) .ReturnsAsync(_connectionDescription); _subject = new BinaryConnection( serverId: serverId, endPoint: _endPoint, settings: new ConnectionSettings(), streamFactory: _mockStreamFactory.Object, connectionInitializer: _mockConnectionInitializer.Object, eventSubscriber: _capturedEvents); }
private CompressorType?ChooseSendCompressorTypeIfAny(ConnectionDescription connectionDescription) { var availableCompressors = connectionDescription.AvailableCompressors; return(availableCompressors.Count > 0 ? (CompressorType?)availableCompressors[0] : null); }
public void AvailableCompressors_should_not_be_null() { var subject = new ConnectionDescription(__connectionId, __isMasterResultWithoutCompression, __buildInfoResult); subject.AvailableCompressors.Count.Should().Be(0); }
public void ServerVersion_should_return_buildInfoResult_ServerVersion() { var subject = new ConnectionDescription(__connectionId, __isMasterResult, __buildInfoResult); subject.ServerVersion.Should().Be(__buildInfoResult.ServerVersion); }
public void MaxMessageSize_should_return_isMasterResult_MaxMessageSize() { var subject = new ConnectionDescription(__connectionId, __isMasterResult, __buildInfoResult); subject.MaxMessageSize.Should().Be(__isMasterResult.MaxMessageSize); }
public void MaxBatchCount_should_return_isMasterResult_MaxBatchCount() { var subject = new ConnectionDescription(__connectionId, __isMasterResult, __buildInfoResult); subject.MaxBatchCount.Should().Be(__isMasterResult.MaxBatchCount); }
public void ConnectionId_should_return_ConnectionId() { var subject = new ConnectionDescription(__connectionId, __isMasterResult, __buildInfoResult); subject.ConnectionId.Should().Be(__connectionId); }
public void MaxDocumentSize_should_return_helloResult_MaxDocumentSize() { var subject = new ConnectionDescription(__connectionId, __helloResult, __buildInfoResult); subject.MaxDocumentSize.Should().Be(__helloResult.MaxDocumentSize); }
public async Task <ConnectionDescription> AuthenticateAsync(IConnection connection, ConnectionDescription description, CancellationToken cancellationToken) { Ensure.IsNotNull(connection, nameof(connection)); Ensure.IsNotNull(description, nameof(description)); var authenticators = GetAuthenticators(connection.Settings); await AuthenticationHelper.AuthenticateAsync(connection, description, authenticators, cancellationToken).ConfigureAwait(false); var connectionIdServerValue = description.HelloResult.ConnectionIdServerValue; if (connectionIdServerValue.HasValue) { description = UpdateConnectionIdWithServerValue(description, connectionIdServerValue.Value); } else { try { var getLastErrorProtocol = CreateGetLastErrorProtocol(_serverApi); var getLastErrorResult = await getLastErrorProtocol .ExecuteAsync(connection, cancellationToken) .ConfigureAwait(false); description = UpdateConnectionIdWithServerValue(description, getLastErrorResult); } catch { // if we couldn't get the server's connection id, so be it. } } return(description); }
public void ConnectionId_should_return_ConnectionId() { var subject = new ConnectionDescription(__connectionId, __helloResult); subject.ConnectionId.Should().Be(__connectionId); }
public void MinWireVersion_should_return_helloResult_MinWireVersion() { var subject = new ConnectionDescription(__connectionId, __helloResult); subject.MinWireVersion.Should().Be(__helloResult.MinWireVersion); }
public void MaxMessageSize_should_return_helloResult_MaxMessageSize() { var subject = new ConnectionDescription(__connectionId, __helloResult); subject.MaxMessageSize.Should().Be(__helloResult.MaxMessageSize); }
public void MaxBatchCount_should_return_helloResult_MaxBatchCount() { var subject = new ConnectionDescription(__connectionId, __helloResult); subject.MaxBatchCount.Should().Be(__helloResult.MaxBatchCount); }