public void HashCodeInvariantCultureCaseInsensitive() { // Arrange var comparer = CharacterComparer.Create(CultureInfo.InvariantCulture, ignoreCase: true); // Act var objectHashCode = comparer.GetHashCode((object)'h'); var objectHashCode2 = comparer.GetHashCode((object)'h'); var objectHashCode3 = comparer.GetHashCode((object)'H'); var charHashCode = comparer.GetHashCode('h'); var charHashCode2 = comparer.GetHashCode('h'); var charHashCode3 = comparer.GetHashCode('H'); // Assert comparer.Should().NotBeNull(); objectHashCode.Should().Be(objectHashCode2); objectHashCode.Should().Be(objectHashCode3); charHashCode.Should().Be(charHashCode2); charHashCode.Should().Be(charHashCode3); objectHashCode.Should().Be(charHashCode); objectHashCode2.Should().Be(charHashCode2); objectHashCode3.Should().Be(charHashCode3); objectHashCode.Should().Be(charHashCode2); objectHashCode.Should().Be(charHashCode3); objectHashCode3.Should().Be(charHashCode); }
public void InvalidCreationArguments() { // Arrange // Act Action nullCreationArgumentAct = () => CharacterComparer.Create(null, ignoreCase: true); // Assert nullCreationArgumentAct.Should().ThrowExactly <ArgumentNullException>(); }
public void InvalidHasCodeArguments() { // Arrange var comparer = CharacterComparer.Create(CultureInfo.InvariantCulture, ignoreCase: true); // Act Action nullHashCodeAct = () => comparer.GetHashCode(null); Action nullHashCodeAct2 = () => comparer.GetHashCode((object)null); // Assert nullHashCodeAct.Should().ThrowExactly <ArgumentNullException>(); nullHashCodeAct2.Should().ThrowExactly <ArgumentNullException>(); }
public void ComparerObjectHashCodeComparison() { // Arrange var comparer = CharacterComparer.Create(CultureInfo.InvariantCulture, ignoreCase: true); var obj = new object(); // Act var objectHashCode = obj.GetHashCode(); var comparerHashCode = comparer.GetHashCode(obj); // Assert comparer.Should().NotBeNull(); objectHashCode.Should().Be(comparerHashCode); }
public void EqualityInvariantCultureCaseSensitive() { // Arrange var comparer = CharacterComparer.Create(CultureInfo.InvariantCulture, ignoreCase: false); // Act var objectEquality = comparer.Equals((object)'H', (object)'H'); var charEquality = comparer.Equals('H', 'H'); var objectInequality = comparer.Equals((object)'h', (object)'H'); var charInequality = comparer.Equals('h', 'H'); // Assert comparer.Should().NotBeNull(); objectEquality.Should().BeTrue(); charEquality.Should().BeTrue(); objectInequality.Should().BeFalse(); charInequality.Should().BeFalse(); }
public void ComparerNonCharEqualityComparison() { // Arrange var comparer = CharacterComparer.Create(CultureInfo.InvariantCulture, ignoreCase: true); // Act var fromNumberCompare = 42.CompareTo(84); var comparerNumberCompare = comparer.Compare(42, 84); Action mixedCompareAct = () => comparer.Compare(42, 'A'); Action mixedCompareAct2 = () => comparer.Compare('A', 42); Action objectCompareAct = () => comparer.Compare(new object(), 42); var nullCompare = comparer.Compare('A', null); // Assert comparer.Should().NotBeNull(); fromNumberCompare.Should().Be(comparerNumberCompare); mixedCompareAct.Should().ThrowExactly <ArgumentException>(); mixedCompareAct2.Should().ThrowExactly <ArgumentException>(); objectCompareAct.Should().ThrowExactly <ArgumentException>(); nullCompare.Should().Be(1); }