Related: #5703, #5704, #5705, #5706 (same pattern).
Problem
CollectionAssertionBase.Count(Func<IAssertionSource<TItem>, Assertion<TItem>?> itemAssertion, ...) passes a generic IAssertionSource<TItem> into the lambda. When TItem is a string, collection, dictionary, or set, specialised assertions on the item are unreachable.
Repro
// IEnumerable<string>
await Assert.That(items).Count(s => s.Contains(\"foo\")); // fails: string-specific Contains not on IAssertionSource<string>
// IEnumerable<List<int>>
await Assert.That(listOfLists).Count(l => l.HasCount(3)); // fails
Affected signature
TUnit.Assertions/Sources/CollectionAssertionBase.cs:167
public CollectionCountSource<TCollection, TItem> Count(
Func<IAssertionSource<TItem>, Assertion<TItem>?> itemAssertion,
...)
Proposed fix
Add specialised Count overloads keyed on TItem shape (string / IEnumerable / IDictionary / ISet / ...), passing the matching specialised source into the lambda. Use OverloadResolutionPriority for compiler steering.
Acceptance
- Specialised assertions reachable inside the
.Count(item => ...) lambda for string/collection/dict/set items.
- Tests cover each specialised element shape.
Related: #5703, #5704, #5705, #5706 (same pattern).
Problem
CollectionAssertionBase.Count(Func<IAssertionSource<TItem>, Assertion<TItem>?> itemAssertion, ...)passes a genericIAssertionSource<TItem>into the lambda. WhenTItemis a string, collection, dictionary, or set, specialised assertions on the item are unreachable.Repro
Affected signature
TUnit.Assertions/Sources/CollectionAssertionBase.cs:167Proposed fix
Add specialised
Countoverloads keyed onTItemshape (string / IEnumerable / IDictionary / ISet / ...), passing the matching specialised source into the lambda. UseOverloadResolutionPriorityfor compiler steering.Acceptance
.Count(item => ...)lambda for string/collection/dict/set items.