コード例 #1
0
        public void Equals_should_return_true_when_all_fields_are_equal()
        {
            ServerDescription subject            = new ServerDescription(__serverId, __endPoint);
            ServerDescription serverDescription2 = new ServerDescription(__serverId, __endPoint);

            subject.Equals(serverDescription2).Should().BeTrue();
            subject.Equals((object)serverDescription2).Should().BeTrue();
            subject.GetHashCode().Should().Be(serverDescription2.GetHashCode());
        }
コード例 #2
0
        public void WithHeartbeat_should_return_new_instance_when_a_field_is_not_equal(string notEqualField)
        {
            var averageRoundTripTime = TimeSpan.FromSeconds(1);
            var replicaSetConfig     = new ReplicaSetConfig(
                new[] { new DnsEndPoint("localhost", 27017), new DnsEndPoint("localhost", 27018) },
                "name",
                new DnsEndPoint("localhost", 27017),
                1);
            var state            = ServerState.Connected;
            var tags             = new TagSet(new[] { new Tag("x", "a") });
            var type             = ServerType.ReplicaSetPrimary;
            var version          = new SemanticVersion(2, 6, 3);
            var wireVersionRange = new Range <int>(2, 3);

            var subject = new ServerDescription(
                __serverId,
                __endPoint,
                state: state,
                type: type,
                averageRoundTripTime: averageRoundTripTime,
                replicaSetConfig: replicaSetConfig,
                tags: tags,
                version: version,
                wireVersionRange: wireVersionRange);

            switch (notEqualField)
            {
            case "AverageRoundTripTime": averageRoundTripTime = averageRoundTripTime.Add(TimeSpan.FromSeconds(1)); break;

            case "ReplicaSetConfig": replicaSetConfig = new ReplicaSetConfig(replicaSetConfig.Members, "newname", replicaSetConfig.Primary, replicaSetConfig.Version); break;

            case "Tags": tags = new TagSet(new[] { new Tag("x", "b") }); break;

            case "Type": type = ServerType.ReplicaSetSecondary; break;

            case "Version": version = new SemanticVersion(version.Major, version.Minor, version.Patch + 1); break;

            case "WireVersionRange": wireVersionRange = new Range <int>(0, 0); break;
            }

            var serverDescription2 = subject.With(
                averageRoundTripTime: averageRoundTripTime,
                replicaSetConfig: replicaSetConfig,
                state: ServerState.Connected,
                tags: tags,
                type: type,
                version: version,
                wireVersionRange: wireVersionRange);

            subject.Equals(serverDescription2).Should().BeFalse();
            subject.Equals((object)serverDescription2).Should().BeFalse();
            subject.GetHashCode().Should().NotBe(serverDescription2.GetHashCode());
        }
コード例 #3
0
        public void Equals_should_return_true_when_all_fields_are_equal()
        {
            var lastUpdateTimestamp   = DateTime.UtcNow;
            ServerDescription subject = new ServerDescription(
                __serverId,
                __endPoint,
                type: ServerType.Standalone,
                lastUpdateTimestamp: lastUpdateTimestamp);
            ServerDescription serverDescription2 = new ServerDescription(
                __serverId,
                __endPoint,
                type: ServerType.Standalone,
                lastUpdateTimestamp: lastUpdateTimestamp);

            subject.Equals(serverDescription2).Should().BeTrue();
            subject.Equals((object)serverDescription2).Should().BeTrue();
            subject.GetHashCode().Should().Be(serverDescription2.GetHashCode());
        }
コード例 #4
0
        public void Equals_should_return_false_when_any_field_is_not_equal(string notEqualField)
        {
            var averageRoundTripTime  = TimeSpan.FromSeconds(1);
            var canonicalEndPoint     = new DnsEndPoint("localhost", 27017);
            var electionId            = new ElectionId(ObjectId.GenerateNewId());
            var endPoint              = new DnsEndPoint("localhost", 27017);
            var logicalSessionTimeout = TimeSpan.FromMinutes(1);
            var replicaSetConfig      = new ReplicaSetConfig(
                new[] { new DnsEndPoint("localhost", 27017), new DnsEndPoint("localhost", 27018) },
                "name",
                new DnsEndPoint("localhost", 27017),
                1);
            var serverId         = new ServerId(__clusterId, endPoint);
            var state            = ServerState.Connected;
            var tags             = new TagSet(new[] { new Tag("x", "a") });
            var type             = ServerType.ReplicaSetPrimary;
            var version          = new SemanticVersion(2, 6, 3);
            var wireVersionRange = new Range <int>(2, 3);

            var subject = new ServerDescription(
                serverId,
                endPoint,
                state: state,
                type: type,
                averageRoundTripTime: averageRoundTripTime,
                canonicalEndPoint: canonicalEndPoint,
                logicalSessionTimeout: logicalSessionTimeout,
                replicaSetConfig: replicaSetConfig,
                tags: tags,
                version: version,
                wireVersionRange: wireVersionRange);

            switch (notEqualField)
            {
            case "AverageRoundTripTime": averageRoundTripTime = averageRoundTripTime.Add(TimeSpan.FromSeconds(1)); break;

            case "CanonicalEndPoint": canonicalEndPoint = new DnsEndPoint("localhost", 27018); break;

            case "ElectionId": electionId = new ElectionId(ObjectId.Empty); break;

            case "EndPoint": endPoint = new DnsEndPoint(endPoint.Host, endPoint.Port + 1); serverId = new ServerId(__clusterId, endPoint); break;

            case "LogicalSessionTimeout": logicalSessionTimeout = TimeSpan.FromMinutes(2); break;

            case "ReplicaSetConfig": replicaSetConfig = new ReplicaSetConfig(replicaSetConfig.Members, "newname", replicaSetConfig.Primary, replicaSetConfig.Version); break;

            case "State": state = ServerState.Disconnected; break;

            case "ServerId": serverId = new ServerId(new ClusterId(), endPoint); break;

            case "Tags": tags = new TagSet(new[] { new Tag("x", "b") }); break;

            case "Type": type = ServerType.ReplicaSetSecondary; break;

            case "Version": version = new SemanticVersion(version.Major, version.Minor, version.Patch + 1); break;

            case "WireVersionRange": wireVersionRange = new Range <int>(0, 0); break;
            }

            var serverDescription2 = new ServerDescription(
                serverId,
                endPoint,
                state: state,
                type: type,
                averageRoundTripTime: averageRoundTripTime,
                canonicalEndPoint: canonicalEndPoint,
                electionId: electionId,
                logicalSessionTimeout: logicalSessionTimeout,
                replicaSetConfig: replicaSetConfig,
                tags: tags,
                version: version,
                wireVersionRange: wireVersionRange);

            subject.Equals(serverDescription2).Should().BeFalse();
            subject.Equals((object)serverDescription2).Should().BeFalse();
            subject.GetHashCode().Should().NotBe(serverDescription2.GetHashCode());
        }