Пример #1
0
        public void Constructor_with_multiple_parameters_should_return_properly_initialized_instance()
        {
            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);

            subject.AverageRoundTripTime.Should().Be(TimeSpan.FromSeconds(1));
            subject.EndPoint.Should().Be(__endPoint);
            subject.ReplicaSetConfig.Should().Be(replicaSetConfig);
            subject.ServerId.Should().Be(__serverId);
            subject.State.Should().Be(state);
            subject.Tags.Should().Be(tags);
            subject.Type.Should().Be(type);
        }
Пример #2
0
        public void WithHeartbeat_should_return_same_instance_when_all_fields_are_equal()
        {
            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>(0, 2);

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

            var serverDescription2 = subject.WithHeartbeatInfo(averageRoundTripTime, replicaSetConfig, tags, type, version, wireVersionRange);

            serverDescription2.Should().BeSameAs(subject);
        }
Пример #3
0
        private ServerDescription(
            TimeSpan averageRoundTripTime,
            EndPoint endPoint,
            ReplicaSetConfig replicaSetConfig,
            ServerId serverId,
            ServerState state,
            TagSet tags,
            ServerType type,
            SemanticVersion version,
            Range <int> wireVersionRange)
        {
            Ensure.IsNotNull(endPoint, "endPoint");
            Ensure.IsNotNull(serverId, "serverId");
            if (!endPoint.Equals(serverId.EndPoint))
            {
                throw new ArgumentException("EndPoint and ServerId.EndPoint must match.");
            }

            _averageRoundTripTime = averageRoundTripTime;
            _endPoint             = endPoint;
            _replicaSetConfig     = replicaSetConfig;
            _serverId             = serverId;
            _state            = state;
            _tags             = tags;
            _type             = type;
            _version          = version;
            _wireVersionRange = wireVersionRange;
        }
Пример #4
0
 public ServerDescription WithHeartbeatInfo(
     TimeSpan averageRoundTripTime,
     ReplicaSetConfig replicaSetConfig,
     TagSet tags,
     ServerType type,
     SemanticVersion version,
     Range <int> wireVersionRange)
 {
     if (_state == ServerState.Connected &&
         _averageRoundTripTime == averageRoundTripTime &&
         object.Equals(_replicaSetConfig, replicaSetConfig) &&
         object.Equals(_tags, tags) &&
         _type == type &&
         object.Equals(_version, version) &&
         object.Equals(_wireVersionRange, wireVersionRange))
     {
         return(this);
     }
     else
     {
         return(new ServerDescription(
                    averageRoundTripTime,
                    _endPoint,
                    replicaSetConfig,
                    _serverId,
                    ServerState.Connected,
                    tags,
                    type,
                    version,
                    wireVersionRange));
     }
 }
