public void Equals_should_return_false_when_any_field_is_not_equal( [Values("mode", "tagSets")] string notEqualFieldName) { var mode = ReadPreferenceMode.Secondary; var tagSets = new[] { new TagSet(new[] { new Tag("name", "value1") }) }; var subject1 = new ReadPreference(mode, tagSets); switch (notEqualFieldName) { case "mode": mode = ReadPreferenceMode.SecondaryPreferred; break; case "tagSets": tagSets = new[] { new TagSet(new[] { new Tag("name", "value2") }) }; break; default: throw new ArgumentException("notEqualFieldName"); } var subject2 = new ReadPreference(mode, tagSets); 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); }
/// <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); }
// private methods private void Equals_Act_and_Assert(ReadPreference lhs, ReadPreference rhs, bool expectedResult) { var result1 = lhs.Equals(rhs); var result2 = lhs.Equals((object)rhs); var hashCode1 = lhs.GetHashCode(); var hashCode2 = rhs.GetHashCode(); result1.Should().Be(expectedResult); result2.Should().Be(expectedResult); (hashCode1 == hashCode2).Should().Be(expectedResult); }
public void Equals_should_return_true_when_all_fields_are_equal() { var mode = ReadPreferenceMode.Secondary; var tagSets = new[] { new TagSet(new[] { new Tag("name", "value") }) }; var subject1 = new ReadPreference(mode, tagSets); var subject2 = new ReadPreference(mode, tagSets); 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); }
/// <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 + _safeMode.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 + _safeMode.GetHashCode(); return(hash); }