public void Equals_should_be_false_when_both_have_different_results() { var subject1 = new HelloResult(new BsonDocument("x", 1)); var subject2 = new HelloResult(new BsonDocument("x", 2)); subject1.Equals(subject2).Should().BeFalse(); }
public void GetReplicaSetConfig_should_return_correct_info_when_the_server_is_a_replica_set() { var doc = new BsonDocument { { "ok", 1 }, { "setName", "funny" }, { "primary", "localhost:1000" }, { "hosts", new BsonArray(new [] { "localhost:1000", "localhost:1001" }) }, { "passives", new BsonArray(new [] { "localhost:1002" }) }, { "arbiters", new BsonArray(new [] { "localhost:1003" }) }, { "setVersion", 20 } }; var subject = new HelloResult(doc); var config = subject.GetReplicaSetConfig(); config.Name.Should().Be("funny"); config.Primary.Should().Be(new DnsEndPoint("localhost", 1000)); config.Members.Should().BeEquivalentTo( new DnsEndPoint("localhost", 1000), new DnsEndPoint("localhost", 1001), new DnsEndPoint("localhost", 1002), new DnsEndPoint("localhost", 1003)); config.Version.Should().Be(20); }
public void Wrapped_should_return_the_document_passed_in_the_constructor() { var doc = new BsonDocument(); var subject = new HelloResult(doc); subject.Wrapped.Should().BeSameAs(doc); }
public void Equals_should_be_true_when_both_have_the_same_result() { var subject1 = new HelloResult(new BsonDocument("x", 1)); var subject2 = new HelloResult(new BsonDocument("x", 1)); subject1.Equals(subject2).Should().BeTrue(); }
public void ElectionId_should_parse_document_correctly(string json, string expectedObjectId) { var subject = new HelloResult(BsonDocument.Parse(json)); var expected = expectedObjectId == null ? (ElectionId)null : new ElectionId(ObjectId.Parse(expectedObjectId)); subject.ElectionId.Should().Be(expected); }
public void Tags_should_parse_document_correctly() { var subject = new HelloResult(BsonDocument.Parse("{ tags: { a: \"one\", b: \"two\" } }")); var expected = new TagSet(new[] { new Tag("a", "one"), new Tag("b", "two") }); subject.Tags.Should().Be(expected); }
public void Compression_should_parse_document_correctly(string json, CompressorType[] expectedCompression) { var subject = new HelloResult(BsonDocument.Parse(json)); var result = subject.Compressions; result.Should().Equal(expectedCompression); }
public void Me_should_parse_document_correctly(string json, string expectedEndPoint) { var endPoint = expectedEndPoint == null ? (EndPoint)null : EndPointHelper.Parse(expectedEndPoint); var subject = new HelloResult(BsonDocument.Parse(json)); subject.Me.Should().Be(endPoint); }
public void LogicalSessionTimeout_should_parse_document_correctly(string json, int?expectedResultMinutes) { var subject = new HelloResult(BsonDocument.Parse(json)); var expectedResult = expectedResultMinutes == null ? (TimeSpan?)null : TimeSpan.FromMinutes(expectedResultMinutes.Value); var result = subject.LogicalSessionTimeout; result.Should().Be(expectedResult); }
public void Compression_should_throw_the_exception_for_an_unsupported_compression_type(string json, string expectedUnsupportedCompressor) { var subject = new HelloResult(BsonDocument.Parse(json)); var exception = Record.Exception(() => subject.Compressions); var e = exception.Should().BeOfType <NotSupportedException>().Subject; e.Message.Should().Be($"The unsupported compressor name: '{expectedUnsupportedCompressor}'."); }
public void ServiceId_should_parse_document_correctly(string json, bool shouldBeParsed) { var subject = new HelloResult(BsonDocument.Parse(json)); subject.ServiceId.HasValue.Should().Be(shouldBeParsed); if (shouldBeParsed) { subject.ServiceId.Should().Be(ObjectId.Empty); } }
public void LastWriteTimestamp_should_parse_document_correctly(string json, int?expectedYear) { var subject = new HelloResult(BsonDocument.Parse(json)); var result = subject.LastWriteTimestamp; var expectedResult = expectedYear.HasValue ? new DateTime(expectedYear.Value, 1, 1, 0, 0, 0, DateTimeKind.Utc) : (DateTime?)null; result.Should().Be(expectedResult); }
public void HelloOk_should_return_false_when_response_does_not_contain_helloOk() { var doc = new BsonDocument { { "ok", 1 } }; var subject = new HelloResult(doc); subject.HelloOk.Should().BeFalse(); }
public void HelloOk_should_return_true_when_response_contains_helloOk_true() { var doc = new BsonDocument { { "ok", 1 }, { "helloOk", true } }; var subject = new HelloResult(doc); subject.HelloOk.Should().BeTrue(); }
// constructors /// <summary> /// Initializes a new instance of the <see cref="ConnectionDescription"/> class. /// </summary> /// <param name="connectionId">The connection identifier.</param> /// <param name="helloResult">The hello result.</param> /// <param name="buildInfoResult">The buildInfo result.</param> public ConnectionDescription(ConnectionId connectionId, HelloResult helloResult, BuildInfoResult buildInfoResult) { _connectionId = Ensure.IsNotNull(connectionId, nameof(connectionId)); _buildInfoResult = Ensure.IsNotNull(buildInfoResult, nameof(buildInfoResult)); _helloResult = Ensure.IsNotNull(helloResult, nameof(helloResult)); _compressors = Ensure.IsNotNull(_helloResult.Compressions, "compressions"); _maxBatchCount = helloResult.MaxBatchCount; _maxDocumentSize = helloResult.MaxDocumentSize; _maxMessageSize = helloResult.MaxMessageSize; _serviceId = helloResult.ServiceId; _serverVersion = buildInfoResult.ServerVersion; }
public void WithConnectionId_should_return_new_instance_even_when_only_the_serverValue_differs() { var clusterId = new ClusterId(); var serverId = new ServerId(clusterId, new DnsEndPoint("localhost", 1)); var connectionId1 = new ConnectionId(serverId, 1); var connectionId2 = new ConnectionId(serverId, 1).WithServerValue(2); var helloResult = new HelloResult(new BsonDocument("maxWireVersion", WireVersion.Server36)); var subject = new ConnectionDescription(connectionId1, helloResult); var result = subject.WithConnectionId(connectionId2); result.Should().NotBeSameAs(subject); result.ConnectionId.Should().BeSameAs(connectionId2); }
public void Equals_should_return_correct_results() { var connectionId1 = new ConnectionId(new ServerId(new ClusterId(), new DnsEndPoint("localhost", 27018)), 10); var connectionId2 = new ConnectionId(new ServerId(new ClusterId(), new DnsEndPoint("localhost", 27018)), 10); var helloResult1 = new HelloResult(new BsonDocument("x", 1)); var helloResult2 = new HelloResult(new BsonDocument("x", 2)); var subject1 = new ConnectionDescription(connectionId1, helloResult1); var subject2 = new ConnectionDescription(connectionId1, helloResult1); var subject3 = new ConnectionDescription(connectionId1, helloResult2); var subject4 = new ConnectionDescription(connectionId2, helloResult1); subject1.Equals(subject2).Should().BeTrue(); subject1.Equals(subject3).Should().BeFalse(); subject1.Equals(subject4).Should().BeFalse(); }
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 } }); var buildInfoResult = new BuildInfoResult(new BsonDocument { { "ok", 1 }, { "version", "3.6.0" } }); _connectionDescription = new ConnectionDescription(connectionId, helloResult, buildInfoResult); _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); }
public void MaxMessageSize_should_parse_document_correctly(string json, int expected) { var subject = new HelloResult(BsonDocument.Parse(json)); subject.MaxMessageSize.Should().Be(expected); }
public void MinWireVersion_should_parse_document_correctly(string json, int expected) { var subject = new HelloResult(BsonDocument.Parse(json)); subject.MinWireVersion.Should().Be(expected); }
public void ServerType_should_parse_document_correctly(string json, ServerType expected) { var subject = new HelloResult(BsonDocument.Parse(json)); subject.ServerType.Should().Be(expected); }
public void Tags_should_be_null_when_no_tags_exist() { var subject = new HelloResult(new BsonDocument()); subject.Tags.Should().BeNull(); }