diff --git a/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs b/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs index d3d7a1d085..7069fa056c 100644 --- a/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs +++ b/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs @@ -1641,8 +1641,11 @@ private static bool CompareIEnumerable(IEnumerable? expected, IEnumerable? actua object? curExpected = expectedEnum.Current; object? curActual = actualEnum.Current; - - if (curExpected is IEnumerable curExpectedEnum && curActual is IEnumerable curActualEnum) + if (comparer.Compare(curExpected, curActual) == 0) + { + position++; + } + else if (curExpected is IEnumerable curExpectedEnum && curActual is IEnumerable curActualEnum) { stack.Push(new(expectedEnum, actualEnum, position + 1)); stack.Push(new(curExpectedEnum.GetEnumerator(), curActualEnum.GetEnumerator(), 0)); @@ -1656,8 +1659,6 @@ private static bool CompareIEnumerable(IEnumerable? expected, IEnumerable? actua position); return false; } - - position++; } if (actualEnum.MoveNext() && !expectedEnum.MoveNext()) diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/CollectionAssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/CollectionAssertTests.cs index e2dfd93e21..e121fb95e8 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/CollectionAssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/CollectionAssertTests.cs @@ -198,6 +198,20 @@ public void CollectionAssertAreEqualComparerNullabilityPostConditions() comparer.ToString(); // no warning } + public void CollectionAssertAreEqual_WithIgnoreCaseComparer_DoesNotThrow() + { + List expected = ["one", "two"]; + List actual = ["ONE", "tWo"]; + CollectionAssert.AreEqual(expected, actual, StringComparer.OrdinalIgnoreCase); + } + + public void CollectionAssertAreEqual_WithCaseSensetiveComparer_Fails() + { + List expected = ["one", "two"]; + List actual = ["ONE", "tWo"]; + VerifyThrows(() => CollectionAssert.AreEqual(expected, actual, StringComparer.Ordinal)); + } + public void CollectionAssertAreEqualComparerMessageNullabilityPostConditions() { ICollection? collection1 = GetCollection(); @@ -264,6 +278,20 @@ public void CollectionAssertAreNotEqual_NotEqualNestedLists_Passes() CollectionAssert.AreNotEqual(collection1, collection2); } + public void CollectionAssertAreNotEqual_WithIgnoreCaseComparer_Fails() + { + List expected = ["one", "two"]; + List actual = ["ONE", "tWo"]; + VerifyThrows(() => CollectionAssert.AreNotEqual(expected, actual, StringComparer.OrdinalIgnoreCase)); + } + + public void CollectionAssertAreNotEqual_WithCaseSensitiveComparer_Passes() + { + List expected = ["one", "two"]; + List actual = ["ONE", "tWo"]; + CollectionAssert.AreNotEqual(expected, actual, StringComparer.Ordinal); + } + public void CollectionAssertAreNotEqual_EqualNestedLists_Fails() { ICollection? collection1 = GetNestedLists();