-
-
Notifications
You must be signed in to change notification settings - Fork 109
System.Text.Json Assertions for JsonNode, JsonElement, etc. #4179
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
Conversation
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Added JsonNode diff helper methods to JsonDiffHelper - Updated IsDeepEqualTo for JsonNode to show path-to-difference on failure - Added tests for whitespace handling and error message path verification 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Added IsJsonArrayEmpty, IsJsonArrayNotEmpty, HasJsonArrayCount - Methods work on JsonNode? to avoid TUnit's collection assertion wrapping - Includes type checking for non-array inputs 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Added IsValidJson, IsNotValidJson, IsValidJsonObject, IsValidJsonArray - Provides detailed error messages for parsing failures - Includes tests for valid, invalid, and type mismatch scenarios 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…an documents - Deleted the JSON Assertions Design document and the JSON Assertions Implementation Plan document as they are no longer needed.
PR Review: System.Text.Json AssertionsReviewed PR #4179 - this is a solid implementation of JSON assertions for TUnit. StrengthsTest Coverage
Code Quality
Error Messages
Style
Areas for Improvement1. Performance NotesJsonStringAssertionExtensions creates JsonDocument on each call. This is acceptable for assertions (not a hot path), but consider documenting that users should prefer JsonElement/JsonNode assertions when working with already-parsed JSON. 2. Missing Edge Case TestsConsider adding:
3. Version HandlingGood job on version-specific conditionals:
4. Naming ConsistencyThe naming difference (IsJsonObject for JsonNode vs IsObject for JsonElement) is intentional and correct - it matches the underlying BCL types. TUnit CLAUDE.md Checklist
VerdictAPPROVE with minor recommendations No critical issues found. Code quality is excellent, test coverage is very good, and TUnit conventions are followed correctly. The recommendations above are nice-to-haves for future improvements. Summary:
Great work! |
PR Review: System.Text.Json AssertionsThis PR adds comprehensive JSON assertion capabilities to TUnit. Overall, this is a high-quality implementation that follows TUnit conventions well. Strengths1. Excellent Code QualityModern C# syntax with collection expressions, file-scoped namespaces, and pattern matching. Proper use of GenerateAssertion attribute. Clean separation of concerns. Good XML documentation throughout. 2. Smart Runtime TargetingProper use of conditional compilation for .NET versions. Leverages built-in DeepEquals methods instead of reimplementing. Appropriate feature gating based on API availability. 3. Helpful Error MessagesJsonDiffHelper provides path-to-difference error messages like differs at dollar-sign.age: expected 31 but found 30. This directly addresses the core issue requirement. 4. Good Test CoverageComprehensive test files for all assertion types with both positive and negative test cases. Tests verify error message content. 5. API ConsistencySnapshots updated for public API changes. Follows TUnit naming conventions. Issues & SuggestionsCRITICAL: file modifier on extension classesLocation: JsonElementAssertionExtensions.cs:9, JsonNodeAssertionExtensions.cs:9, JsonStringAssertionExtensions.cs:9 The file modifier makes these extension methods invisible outside the declaring file. Users will not be able to call these assertions. Fix Required: Change from file to public scope on all three extension classes. This is critical - the feature will not work without this change. Performance: String allocation in diff pathLocation: JsonDiffHelper.cs:51, 68 String interpolation allocates on every property even when there is no difference. Consider lazy path construction - only build path string if difference found. Low priority impact since diff checking is not a hot path. Missing null handling testAdd test case for both JsonNode arguments being null to verify proper handling. Naming inconsistencyJsonNode methods use Json prefix while JsonElement methods do not. Consider standardizing for consistency. Recommended ActionsRequired (Blocking):
Recommended (Non-blocking): SummaryThis is excellent work that adds valuable JSON testing capabilities to TUnit. Once the file modifier issue is fixed, this PR will be ready to merge. Great job on the detailed error messages! Reviewed using TUnit CLAUDE.md guidelines |
Fixes #4178