Пример #5
0
        // constructors
        /// <summary>
        /// Initializes a new instance of the <see cref="ServerDescription" /> class.
        /// </summary>
        /// <param name="serverId">The server identifier.</param>
        /// <param name="endPoint">The end point.</param>
        /// <param name="reasonChanged">The reason the server description was last changed.</param>
        /// <param name="averageRoundTripTime">The average round trip time.</param>
        /// <param name="canonicalEndPoint">The canonical end point.</param>
        /// <param name="electionId">The election identifier.</param>
        /// <param name="heartbeatException">The heartbeat exception.</param>
        /// <param name="heartbeatInterval">The heartbeat interval.</param>
        /// <param name="helloOk">Whether the server supports the hello command.</param>
        /// <param name="lastHeartbeatTimestamp">The last heartbeat timestamp.</param>
        /// <param name="lastUpdateTimestamp">The last update timestamp.</param>
        /// <param name="lastWriteTimestamp">The last write timestamp.</param>
        /// <param name="logicalSessionTimeout">The logical session timeout.</param>
        /// <param name="maxBatchCount">The maximum batch count.</param>
        /// <param name="maxDocumentSize">The maximum size of a document.</param>
        /// <param name="maxMessageSize">The maximum size of a message.</param>
        /// <param name="maxWireDocumentSize">The maximum size of a wire document.</param>
        /// <param name="replicaSetConfig">The replica set configuration.</param>
        /// <param name="state">The server state.</param>
        /// <param name="tags">The replica set tags.</param>
        /// <param name="topologyVersion">The topology version.</param>
        /// <param name="type">The server type.</param>
        /// <param name="version">The server version.</param>
        /// <param name="wireVersionRange">The wire version range.</param>
        /// <exception cref="ArgumentException">EndPoint and ServerId.EndPoint must match.</exception>
        public ServerDescription(
            ServerId serverId,
            EndPoint endPoint,
            Optional <string> reasonChanged          = default(Optional <string>),
            Optional <TimeSpan> averageRoundTripTime = default(Optional <TimeSpan>),
            Optional <EndPoint> canonicalEndPoint    = default(Optional <EndPoint>),
            Optional <ElectionId> electionId         = default(Optional <ElectionId>),
            Optional <Exception> heartbeatException  = default(Optional <Exception>),
            Optional <TimeSpan> heartbeatInterval    = default(Optional <TimeSpan>),
            Optional <bool> helloOk = default(Optional <bool>),
            Optional <DateTime?> lastHeartbeatTimestamp = default(Optional <DateTime?>),
            Optional <DateTime> lastUpdateTimestamp     = default(Optional <DateTime>),
            Optional <DateTime?> lastWriteTimestamp     = default(Optional <DateTime?>),
            Optional <TimeSpan?> logicalSessionTimeout  = default(Optional <TimeSpan?>),
            Optional <int> maxBatchCount                 = default(Optional <int>),
            Optional <int> maxDocumentSize               = default(Optional <int>),
            Optional <int> maxMessageSize                = default(Optional <int>),
            Optional <int> maxWireDocumentSize           = default(Optional <int>),
            Optional <ReplicaSetConfig> replicaSetConfig = default(Optional <ReplicaSetConfig>),
            Optional <ServerState> state                 = default(Optional <ServerState>),
            Optional <TagSet> tags = default(Optional <TagSet>),
            Optional <TopologyVersion> topologyVersion = default(Optional <TopologyVersion>),
            Optional <ServerType> type               = default(Optional <ServerType>),
            Optional <SemanticVersion> version       = default(Optional <SemanticVersion>),
            Optional <Range <int> > wireVersionRange = default(Optional <Range <int> >))
        {
            Ensure.IsNotNull(endPoint, nameof(endPoint));
            Ensure.IsNotNull(serverId, nameof(serverId));
            if (!EndPointHelper.Equals(endPoint, serverId.EndPoint))
            {
                throw new ArgumentException("EndPoint and ServerId.EndPoint must match.");
            }

            _averageRoundTripTime = averageRoundTripTime.WithDefault(TimeSpan.Zero);
            _canonicalEndPoint    = canonicalEndPoint.WithDefault(null);
            _electionId           = electionId.WithDefault(null);
            _endPoint             = endPoint;
            _heartbeatException   = heartbeatException.WithDefault(null);
            _heartbeatInterval    = heartbeatInterval.WithDefault(TimeSpan.Zero);
            _helloOk = helloOk.WithDefault(false);
            _lastHeartbeatTimestamp = lastHeartbeatTimestamp.WithDefault(null);
            _lastUpdateTimestamp    = lastUpdateTimestamp.WithDefault(DateTime.UtcNow);
            _lastWriteTimestamp     = lastWriteTimestamp.WithDefault(null);
            _logicalSessionTimeout  = logicalSessionTimeout.WithDefault(null);
            _maxBatchCount          = maxBatchCount.WithDefault(1000);
            _maxDocumentSize        = maxDocumentSize.WithDefault(4 * 1024 * 1024);
            _maxMessageSize         = maxMessageSize.WithDefault(Math.Max(_maxDocumentSize + 1024, 16000000));
            _maxWireDocumentSize    = maxWireDocumentSize.WithDefault(_maxDocumentSize + 16 * 1024);
            _reasonChanged          = reasonChanged.WithDefault("NotSpecified");
            _replicaSetConfig       = replicaSetConfig.WithDefault(null);
            _serverId         = serverId;
            _state            = state.WithDefault(ServerState.Disconnected);
            _tags             = tags.WithDefault(null);
            _topologyVersion  = topologyVersion.WithDefault(null);
            _type             = type.WithDefault(ServerType.Unknown);
            _version          = version.WithDefault(null);
            _wireVersionRange = wireVersionRange.WithDefault(null);
        }
Пример #6
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());
        }
        public void Constructor_with_multiple_parameters_should_return_properly_initialized_instance()
        {
            var averageRoundTripTime = TimeSpan.FromSeconds(1);
            var canonicalEndPoint    = new DnsEndPoint("localhost", 27017);
            var electionId           = new ElectionId(ObjectId.GenerateNewId());
            var helloOk = true;
            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 state            = ServerState.Connected;
            var tags             = new TagSet(new[] { new Tag("x", "a") });
            var type             = ServerType.ReplicaSetPrimary;
            var version          = new SemanticVersion(3, 6, 0);
            var wireVersionRange = new Range <int>(6, 14);

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

            subject.AverageRoundTripTime.Should().Be(TimeSpan.FromSeconds(1));
            subject.CanonicalEndPoint.Should().Be(canonicalEndPoint);
            subject.ElectionId.Should().Be(electionId);
            subject.EndPoint.Should().Be(__endPoint);
            subject.HelloOk.Should().Be(helloOk);
            subject.LogicalSessionTimeout.Should().Be(logicalSessionTimeout);
            subject.ReplicaSetConfig.Should().Be(replicaSetConfig);
            subject.ServerId.Should().Be(__serverId);
            subject.State.Should().Be(state);
            subject.Tags.Should().Be(tags);
            subject.Type.Should().Be(type);
        }
Пример #8
0
        // constructors
        /// <summary>
        /// Initializes a new instance of the <see cref="ServerDescription" /> class.
        /// </summary>
        /// <param name="serverId">The server identifier.</param>
        /// <param name="endPoint">The end point.</param>
        /// <param name="averageRoundTripTime">The average round trip time.</param>
        /// <param name="canonicalEndPoint">The canonical end point.</param>
        /// <param name="electionId">The election identifier.</param>
        /// <param name="heartbeatException">The heartbeat exception.</param>
        /// <param name="maxBatchCount">The maximum batch count.</param>
        /// <param name="maxDocumentSize">The maximum size of a document.</param>
        /// <param name="maxMessageSize">The maximum size of a message.</param>
        /// <param name="maxWireDocumentSize">The maximum size of a wire document.</param>
        /// <param name="replicaSetConfig">The replica set configuration.</param>
        /// <param name="state">The server state.</param>
        /// <param name="tags">The replica set tags.</param>
        /// <param name="type">The server type.</param>
        /// <param name="version">The server version.</param>
        /// <param name="wireVersionRange">The wire version range.</param>
        /// <exception cref="System.ArgumentException">EndPoint and ServerId.EndPoint must match.</exception>
        public ServerDescription(
            ServerId serverId,
            EndPoint endPoint,
            Optional <TimeSpan> averageRoundTripTime     = default(Optional <TimeSpan>),
            Optional <EndPoint> canonicalEndPoint        = default(Optional <EndPoint>),
            Optional <ElectionId> electionId             = default(Optional <ElectionId>),
            Optional <Exception> heartbeatException      = default(Optional <Exception>),
            Optional <int> maxBatchCount                 = default(Optional <int>),
            Optional <int> maxDocumentSize               = default(Optional <int>),
            Optional <int> maxMessageSize                = default(Optional <int>),
            Optional <int> maxWireDocumentSize           = default(Optional <int>),
            Optional <ReplicaSetConfig> replicaSetConfig = default(Optional <ReplicaSetConfig>),
            Optional <ServerState> state                 = default(Optional <ServerState>),
            Optional <TagSet> tags                   = default(Optional <TagSet>),
            Optional <ServerType> type               = default(Optional <ServerType>),
            Optional <SemanticVersion> version       = default(Optional <SemanticVersion>),
            Optional <Range <int> > wireVersionRange = default(Optional <Range <int> >))
        {
            Ensure.IsNotNull(endPoint, "endPoint");
            Ensure.IsNotNull(serverId, "serverId");
            if (!EndPointHelper.Equals(endPoint, serverId.EndPoint))
            {
                throw new ArgumentException("EndPoint and ServerId.EndPoint must match.");
            }

            _averageRoundTripTime = averageRoundTripTime.WithDefault(TimeSpan.Zero);
            _canonicalEndPoint    = canonicalEndPoint.WithDefault(null);
            _electionId           = electionId.WithDefault(null);
            _endPoint             = endPoint;
            _heartbeatException   = heartbeatException.WithDefault(null);
            _maxBatchCount        = maxBatchCount.WithDefault(1000);
            _maxDocumentSize      = maxDocumentSize.WithDefault(4 * 1024 * 1024);
            _maxMessageSize       = maxMessageSize.WithDefault(Math.Max(_maxDocumentSize + 1024, 16000000));
            _maxWireDocumentSize  = maxWireDocumentSize.WithDefault(_maxDocumentSize + 16 * 1024);
            _replicaSetConfig     = replicaSetConfig.WithDefault(null);
            _serverId             = serverId;
            _state            = state.WithDefault(ServerState.Disconnected);
            _tags             = tags.WithDefault(null);
            _type             = type.WithDefault(ServerType.Unknown);
            _version          = version.WithDefault(null);
            _wireVersionRange = wireVersionRange.WithDefault(null);
        }
        public void With_should_return_same_instance_when_all_fields_are_equal()
        {
            var averageRoundTripTime = TimeSpan.FromSeconds(1);
            var helloOk             = true;
            var lastUpdateTimestamp = DateTime.UtcNow;
            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(3, 6, 0);
            var wireVersionRange = new Range <int>(6, 14);

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

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

            result.ShouldBeEquivalentTo(subject);
        }
Пример #10
0
 public ServerDescription(
     ServerId serverId,
     EndPoint endPoint,
     ServerState state,
     ServerType type,
     TimeSpan averageRoundTripTime,
     ReplicaSetConfig replicaSetConfig,
     TagSet tags,
     SemanticVersion version,
     Range <int> wireVersionRange)
     : this(
         averageRoundTripTime,
         endPoint,
         replicaSetConfig,
         serverId,
         state,
         tags,
         type,
         version,
         wireVersionRange)
 {
 }
Пример #11
0
        public void With_should_return_new_instance_when_a_field_is_not_equal(string notEqualField)
        {
            var averageRoundTripTime  = TimeSpan.FromSeconds(1);
            var canonicalEndPoint     = new DnsEndPoint("localhost", 27017);
            var electionId            = new ElectionId(ObjectId.GenerateNewId());
            var heartbeatException    = new Exception();
            var heartbeatInterval     = TimeSpan.FromSeconds(10);
            var lastUpdateTimestamp   = DateTime.UtcNow;
            var lastWriteTimestamp    = DateTime.UtcNow;
            var logicalSessionTimeout = TimeSpan.FromMinutes(1);
            var maxBatchCount         = 1000;
            var maxDocumentSize       = 16000000;
            var maxMessageSize        = 48000000;
            var maxWireDocumentSize   = 16000000;
            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,
                averageRoundTripTime: averageRoundTripTime,
                canonicalEndPoint: canonicalEndPoint,
                electionId: electionId,
                heartbeatException: heartbeatException,
                heartbeatInterval: heartbeatInterval,
                lastUpdateTimestamp: lastUpdateTimestamp,
                lastWriteTimestamp: lastWriteTimestamp,
                logicalSessionTimeout: logicalSessionTimeout,
                maxBatchCount: maxBatchCount,
                maxDocumentSize: maxDocumentSize,
                maxMessageSize: maxMessageSize,
                maxWireDocumentSize: maxWireDocumentSize,
                replicaSetConfig: replicaSetConfig,
                state: state,
                tags: tags,
                type: type,
                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 "HeartbeatException": heartbeatException = new Exception(); break;

            case "HeartbeatInterval": heartbeatInterval = TimeSpan.FromSeconds(11); break;

            case "LastUpdateTimestamp": lastUpdateTimestamp = lastUpdateTimestamp.Add(TimeSpan.FromSeconds(1)); break;

            case "LastWriteTimestamp": lastWriteTimestamp = lastWriteTimestamp.Add(TimeSpan.FromSeconds(1)); break;

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

            case "MaxBatchCount": maxBatchCount += 1; break;

            case "MaxDocumentSize": maxDocumentSize += 1; break;

            case "MaxMessageSize": maxMessageSize += 1; break;

            case "MaxWireDocumentSize": maxWireDocumentSize += 1; break;

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

            case "State": state = ServerState.Disconnected; 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 result = subject.With(
                averageRoundTripTime: averageRoundTripTime,
                canonicalEndPoint: canonicalEndPoint,
                electionId: electionId,
                heartbeatException: heartbeatException,
                heartbeatInterval: heartbeatInterval,
                lastUpdateTimestamp: lastUpdateTimestamp,
                lastWriteTimestamp: lastWriteTimestamp,
                logicalSessionTimeout: logicalSessionTimeout,
                maxBatchCount: maxBatchCount,
                maxDocumentSize: maxDocumentSize,
                maxMessageSize: maxMessageSize,
                maxWireDocumentSize: maxWireDocumentSize,
                replicaSetConfig: replicaSetConfig,
                state: state,
                tags: tags,
                type: type,
                version: version,
                wireVersionRange: wireVersionRange);

            result.Should().NotBeSameAs(subject);
            result.Equals(subject).Should().BeFalse();
            result.Equals((object)subject).Should().BeFalse();
            result.GetHashCode().Should().NotBe(subject.GetHashCode());
        }
Пример #12
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());
        }