-
-
Notifications
You must be signed in to change notification settings - Fork 540
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
HaveCount() does not trigger IReadOnlyCollection<T>.Count #2200
Comments
I assume any |
@jnyrup I know there is a work-around, that is not the point. The point is that there is a analyzer rule, that suggests to rewrite a test, and by doing that changing the coverage. And that brought me to the question if we should expect it to use the int actualCount = Subject.AsEnumerable().Count(); I'm not sure, hence the question. |
The purpose of the analyzer is to help using Fluent Assertions in a more idiomatic way, which can approximately be interpreted as the most readable code code and the most informative failure messages. You should not make assumptions on exactly how Guarding against a bogus implementation of I hope I got your questions right. |
I think you did. As mentioned, I understand the choices (implicitly) made. I was just curious, if my assumptions where correct, and if coverage was a parameter in designing the FluentAssertions API. From maintainability perspective, I can see that. |
Description
I'm not sure if this is a real bug, but is not desirable, specially because the analyzer suggests to change
collection.Count.Should.Be()
tocollection.Should().HaveCount()
.The reason is that
HaveCount()
callsEnumerable.Count()
that itself has a special case for whenT is ICollection
, but not forIReadOnlyCollection
. The question is, if this should be the responsibility of FluentAssertions.If so, the fix is easy:
Reproduction Steps
Expected behavior
SomeReadOnlyCollection.Count is covered by this test.
Actual behavior
SomeReadOnlyCollection.Count is not cover by this test.
Regression?
Logically not, as it is behavior due to .NET's implementation.
Known Workarounds
The text was updated successfully, but these errors were encountered: