/// <summary>
        /// Gets the hash code.
        /// </summary>
        /// <returns>The hash code.</returns>
        public override int GetHashCode()
        {
            if (_isFrozen)
            {
                return(_frozenHashCode);
            }

            // see Effective Java by Joshua Bloch
            int hash = 17;

            hash = 37 * hash + _connectionMode.GetHashCode();
            hash = 37 * hash + _connectTimeout.GetHashCode();
            hash = 37 * hash + _credentialsStore.GetHashCode();
            hash = 37 * hash + ((_defaultCredentials == null) ? 0 : _defaultCredentials.GetHashCode());
            hash = 37 * hash + _guidRepresentation.GetHashCode();
            hash = 37 * hash + _ipv6.GetHashCode();
            hash = 37 * hash + _maxConnectionIdleTime.GetHashCode();
            hash = 37 * hash + _maxConnectionLifeTime.GetHashCode();
            hash = 37 * hash + _maxConnectionPoolSize.GetHashCode();
            hash = 37 * hash + _minConnectionPoolSize.GetHashCode();
            hash = 37 * hash + _readPreference.GetHashCode();
            hash = 37 * hash + ((_replicaSetName == null) ? 0 : _replicaSetName.GetHashCode());
            hash = 37 * hash + _secondaryAcceptableLatency.GetHashCode();
            foreach (var server in _servers)
            {
                hash = 37 * hash + server.GetHashCode();
            }
            hash = 37 * hash + _socketTimeout.GetHashCode();
            hash = 37 * hash + _useSsl.GetHashCode();
            hash = 37 * hash + _verifySslCertificate.GetHashCode();
            hash = 37 * hash + _waitQueueSize.GetHashCode();
            hash = 37 * hash + _waitQueueTimeout.GetHashCode();
            hash = 37 * hash + _writeConcern.GetHashCode();
            return(hash);
        }
Exemplo n.º 2
0
        public void Equals_should_return_false_when_any_fields_are_not_equal(
            [Values("fsync", "journal", "w", "wTimeout")]
            string notEqualFieldName)
        {
            var          subject1 = new WriteConcern(1, TimeSpan.FromSeconds(1), false, false);
            WriteConcern subject2;

            switch (notEqualFieldName)
            {
            case "fsync": subject2 = subject1.With(fsync: true); break;

            case "journal": subject2 = subject1.With(journal: true); break;

            case "w": subject2 = subject1.With(w: 2); break;

            case "wTimeout": subject2 = subject1.With(wTimeout: TimeSpan.FromSeconds(2)); break;

            default: throw new ArgumentException("notEqualFieldName");
            }

            var result1   = subject1.Equals(subject2);
            var result2   = subject1.Equals((object)subject2);
            var hashCode1 = subject1.GetHashCode();
            var hashCode2 = subject2.GetHashCode();

            result1.Should().BeFalse();
            result2.Should().BeFalse();
            hashCode1.Should().NotBe(hashCode2);
        }
Exemplo n.º 3
0
        public void Equals_should_return_false_if_journal_is_not_equal(bool?journal1, bool?journal2)
        {
            var writeConcern1 = new WriteConcern(null, null, null, journal1);
            var writeConcern2 = new WriteConcern(null, null, null, journal2);

            writeConcern1.Equals((WriteConcern)writeConcern2).Should().BeFalse();
            writeConcern1.Equals((object)writeConcern2).Should().BeFalse();
            writeConcern1.GetHashCode().Should().NotBe(writeConcern2.GetHashCode());
        }
Exemplo n.º 4
0
        public void Equals_should_return_false_if_fsync_is_not_equal(bool?fsync1, bool?fsync2)
        {
            var writeConcern1 = new WriteConcern(null, null, fsync1, null);
            var writeConcern2 = new WriteConcern(null, null, fsync2, null);

            writeConcern1.Equals((WriteConcern)writeConcern2).Should().BeFalse();
            writeConcern1.Equals((object)writeConcern2).Should().BeFalse();
            writeConcern1.GetHashCode().Should().NotBe(writeConcern2.GetHashCode());
        }
