Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Count with predicate #11

Closed
jnyrup opened this issue Oct 23, 2017 · 5 comments
Closed

Count with predicate #11

jnyrup opened this issue Oct 23, 2017 · 5 comments
Labels

Comments

@jnyrup
Copy link
Member

jnyrup commented Oct 23, 2017

When using the Count method with a predicate overload the predicate is not taken into account.

list.Count(e => e > 1).Should().Be(2);

is simplified into:

list.Should().HaveCount(2);
@Meir017
Copy link
Member

Meir017 commented Oct 23, 2017

should this case be ignored?

there is an overload HaveCount(Expression<Func<int, bool>> countPredicate, string because = "", params object[] becauseArgs) but I'm not sure how to use it.
@dennisdoomen is it possible to write the assertion using this overload?

@jnyrup
Copy link
Member Author

jnyrup commented Oct 23, 2017

If you're updating the docs, there is a related example in there:

- old: |
    actual.Where(x => x.SomeProperty).Should().HaveCount(1);
  new: |
    actual.Should().ContainSingle(x => x.SomeProperty);

https://github.com/fluentassertions/fluentassertions/blob/88c4fd6ff7c5444b46096553ea7bd2e3df804289/docs/_data/tips/collections.yml#L248

And I would probably replace

list.Count(e => e > 1).Should().Be(2);

with

list.Where(e => e > 1).Should().HaveCount(2);

@Meir017 Meir017 added the bug label Oct 23, 2017
@dennisdoomen
Copy link
Member

When using the Count method with a predicate overload the predicate is not taken into account.

What do you mean with that? The Count is an LINQ extension method. The resulting IEnumerable<T> should return a lazy evaluated filter.

@Meir017
Copy link
Member

Meir017 commented Oct 23, 2017

@dennisdoomen he was talking about the analyzer...

I meant that I wanted to see if it was possible to rewrite the assertion using that overload

@jnyrup
Copy link
Member Author

jnyrup commented Oct 23, 2017

@dennisdoomen
The "not taken in to account" is my attempt to blame the computer rather than @Meir017's great work.

When using The Count method from LINQ that takes an predicate, the simplified assertion produced by the analyzer no longer contains the predicate.

Meir017 added a commit that referenced this issue Oct 24, 2017
refactored analyzers visitors algorithm
fixed #11 
fixed #10 
fixed #13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants