-
Notifications
You must be signed in to change notification settings - Fork 312
Add ToString() to SqlJson #3427
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
- Added ToString() to SqlJson. - Added missing commentary to public API docs. - Simplified implementation. - Improved tests and moved them to the UnitTests project.
- Fixed ManualTests project.
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 a ToString()
override to SqlJson
, refactors constructors to validate JSON via JsonDocument.Parse
, migrates manual tests into unit tests, and updates XML documentation.
- Implement
ToString()
to return the underlying JSON string or null. - Simplify null-handling logic in constructors and validate inputs with
JsonDocument.Parse
. - Replace manual test file with comprehensive unit tests and update documentation snippets.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlTypes/SqlJson.cs |
Added ToString() , removed legacy null field, streamlined constructors |
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlTypes/SqlJsonTest.cs |
New unit tests covering constructors, Value , and ToString() |
src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj |
Removed manual test entry for SqlJsonTest |
src/Microsoft.Data.SqlClient/tests/ManualTests/Json/SqlJsonTest.cs |
Deleted legacy manual test file |
doc/snippets/Microsoft.Data.SqlTypes/SqlJson.xml |
Updated XML docs for constructors, added <ToString> docs |
Comments suppressed due to low confidence (1)
doc/snippets/Microsoft.Data.SqlTypes/SqlJson.xml:63
- [nitpick] Consider adding a
<returns>
element under<ToString>
to explicitly describe the return value (including its null semantics).
<ToString>
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.
Added commentary for reviewers.
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlTypes/SqlJson.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlTypes/SqlJsonTest.cs
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlTypes/SqlJsonTest.cs
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlTypes/SqlJson.cs
Outdated
Show resolved
Hide resolved
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.
Added some minor comments.
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlTypes/SqlJson.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlTypes/SqlJson.cs
Outdated
Show resolved
Hide resolved
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.
It seems integration (manual) tests using SqlDataReader to test SqlJson are not running, which should be running now against Azure for a more comprehensive code coverage around Json feature.
Since its out of scope for this PR, can you create an issue and we can try assigning to Copilot to configure the same (after PR #3429 is merged) - and we should be able to run those tests against Azure SQL DBs now.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3427 +/- ##
==========================================
+ Coverage 63.59% 69.83% +6.23%
==========================================
Files 299 280 -19
Lines 65418 62169 -3249
==========================================
+ Hits 41601 43414 +1813
+ Misses 23817 18755 -5062
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Added StringSyntax JSON attribute to the string constructor. - Disposing of JsonDocument used for validation. - Enabled CA2000 analyzer as a suggestion.
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.
Move commentary for reviewers.
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlTypes/SqlJson.cs
Outdated
Show resolved
Hide resolved
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.
Mostly just looking for changes to the tests.
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlTypes/SqlJson.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlTypes/SqlJsonTest.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlTypes/SqlJsonTest.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlTypes/SqlJsonTest.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlTypes/SqlJsonTest.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlTypes/SqlJsonTest.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlTypes/SqlJsonTest.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlTypes/SqlJsonTest.cs
Outdated
Show resolved
Hide resolved
- Split tests up further.
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.
A few nits, but I won't hold it up on this. My tolerance level for test code is a lot higher than prod code.
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlTypes/SqlJsonTest.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlTypes/SqlJsonTest.cs
Outdated
Show resolved
Hide resolved
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.
Test using nits.
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlTypes/SqlJsonTest.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlTypes/SqlJsonTest.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlTypes/SqlJsonTest.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlTypes/SqlJsonTest.cs
Outdated
Show resolved
Hide resolved
- Added some missing usings.
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.
Rest everything looks good!
- Added ToString() to SqlJson in the ref projects.
Description
Issues
Addresses #3424 and #3107 .
Testing
Unit tests were run manually, and CI will cover regressions.