Skip to content
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

Reduce friction on importing FluentAssertions.Json idea #56

Open
coolhome opened this issue Sep 6, 2021 · 7 comments
Open

Reduce friction on importing FluentAssertions.Json idea #56

coolhome opened this issue Sep 6, 2021 · 7 comments

Comments

@coolhome
Copy link

coolhome commented Sep 6, 2021

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

@dennisdoomen
Copy link
Member

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.

@akamud
Copy link

akamud commented Nov 15, 2021

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.

@coolhome
Copy link
Author

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

@dennisdoomen
Copy link
Member

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

@vkhobor
Copy link

vkhobor commented Jul 3, 2024

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?

@coolhome
Copy link
Author

coolhome commented Jul 3, 2024

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

@vkhobor
Copy link

vkhobor commented Jul 3, 2024

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants