Closed
Description
Description
Misleading diagnostic and wrong fix when asserting array length
Complete minimal example reproducing the issue
int[] ar = new int[2];
ar.Length.Should().Be(2);
Expected behavior:
I'm not sure what to expect. "Actual behavior" should make the problem clear.
Actual behavior:
The code triggers FluentAssertions0206: Use .Should().HaveLength() instead.
This would be fine, except the only HaveLength
I've seen applies to strings, not to arrays.
Applying the "Simplify Assertion" fix changes the code to:
ar.Should().HaveLength(2);
This does not compile, as ar
is not a string.
If FluentAssertions were to support array Length
properties with a HaveLength
assertion, that would be nice.
In lieu of that, HaveCount
would actually make sense here.
Versions
FluentAssertions | 6.9.0 |
---|---|
FluentAssertions.Analyzers | 0.25.0 |
target | .net6.0 |