question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hidden breaking change in 5.5.0: Assertions on Func lose access to ObjectAssertions

See original GitHub issue

Description

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

  1. Reference FluentAssertions 5.4.2 and use a Should().Be() assertion on a Func<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);
  1. 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, including 5.5.3 and latest 5.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 not ReferenceTypeAssertions, namely Be, NotBe, BeEquivalentTo, HaveFlag and NotHaveFlag.
  • Issue can be resolved by replacing usage of Be() by BeSameAs().

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
dennisdoomencommented, Dec 7, 2019

Updated the release motes.

2reactions
dennisdoomencommented, Dec 3, 2019

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 a Func<T>? Those things don’t override Equals, so in principle I would recommend using BeSameAs 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 and NotHaveFlag are only meant for enumerations.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found