Hidden breaking change in 5.5.0: Assertions on Func lose access to ObjectAssertions
See original GitHub issueDescription
I came across this while bumping the version we use in our repository. Basically any code that used assertions from ObjectAssertions
like .Should().Be()
on Func<T>
types won’t compile when FluentAssertion
is bumped to 5.5.0
, because FuncAssertions
was added and inherits from ReferenceTypeAssertions
, but not from ObjectAssertions
.
I think most if not all use cases for assertions on Func<T>
are covered by ReferenceTypeAssertions
, so Be
can easily be swapped by BeSameAs
. However, this sort of breaking change is unexpected and confusing.
Complete minimal example reproducing the issue
- Reference
FluentAssertions
5.4.2
and use aShould().Be()
assertion on aFunc<T>
object.
<PackageReference Include="FluentAssertions" Version="5.4.2" />
Func<string> func = () => string.Empty;
var funcs = new[] { func };
var result = funcs[0];
result.Should().Be(func);
- Bump reference to version
5.5.0
.
Expected behavior:
The minor version bump is seamless and no breaking changes are encountered.
Actual behavior:
A compilation error is encountered:
Error CS1061 'FunctionAssertions<string>' does not contain a definition for 'Be' and no accessible extension method 'Be' accepting a first argument of type 'FunctionAssertions<string>' could be found (are you missing a using directive or an assembly reference?)
Additional Information
- Issue is present in all versions since
5.5.0
, including5.5.3
and latest5.9.0
. - Release notes don’t mention such a possible breaking change.
- Issue was introduced in #951, where
FunctionAssertions
was added. - Issue occurs for all assertions present in
ObjectAssertions
but notReferenceTypeAssertions
, namelyBe
,NotBe
,BeEquivalentTo
,HaveFlag
andNotHaveFlag
. - Issue can be resolved by replacing usage of
Be()
byBeSameAs()
.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Upgrading to version 6.0 - Fluent Assertions
In Fluent Assertions v5 enums were handled by the ObjectAssertions class, ... This change also breaks compilation for cases that might worked before, ......
Read more >Drools Expert User Guide
Generally people assert that "loose" or "weak" coupling is preferable in design ... The Rete algorithm can be broken into 2 parts: rule...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Updated the release motes.
Thanks for reporting this and the elaborate issue description. Technically you’re right. But I’m in doubt whether we should fix this. What kind of behavior would you expect when using
Be
on aFunc<T>
? Those things don’t overrideEquals
, so in principle I would recommend usingBeSameAs
to emphasize you’re comparing references and not relying on equality.BeEquivalentTo
is already available on the specific assertion types for which this makes sense.HaveFlag
andNotHaveFlag
are only meant for enumerations.