/// <summary> /// Verifies that two specified object variables refer to the same object. The assertion fails if they refer to different objects. /// </summary> /// <param name="expected">The expected reference.</param> /// <param name="actual">The actual reference.</param> /// <param name="message">An optional message to display if the assertion fails.</param> public void AreSame(object expected, object actual, string message = "") { if (!ReferenceEquityAssertTypesMatch(expected, actual, true)) { return; } if (expected == null && actual != null) { AssertHandler.OnAssertFailed(string.Format(RubberduckUI.Assert_ParameterResultFormat, Tokens.Nothing, actual.GetHashCode(), message).Trim()); return; } if (actual == null && expected != null) { AssertHandler.OnAssertFailed(string.Format(RubberduckUI.Assert_ParameterResultFormat, expected.GetHashCode(), Tokens.Nothing, message).Trim()); return; } if (ReferenceEquals(expected, actual)) { AssertHandler.OnAssertSucceeded(); } else { AssertHandler.OnAssertFailed(string.Format(RubberduckUI.Assert_ParameterResultFormat, expected.GetHashCode(), actual.GetHashCode(), message).Trim()); } }
/// <summary> /// Verifies that two specified object variables refer to different objects. The assertion fails if they refer to the same object. /// </summary> /// <param name="expected">The expected reference.</param> /// <param name="actual">The actual reference.</param> /// <param name="message">An optional message to display if the assertion fails.</param> public void AreNotSame(object expected, object actual, string message = "") { if (!ReferenceEquityAssertTypesMatch(expected, actual, false)) { return; } if (expected == null && actual == null) { AssertHandler.OnAssertFailed(string.Format(AssertMessages.Assert_ParameterResultFormat, Tokens.Nothing, Tokens.Nothing, message).Trim()); return; } if (expected == null || actual == null) { AssertHandler.OnAssertSucceeded(); return; } if (!ReferenceEquals(expected, actual)) { AssertHandler.OnAssertSucceeded(); return; } AssertHandler.OnAssertFailed(string.Format(AssertMessages.Assert_ParameterResultFormat, expected.GetHashCode(), actual.GetHashCode(), message).Trim()); }
/// <summary> /// Verifies that the specified object is <c>Nothing</c>. The assertion fails if it is not <c>Nothing</c>. /// </summary> /// <param name="value">The object to verify.</param> /// <param name="message">An optional message to display if the assertion fails.</param> public void IsNothing(object value, string message = "") { if (value == null) { AssertHandler.OnAssertSucceeded(); } else { AssertHandler.OnAssertFailed(message); } }
/// <summary> /// Verifies that the specified condition is <c>false</c>. The assertion fails if the condition is <c>true</c>. /// </summary> /// <param name="condition">Any Boolean value or expression.</param> /// <param name="message">An optional message to display if the assertion fails.</param> public void IsFalse(bool condition, string message = "") { if (!condition) { AssertHandler.OnAssertSucceeded(); } else { AssertHandler.OnAssertFailed(message); } }
/// <summary> /// Verifies that the specified condition is <c>true</c>. The assertion fails if the condition is <c>false</c>. /// </summary> /// <param name="condition">Any Boolean value or expression.</param> /// <param name="message">An optional message to display if the assertion fails.</param> public void IsTrue(bool condition, string message = null) { if (condition) { AssertHandler.OnAssertSucceeded(); } else { AssertHandler.OnAssertFailed("IsTrue", message); } }
/// <summary> /// Verifies that two specified objects are equal as considered equal under the loose terms of VBA equality. /// As such the assertion fails, if the objects are not equal, even after applying VBA Type promotions. /// </summary> /// <param name="expected">The expected value.</param> /// <param name="actual">The actual value.</param> /// <param name="message">An optional message to display if the assertion fails.</param> /// <remarks> /// contrary to <see cref="AssertClass.AreEqual"/> <paramref name="expected"/> and <paramref name="actual"/> are not required to be of the same type /// </remarks> public override void AreEqual(object expected, object actual, string message = "") { if (PermissiveComparer.Equals(expected, actual)) { AssertHandler.OnAssertSucceeded(); } else { AssertHandler.OnAssertFailed(message); } }
public override void AreNotEqual(object expected, object actual, string message = "") { // vbNullString is marshalled as null. assume value semantics: expected = expected ?? string.Empty; actual = actual ?? string.Empty; if (PermissiveComparer.Equals(expected, actual)) { AssertHandler.OnAssertFailed(message); } AssertHandler.OnAssertSucceeded(); }
protected void TestArraySequenceEquity(Array expected, Array actual, string message, bool equals, IEqualityComparer <object> comparer, [CallerMemberName] string methodName = "") { if (expected.Rank != actual.Rank) { if (equals) { AssertHandler.OnAssertFailed(string.Format(AssertMessages.Assert_DimensionMismatchFormat, expected.Rank, actual.Rank, message).Trim(), methodName); return; } AssertHandler.OnAssertSucceeded(); } for (var rank = 0; rank < expected.Rank; rank++) { var expectedBound = expected.GetLowerBound(rank); var actualBound = actual.GetLowerBound(rank); if (expectedBound != actualBound) { if (equals) { AssertHandler.OnAssertFailed(string.Format(AssertMessages.Assert_LBoundMismatchFormat, rank + 1, expectedBound, actualBound, message).Trim(), methodName); return; } AssertHandler.OnAssertSucceeded(); } expectedBound = expected.GetUpperBound(rank); actualBound = actual.GetUpperBound(rank); if (expectedBound != actualBound) { if (equals) { AssertHandler.OnAssertFailed(string.Format(AssertMessages.Assert_UBoundMismatchFormat, rank + 1, expectedBound, actualBound, message).Trim(), methodName); return; } AssertHandler.OnAssertSucceeded(); } } var flattenedExpected = expected.Cast <object>().ToList(); var flattenedActual = actual.Cast <object>().ToList(); if (equals ^ flattenedActual.SequenceEqual(flattenedExpected, comparer)) { AssertHandler.OnAssertFailed(message, methodName); return; } AssertHandler.OnAssertSucceeded(); }
public override void AreNotEqual(object expected, object actual, string message = null) { // vbNullString is marshalled as null. assume value semantics: expected = expected ?? string.Empty; actual = actual ?? string.Empty; if (expected.GetType() != actual.GetType()) { if (!RunTypePromotions(ref expected, ref actual)) { AssertHandler.OnAssertFailed("AreNotEqual", message); } } if (!expected.Equals(actual)) { AssertHandler.OnAssertSucceeded(); } }
/// <summary> /// Verifies that two specified objects are not equal. The assertion fails if the objects are equal. /// </summary> /// <param name="expected">The expected value.</param> /// <param name="actual">The actual value.</param> /// <param name="message">An optional message to display if the assertion fails.</param> /// <remarks> /// <paramref name="expected"/> and <paramref name="actual"/> must be the same type. /// </remarks> public virtual void AreNotEqual(object expected, object actual, string message = "") { // vbNullString is marshaled as a null. assume value semantics: expected = expected ?? string.Empty; actual = actual ?? string.Empty; if (!ValueEquityAssertTypesMatch(expected, actual, false)) { return; } if (!expected.Equals(actual)) { AssertHandler.OnAssertSucceeded(); } else { AssertHandler.OnAssertFailed(string.Format(AssertMessages.Assert_ParameterResultFormat, expected, actual, message).Trim()); } }
/// <summary> /// Verifies that two specified object variables refer to different objects. The assertion fails if they refer to the same object. /// </summary> /// <param name="expected">The expected reference.</param> /// <param name="actual">The actual reference.</param> /// <param name="message">An optional message to display if the assertion fails.</param> public void AreNotSame(object expected, object actual, string message = null) { if (expected == null && actual == null) { AssertHandler.OnAssertFailed("AreNotSame", string.Concat("expected: Nothing; actual: Nothing. ", message)); return; } if (expected == null || actual == null) { AssertHandler.OnAssertSucceeded(); return; } if (!ReferenceEquals(expected, actual)) { AssertHandler.OnAssertSucceeded(); return; } AssertHandler.OnAssertFailed("AreNotSame", string.Concat("expected: ", expected.GetHashCode(), "; actual: ", actual.GetHashCode(), ". ", message)); }
/// <summary> /// Verifies that two specified objects are not equal. The assertion fails if the objects are equal. /// </summary> /// <param name="expected">The expected value.</param> /// <param name="actual">The actual value.</param> /// <param name="message">An optional message to display if the assertion fails.</param> /// <remarks> /// <paramref name="expected"/> and <paramref name="actual"/> must be the same type. /// </remarks> public void AreNotEqual(object expected, object actual, string message = null) { // vbNullString is marshaled as a null. assume value semantics: expected = expected ?? string.Empty; actual = actual ?? string.Empty; if (expected.GetType() != actual.GetType()) { AssertHandler.OnAssertInconclusive("[expected] and [actual] values are not the same type."); return; } if (!expected.Equals(actual)) { AssertHandler.OnAssertSucceeded(); } else { AssertHandler.OnAssertFailed("AreNotEqual", string.Concat("expected: ", expected.ToString(), "; actual: ", actual.ToString(), ". ", message)); } }
public void Succeed() { AssertHandler.OnAssertSucceeded(); }