fluentassertions.json icon indicating copy to clipboard operation
fluentassertions.json copied to clipboard

Reduce friction on importing `FluentAssertions.Json` idea

Open coolhome opened this issue 4 years ago • 7 comments
trafficstars

To reduce false positives and improve user experience with someJToken.Should().BeEquivalentTo(expectedJToken) I was thinking a Roselyn Analyzer can be used to suggest a code fix.

public AndConstraint<TAssertions> BeEquivalentTo<TExpectation>(TExpectation expectation, string because = "", params object[] becauseArgs)

I imagine we can find all references to this where TAssertions and TExpectation are JToken/JObject/JArray/JValue and suggest a code fix to import FluentAssertions.Json.

I think another approach could be to move JsonAssertionExtensions, ObjectAssertionsExtensions, and StringAssertionsExtensions in the FluentAssertions namespace? Related to #28

coolhome avatar Sep 06 '21 17:09 coolhome

As we don't want to have Fluent Assertions take a dependency on NewtownSoft.Json, we decided to have a separate package, this repository. But a Roslyn analyzer could work. But unless somebody from the community is willing to assist here, we don't have to time to build one.

dennisdoomen avatar Sep 06 '21 18:09 dennisdoomen

I like this idea, in my team we had so many false positives and it took so long for people to find them that we ended up creating wrappers to make sure we are always using the FluentAssertions.Json method.

An analyzer would be perfect indeed.

akamud avatar Nov 15 '21 13:11 akamud

I wonder what other imports cause this same problem. If anyone has some knowledge here it might be beneficial for whoever takes this ticket.

coolhome avatar Jan 19 '22 18:01 coolhome

Importing FluentAssertions and not importing FluentAssertions.Json causes this problem.

dennisdoomen avatar Jan 19 '22 19:01 dennisdoomen

Hi. In the meantime, if I just put FluentAssertions.Json into the test package as a global using that would eliminate false positives all together?

vkhobor avatar Jul 03 '24 11:07 vkhobor

@vkhobor I imagine that would work. You should give it a test and let us know :)

coolhome avatar Jul 03 '24 12:07 coolhome

@vkhobor I imagine that would work. You should give it a test and let us know :)

Will do. 👍🏻 Is there a documented test case that I can use to produce a false positive? When does this occur?

vkhobor avatar Jul 03 '24 12:07 vkhobor