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?
Comments: Bump, manually created stub classes in the fixture. No more Fluent assertions stuff.
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?
Comments: Bump, manually created stub classes in the fixture. No more Fluent assertions stuff.