public override void Verify(Type type) { if (type == null) { throw new ArgumentNullException("type"); } var equalsFromIEquatable = type.GetStronglyTypedEqualsMethod(); foreach (var testCase in equalityTestCaseProvider.For(type)) { var result = (bool)equalsFromIEquatable.Invoke(testCase.FirstInstance, new[] { testCase.SecondInstance }); if (result != testCase.ExpectedResult) { if (testCase.ExpectedResult) { throw new IEquatableValueCheckException( string.Format( "Expected IEquatable<{0}>.Equals method to perform value check but looks like it performs identity check", type.Name)); } throw new IEquatableValueCheckException( string.Format( "Expected IEquatable<{0}>.Equals method return {1}, but {2} was returned for {3} {4}", type.Name, testCase.ExpectedResult, !testCase.ExpectedResult, testCase.FirstInstance, testCase.SecondInstance)); } } }
public override void Verify(Type type) { if (type == null) { throw new ArgumentNullException("type"); } foreach (var testCase in equalityTestCaseProvider.For(type)) { var firstInstanceHashCode = testCase.FirstInstance.GetHashCode(); var secondInstanceHashCode = testCase.SecondInstance.GetHashCode(); var result = firstInstanceHashCode == secondInstanceHashCode; if (result != testCase.ExpectedResult) { if (testCase.ExpectedResult) { throw new GetHashCodeValueCheckException( string.Format( "Expected type {0} GetHashCode method to compute bash based on value semantic not identity", type.Name)); } throw new GetHashCodeValueCheckException( string.Format("Expected type {0} GetHashCode to return {1} hash codes for {2} and {3}", type.Name, testCase.ExpectedResult ? "equal" : "not equal", testCase.FirstInstance, testCase.SecondInstance)); } } }
public override void Verify(Type type) { if (type == null) { throw new ArgumentNullException("type"); } foreach (var testCase in equalityTestCaseProvider.For(type)) { var result = testCase.FirstInstance.Equals(testCase.SecondInstance); if (result != testCase.ExpectedResult) { if (testCase.ExpectedResult) { throw new EqualsValueCheckException( string.Format( "Expected type {0} to perform value check but looks like it performs identity check", type.Name)); } throw new EqualsValueCheckException(string.Format("Expected {0} to be not equal to {1}", testCase.FirstInstance, testCase.SecondInstance)); } } }
public override void Verify(Type type) { if (type == null) { throw new ArgumentNullException("type"); } var inequalityOperator = type.GetInequalityOperatorMethod(); foreach (var testCase in equalityTestCaseProvider.For(type)) { var result = (bool)inequalityOperator.Invoke(null, new[] { testCase.FirstInstance, testCase.SecondInstance }); if (result == testCase.ExpectedResult) { if (testCase.ExpectedResult) { throw new InequalityOperatorValueCheckException( string.Format( "Expected type {0} != operator to perform value check but looks like it performs identity check", type.Name)); } throw new InequalityOperatorValueCheckException( string.Format("Expected type {0} != operator to returns result {1} for {2} == {3}", type.Name, testCase.ExpectedResult, testCase.FirstInstance, testCase.SecondInstance)); } } }