diff --git a/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs b/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs index 6be196fa94..c8f37e098b 100644 --- a/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs +++ b/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs @@ -504,7 +504,7 @@ public static void AreEquivalent( } // If both collections are empty, they are equivalent. - if (!expected.Any()) + if (expectedCollectionCount == 0) { return; } @@ -661,13 +661,15 @@ public static void AreNotEquivalent( DebugEx.Assert(notExpected is not null, "expected is not null here"); // Check whether the element counts are different. - if (notExpected.Count() != actual.Count()) + int notExpectedCount = notExpected.Count(); + int actualCount = actual.Count(); + if (notExpectedCount != actualCount) { return; } // If both collections are empty, they are equivalent. - if (!notExpected.Any()) + if (notExpectedCount == 0) { string userMessage = Assert.BuildUserMessage(message); string finalMessage = string.Format( @@ -743,9 +745,8 @@ public static void AllItemsAreInstancesOfType( int i = 0; foreach (object? element in collection) { - if (expectedType.GetTypeInfo() is { } expectedTypeInfo - && element?.GetType().GetTypeInfo() is { } elementTypeInfo - && !expectedTypeInfo.IsAssignableFrom(elementTypeInfo)) + if (element?.GetType() is { } elementType + && !expectedType.IsAssignableFrom(elementType)) { string userMessage = Assert.BuildUserMessage(message); string finalMessage = string.Format(