-
-
Notifications
You must be signed in to change notification settings - Fork 240
Support normalization of objects for Z.DynamicLinq.Json #958
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
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a835ac8
Json : Normalize
StefH 812e0ce
.
StefH bee9dea
tst
StefH e70bc42
ns
StefH 643bf5a
sc
StefH 6392b72
any
StefH b9e13f3
Update src/System.Linq.Dynamic.Core.NewtonsoftJson/Config/Normalizati…
StefH e98ae23
Update src/System.Linq.Dynamic.Core.SystemTextJson/Config/SystemTextJ…
StefH 9660958
Update src/System.Linq.Dynamic.Core.NewtonsoftJson/Config/NewtonsoftJ…
StefH c1ffa97
Update src/System.Linq.Dynamic.Core.SystemTextJson/Utils/NormalizeUti…
StefH b372a4d
.
StefH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
tst
- Loading branch information
commit bee9dea075b9638bad4814df06538980c431881c
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,7 +1,6 @@ | ||||||
| using System.Linq.Dynamic.Core.SystemTextJson.Config; | ||||||
| using System.Text.Json; | ||||||
| using FluentAssertions; | ||||||
| using Newtonsoft.Json.Linq; | ||||||
| using Xunit; | ||||||
|
|
||||||
| namespace System.Linq.Dynamic.Core.SystemTextJson.Tests; | ||||||
|
|
@@ -538,34 +537,6 @@ public void Where_With_Select() | |||||
| array.First().GetString().Should().Be("Doe"); | ||||||
| } | ||||||
|
|
||||||
| [Fact] | ||||||
| public void Where_OptionalProperty() | ||||||
| { | ||||||
| // Arrange | ||||||
| var data = | ||||||
| """ | ||||||
| [ | ||||||
| { | ||||||
| "Name": "John", | ||||||
| "Age": 30 | ||||||
| }, | ||||||
| { | ||||||
| "Name": "Doe" | ||||||
| } | ||||||
| ] | ||||||
| """; | ||||||
| var source = JsonDocument.Parse(data); | ||||||
|
|
||||||
| // Act | ||||||
| var result = source.Where("Age >= 30").Select("Name"); | ||||||
|
|
||||||
| // Assert | ||||||
| var array = result.RootElement.EnumerateArray(); | ||||||
| array.Should().HaveCount(1); | ||||||
| var first = result.First(); | ||||||
| array.First().GetString().Should().Be("John"); | ||||||
| } | ||||||
|
|
||||||
| [Theory] | ||||||
| [InlineData("notExisting == true")] | ||||||
| [InlineData("notExisting == \"true\"")] | ||||||
|
|
@@ -580,17 +551,49 @@ public void Where_OptionalProperty() | |||||
| [InlineData("\"something\" == notExisting")] | ||||||
| [InlineData("1 < notExisting")] | ||||||
| public void Where_NonExistingMember_EmptyResult(string predicate) | ||||||
| { | ||||||
| // Act | ||||||
| var result = _source.Where(predicate).RootElement.EnumerateArray(); | ||||||
|
|
||||||
| // Assert | ||||||
| result.Should().BeEmpty(); | ||||||
| } | ||||||
|
|
||||||
| [Theory] | ||||||
| [InlineData("""[ { "Name": "John", "Age": 30 }, { "Name": "Doe" }, { } ]""")] | ||||||
| [InlineData("""[ { "Name": "Doe" }, { "Name": "John", "Age": 30 }, { } ]""")] | ||||||
| public void NormalizeArray(string data) | ||||||
| { | ||||||
| // Arrange | ||||||
| var source = JsonDocument.Parse(data); | ||||||
|
|
||||||
| // Act | ||||||
| var result = source | ||||||
| .Where("Age >= 30") | ||||||
| .Select("Name"); | ||||||
|
|
||||||
| // Assert | ||||||
| var array = result.RootElement.EnumerateArray(); | ||||||
| array.Should().HaveCount(1); | ||||||
| var first = result.First(); | ||||||
| array.First().GetString().Should().Be("John"); | ||||||
| } | ||||||
|
|
||||||
| [Fact] | ||||||
| public void NormalizeArray_When_NormalizeIsFalse_ShouldThrow() | ||||||
| { | ||||||
| // Arrange | ||||||
| var config = new SystemTextJsonParsingConfig | ||||||
| { | ||||||
| ConvertObjectToSupportComparison = true | ||||||
| Normalize = false | ||||||
| }; | ||||||
| var data = """[ { "Name": "Doe" }, { "Name": "John", "Age": 30 }, { } ]"""; | ||||||
| var array = JsonDocument.Parse(data); | ||||||
StefH marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| // Act | ||||||
| var result = _source.Where(config, predicate).RootElement.EnumerateArray(); | ||||||
| Action act = () => JsonDocument.Parse(data).Where(config, "Age >= 30"); | ||||||
|
|
||||||
| // Assert | ||||||
| result.Should().BeEmpty(); | ||||||
| act.Should().Throw<InvalidOperationException>().WithMessage("Unable to find property 'Age' on type '<>f__AnonymousType*"); | ||||||
|
||||||
| act.Should().Throw<InvalidOperationException>().WithMessage("Unable to find property 'Age' on type '<>f__AnonymousType*"); | |
| act.Should().Throw<InvalidOperationException>().WithMessage("*Unable to find property 'Age'*"); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Unused variable: The variable
firstis declared but never used. This line should be removed or the variable should be used in an assertion.