Quantcast
Channel: Fluent Assertions
Viewing all articles
Browse latest Browse all 1402

Edited Issue: CollectionAssertions.HaveCount never calls Count property, always Enumerates [12469]

$
0
0
FIrst off, I'm checking out your repo and I'll supply a fix with this issue... tagged in a pull request?

Gents,

public AndConstraint<TAssertions> HaveCount(int expected, string reason = "", params object[] reasonArgs)
{
...
int num = Enumerable.Count<object>(Enumerable.Cast<object>((IEnumerable) this.Subject));
...
}

is no good. In that call to Linq.Enumerable.Cast() --a function which isn't strictly a cast-- you're getting a yielded value from Subject, a type that doesn't actually relate to the original type of Subject. You cant use an uncasted Subject because Count requires a typed IEnumerable, not an untyped one.

I think the best solution is to do a couple things:
- Make HaveCount virtual.
- Have the non-generic one do the type checking to find the best method (either the property Count or manually enumerating via Count()).
- Have the GenericCollectionAssertions() override the Non-generic one and simply call Linq.Enumerable.Count() with an un-modified Subject.

So branch and pull request pending?


Viewing all articles
Browse latest Browse all 1402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>