-
Notifications
You must be signed in to change notification settings - Fork 731
Added System.Text.Json assertion APIs and BeEquivalentTo support #3094
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
Added System.Text.Json assertion APIs and BeEquivalentTo support #3094
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds comprehensive JSON assertion capabilities to FluentAssertions by introducing specialized assertion methods for System.Text.Json.Nodes.JsonNode and enabling equivalency comparisons between JSON nodes and C# objects.
Key changes include:
- New JSON-specific assertion methods for type checking (
BeNumeric(),BeString(),BeBool(),BeLocalDate(),BeUtcDate()) - Property verification methods (
HaveProperty(),NotHaveProperty()) and array checking (BeAnArray(),NotBeAnArray()) BeEquivalentTo()functionality that allows direct comparison of JSON nodes to C# objects with automatic type conversion- Case-insensitive property matching option through
IgnoringJsonPropertyCasing()
Reviewed Changes
Copilot reviewed 37 out of 37 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/FluentAssertions.Specs/Specialized/JsonNodeSpecs.cs | Comprehensive test suite covering all new JSON assertion methods |
| Tests/FluentAssertions.Equivalency.Specs/JsonNodeSpecs.cs | Test cases for JSON equivalency comparisons with various scenarios |
| Tests/FluentAssertions.Extensibility.Specs/JsonWithInlineAssertionsSpecs.cs | Tests demonstrating JSON assertions with inline predicates and assertions |
| Tests/FluentAssertions.Extensibility.Specs/HttpResponseMessageAssertions.cs | Extension methods for HTTP response JSON assertion support |
| Src/FluentAssertions/Specialized/JsonNodeAssertions.cs | Main assertion class providing JSON-specific assertion methods |
| Src/FluentAssertions/Formatting/JsonNodeFormatter.cs | Custom formatter for rendering JSON nodes in assertion messages |
| Src/FluentAssertions/Equivalency/Steps/JsonConversionStep.cs | Equivalency step for converting JSON values to appropriate .NET types |
| Src/FluentAssertions/Equivalency/JsonProperty.cs | JSON property representation for equivalency matching |
| Src/FluentAssertions/Equivalency/Matching/*.cs | JSON-aware matching rules for property comparison |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Tests/FluentAssertions.Extensibility.Specs/JsonWithInlineAssertionsSpecs.cs
Outdated
Show resolved
Hide resolved
3ca68d4 to
a534045
Compare
Qodana for .NETIt seems all right 👌 No new problems were found according to the checks applied 💡 Qodana analysis was run in the pull request mode: only the changed files were checked Contact Qodana teamContact us at qodana-support@jetbrains.com
|
90ce2b6 to
5995d90
Compare
Tests/FluentAssertions.Extensibility.Specs/HttpResponseMessageAssertions.cs
Outdated
Show resolved
Hide resolved
Tests/FluentAssertions.Extensibility.Specs/JsonWithInlineAssertionsSpecs.cs
Outdated
Show resolved
Hide resolved
Tests/FluentAssertions.Extensibility.Specs/JsonWithInlineAssertionsSpecs.cs
Outdated
Show resolved
Hide resolved
Tests/FluentAssertions.Equivalency.Specs/FluentAssertions.Equivalency.Specs.csproj
Outdated
Show resolved
Hide resolved
5995d90 to
6ed1e49
Compare
Tests/FluentAssertions.Extensibility.Specs/JsonWithInlineAssertionsSpecs.cs
Outdated
Show resolved
Hide resolved
6a0cc0c to
3f5a206
Compare
Pull Request Test Coverage Report for Build 17881824721Details
💛 - Coveralls |
3f5a206 to
3b050a8
Compare
3b050a8 to
e8d5da8
Compare
jnyrup
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coveralls seems down for me, but have you checked the missing lines if they warrant extra tests?
e8d5da8 to
a5f0796
Compare
This PR adds comprehensive support for JSON assertion APIs in FluentAssertions along with
BeEquivalentTofunctionality for JSON nodes.The PR introduces new assertion methods for
System.Text.Json.Nodes.JsonNodeandJsonArraytypes, including type checking methods likeBeNumeric(),BeString(),BeBool(),BeLocalDate(), andBeUtcDate(). It also adds property verification methods such asHaveProperty()and array checking withBeAnArray().A key feature is the
BeEquivalentTo()method that allows comparing JSON nodes directly to C# objects, with automatic conversion of JSON values to appropriate .NET types (including ISO 8601 date parsing). This comparison supports case-insensitive property matching through theIgnoringJsonPropertyCasing()option.The implementation includes new matching rules specifically for JSON properties that work alongside existing member matching, and a JSON conversion step that automatically handles type conversions during equivalency comparisons. The system seamlessly integrates with the existing equivalency framework, allowing JSON nodes to be compared against complex object graphs with nested properties and collections.
Closes #2205