You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Please add function overloads for IReadOnlyCollection #7956
ICollection is very rarely implemented in custom types because, for syntactic sugar, it's sufficient to implement the Add(TValue item) method with any return type.
It's usually very convenient to implement bool Add(TValue item) because its operation is easy to control without having to first use bool Contains(TValue item). Otherwise, you'll encounter exceptions. In any case, this reduces code performance because bool Contains(TValue item) is essentially already implemented in the bool Add(TValue item) method under the hood. You're probably familiar with the slowness of exceptions.
Often, validation methods such as CollectionAssert.AreEqual and similar methods don't change anything in collections anyway. Therefore, choosing ICollection as the argument type isn't a good idea. (I assume this was done to support legacy versions of C#.)
Closing as superseded — the modern Assert.* family added in 4.x already accepts IEnumerable<T> (which is strictly broader than IReadOnlyCollection<T> and ICollection<T>), so no extra CollectionAssert overloads are needed. The recommended replacements are all on Assert itself:
CollectionAssert.*
Modern Assert.* replacement (takes IEnumerable<T>)
All overloads use RFC 012 structured failure messages and apply to any IReadOnlyCollection<T>, custom enumerable, or LINQ query without needing .ToList() / casts.
For the umbrella analyzer guidance pushing users toward these APIs (extension of MSTEST0037), see #8338.
Activity
MihuBot commentedon Apr 30, 2026
I'm a bot. Here is a possible related and/or duplicate issue (I may be wrong):
Evangelink commentedon May 20, 2026
Closing as superseded — the modern
Assert.*family added in 4.x already acceptsIEnumerable<T>(which is strictly broader thanIReadOnlyCollection<T>andICollection<T>), so no extraCollectionAssertoverloads are needed. The recommended replacements are all onAssertitself:CollectionAssert.*Assert.*replacement (takesIEnumerable<T>)AreEqual(ordered)Assert.AreSequenceEqual<T>(expected, actual)(#8334)AreNotEqual(ordered)Assert.AreNotSequenceEqual<T>(notExpected, actual)(#8334)AreEqual(any order)Assert.AreSequenceEqual<T>(expected, actual, SequenceOrder.InAnyOrder)(#8334)AreEquivalent/ structuralAssert.AreEquivalent<T>/AreNotEquivalent<T>(#8266)ContainsAssert.Contains<T>(item, collection)(#8265)DoesNotContainAssert.DoesNotContain<T>(item, collection)(#8265)AllItemsAreNotNullAssert.AreAllNotNull<T>(collection)(#8237)AllItemsAreUniqueAssert.AreAllDistinct<T>(collection)(#8237)AllItemsAreInstancesOfTypeAssert.AreAllOfType<T>(collection)(#8237)IsSubsetOfAssert.ContainsAll<T>(expected, collection)(#8234)IsNotSubsetOfAssert.DoesNotContainAll<T>(expected, collection)(#8234)Assert.HasCount<T>(n, collection)/IsEmpty/IsNotEmpty(#8262)All overloads use RFC 012 structured failure messages and apply to any
IReadOnlyCollection<T>, custom enumerable, or LINQ query without needing.ToList()/ casts.For the umbrella analyzer guidance pushing users toward these APIs (extension of MSTEST0037), see #8338.