From 55b645cf4a070dc43948e5a21c89df640aa06790 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 6 Jan 2025 13:02:16 +0100 Subject: [PATCH] Use different message for Assert.AreEqual when string difference is casing only --- src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs | 3 ++- .../Assertions/AssertTests.AreEqualTests.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index 274bc26248..5b94c7ed13 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -698,7 +698,8 @@ private static void ThrowAssertAreEqualFailed(T expected, T actual, T delta, [DoesNotReturn] private static void ThrowAssertAreEqualFailed(string? expected, string? actual, bool ignoreCase, CultureInfo culture, string userMessage) { - string finalMessage = !ignoreCase && CompareInternal(expected, actual, ignoreCase, culture) == 0 + // If the user requested to match case, and the difference between expected/actual is casing only, then we use a different message. + string finalMessage = !ignoreCase && CompareInternal(expected, actual, ignoreCase: true, culture) == 0 ? string.Format( CultureInfo.CurrentCulture, FrameworkMessages.AreEqualCaseFailMsg, diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs index 4760984225..746caa344f 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs @@ -126,7 +126,8 @@ public void AreEqual_WithEnglishCultureAndDoesNotIgnoreCase_Throws() var englishCulture = new CultureInfo("en-EN"); // Won't ignore case. - VerifyThrows(() => Assert.AreEqual(expected, actual, false, englishCulture)); + Exception ex = VerifyThrows(() => Assert.AreEqual(expected, actual, false, englishCulture)); + Verify(ex.Message == "Assert.AreEqual failed. Expected:. Case is different for actual value:. "); } public void AreEqual_WithTurkishCultureAndDoesNotIgnoreCase_Throws()