Exemplo n.º 5
0
        public void Equals_should_return_false_if_wTimeout_is_not_equal(int?wTimeout1Seconds, int?wTimeout2Seconds)
        {
            var wTimeout1     = wTimeout1Seconds.HasValue ? (TimeSpan?)TimeSpan.FromSeconds(wTimeout1Seconds.Value) : null;
            var wTimeout2     = wTimeout2Seconds.HasValue ? (TimeSpan?)TimeSpan.FromSeconds(wTimeout2Seconds.Value) : null;
            var writeConcern1 = new WriteConcern(null, wTimeout1, null, null);
            var writeConcern2 = new WriteConcern(null, wTimeout2, null, null);

            writeConcern1.Equals((WriteConcern)writeConcern2).Should().BeFalse();
            writeConcern1.Equals((object)writeConcern2).Should().BeFalse();
            writeConcern1.GetHashCode().Should().NotBe(writeConcern2.GetHashCode());
        }
Exemplo n.º 6
0
        public void Equals_should_return_false_if_w_is_not_equal(int?w1, int?w2)
        {
            var wCount1       = w1.HasValue ? (WriteConcern.WValue)w1.Value : null;
            var wCount2       = w2.HasValue ? (WriteConcern.WValue)w2.Value : null;
            var writeConcern1 = new WriteConcern(wCount1, null, null, null);
            var writeConcern2 = new WriteConcern(wCount2, null, null, null);

            writeConcern1.Equals((WriteConcern)writeConcern2).Should().BeFalse();
            writeConcern1.Equals((object)writeConcern2).Should().BeFalse();
            writeConcern1.GetHashCode().Should().NotBe(writeConcern2.GetHashCode());
        }
Exemplo n.º 7
0
        public void Equals_should_return_true_if_all_fields_are_equal(int?w, int?wTimeoutSeconds, bool?fsync, bool?journal)
        {
            var wCount        = w.HasValue ? (WriteConcern.WValue)w.Value : null;
            var wTimeout      = wTimeoutSeconds.HasValue ? (TimeSpan?)TimeSpan.FromSeconds(wTimeoutSeconds.Value) : null;
            var writeConcern1 = new WriteConcern(wCount, wTimeout, fsync, journal);
            var writeConcern2 = new WriteConcern(wCount, wTimeout, fsync, journal);

            writeConcern1.Equals((WriteConcern)writeConcern2).Should().BeTrue();
            writeConcern1.Equals((object)writeConcern2).Should().BeTrue();
            writeConcern1.GetHashCode().Should().Be(writeConcern2.GetHashCode());
        }
Exemplo n.º 8
0
        public void Equals_should_return_true_when_all_fields_are_equal()
        {
            var subject1 = new WriteConcern(1, TimeSpan.FromSeconds(1), false, false);
            var subject2 = new WriteConcern(1, TimeSpan.FromSeconds(1), false, false);

            var result1   = subject1.Equals(subject2);
            var result2   = subject1.Equals((object)subject2);
            var hashCode1 = subject1.GetHashCode();
            var hashCode2 = subject2.GetHashCode();

            result1.Should().BeTrue();
            result2.Should().BeTrue();
            hashCode1.Should().Be(hashCode2);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets the hash code.
        /// </summary>
        /// <returns>The hash code.</returns>
        public override int GetHashCode()
        {
            if (_isFrozen)
            {
                return(_frozenHashCode);
            }

            // see Effective Java by Joshua Bloch
            int hash = 17;

            hash = 37 * hash + _databaseName.GetHashCode();
            hash = 37 * hash + ((_credentials != null) ? _credentials.GetHashCode() : 0);
            hash = 37 * hash + _guidRepresentation.GetHashCode();
            hash = 37 * hash + _readPreference.GetHashCode();
            hash = 37 * hash + _writeConcern.GetHashCode();
            return(hash);
        }
        /// <summary>
        /// Gets the hash code.
        /// </summary>
        /// <returns>The hash code.</returns>
        public override int GetHashCode()
        {
            if (_isFrozen)
            {
                return(_frozenHashCode);
            }

            // see Effective Java by Joshua Bloch
            int hash = 17;

            hash = 37 * hash + _collectionName.GetHashCode();
            hash = 37 * hash + _assignIdOnInsert.GetHashCode();
            hash = 37 * hash + _defaultDocumentType.GetHashCode();
            hash = 37 * hash + _guidRepresentation.GetHashCode();
            hash = 37 * hash + _readPreference.GetHashCode();
            hash = 37 * hash + _writeConcern.GetHashCode();
            return(hash);
        }