-
Notifications
You must be signed in to change notification settings - Fork 350
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
Fixes #3154: Enable serialize/deserialize navigation property with count without content #3155
Open
xuzhg
wants to merge
3
commits into
main
Choose a base branch
from
issue_dollarCountOnDollarExpand
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
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
There are no files selected for viewing
This file contains 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 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 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 | ||||
---|---|---|---|---|---|---|
|
@@ -968,7 +968,7 @@ protected override void WriteDeferredNestedResourceInfo(ODataNestedResourceInfo | |||||
Debug.Assert(this.writingResponse, "Deferred links are only supported in response, we should have verified this already."); | ||||||
|
||||||
// A deferred nested resource info is just the link metadata, no value. | ||||||
this.jsonResourceSerializer.WriteNavigationLinkMetadata(nestedResourceInfo, this.DuplicatePropertyNameChecker); | ||||||
this.jsonResourceSerializer.WriteNavigationLinkMetadata(nestedResourceInfo, this.DuplicatePropertyNameChecker, count: true); | ||||||
} | ||||||
|
||||||
/// <summary> | ||||||
|
@@ -999,7 +999,7 @@ protected override void StartNestedResourceInfoWithContent(ODataNestedResourceIn | |||||
} | ||||||
|
||||||
// Write the nested resource info metadata first. The rest is written by the content resource or resource set. | ||||||
this.jsonResourceSerializer.WriteNavigationLinkMetadata(nestedResourceInfo, this.DuplicatePropertyNameChecker); | ||||||
this.jsonResourceSerializer.WriteNavigationLinkMetadata(nestedResourceInfo, this.DuplicatePropertyNameChecker, count: false); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The count parameter should be set to true when calling WriteNavigationLinkMetadata for nested resource info with content.
Suggested change
Copilot is powered by AI, so mistakes are possible. Review output carefully before use. |
||||||
} | ||||||
else | ||||||
{ | ||||||
|
@@ -2038,7 +2038,7 @@ protected override Task WriteDeferredNestedResourceInfoAsync(ODataNestedResource | |||||
// A deferred nested resource info is just the link metadata, no value. | ||||||
return this.jsonResourceSerializer.WriteNavigationLinkMetadataAsync( | ||||||
nestedResourceInfo, | ||||||
this.DuplicatePropertyNameChecker); | ||||||
this.DuplicatePropertyNameChecker, count: true); | ||||||
xuzhg marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
|
||||||
/// <summary> | ||||||
|
@@ -2078,7 +2078,7 @@ await this.jsonResourceSerializer.WriteNestedResourceInfoContextUrlAsync(innerNe | |||||
// Write the nested resource info metadata first. The rest is written by the content resource or resource set. | ||||||
await this.jsonResourceSerializer.WriteNavigationLinkMetadataAsync( | ||||||
innerNestedResourceInfo, | ||||||
this.DuplicatePropertyNameChecker).ConfigureAwait(false); | ||||||
this.DuplicatePropertyNameChecker, count: false).ConfigureAwait(false); | ||||||
xuzhg marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
} | ||||||
else | ||||||
|
This file contains 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 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 |
---|---|---|
|
@@ -51,6 +51,21 @@ public void SerializedNavigationPropertyShouldIncludeNavigationLinkUrl() | |
Assert.Contains("[email protected]\":\"http://example.com/navigation", jsonResult); | ||
} | ||
|
||
[Fact] | ||
public void SerializedNavigationPropertyShouldIncludeCountIfApply() | ||
{ | ||
var jsonResult = this.SerializeJsonFragment(serializer => | ||
serializer.WriteNavigationLinkMetadata( | ||
new ODataNestedResourceInfo | ||
{ | ||
Name = "NavigationProperty", | ||
Count = 42 | ||
}, | ||
new DuplicatePropertyNameChecker(), true)); | ||
|
||
Assert.Contains("[email protected]\":42", jsonResult); | ||
} | ||
|
||
[Fact] | ||
public void WriteOperationsOnRequestsShouldThrow() | ||
{ | ||
|
This file contains 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 |
---|---|---|
|
@@ -311,6 +311,27 @@ public async Task WriteNavigationLinkMetadataAsync_WritesNavigationLinkMetadata( | |
"\"[email protected]\":\"http://tempuri.org/Categories(1)/BestSeller\"", result); | ||
} | ||
|
||
[Fact] | ||
public async Task WriteNavigationLinkMetadataAsync_WritesCountMetadata() | ||
{ | ||
var nestedResourceInfo = new ODataNestedResourceInfo | ||
{ | ||
Name = "BestSeller", | ||
IsCollection = true, | ||
Count = 42 | ||
}; | ||
|
||
var result = await SetupJsonResourceSerializerAndRunTestAsync( | ||
(jsonResourceSerializer) => | ||
{ | ||
return jsonResourceSerializer.WriteNavigationLinkMetadataAsync( | ||
nestedResourceInfo, | ||
new NullDuplicatePropertyNameChecker(), true); | ||
}); | ||
|
||
Assert.Equal("{\"[email protected]\":42", result); | ||
} | ||
|
||
[Fact] | ||
public async Task WriteNestedResourceInfoContextUrlAsync_WritesNestedResourceInfoContextUrl() | ||
{ | ||
|
This file contains 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 |
---|---|---|
|
@@ -842,6 +842,33 @@ public void WritingNestedInlinecountTest() | |
"\"[email protected]\":\"http://example.org/odata.svc/navigation\"," + | ||
"\"[email protected]\":1," + | ||
"\"ContainedCollectionNavProp\":[]" + | ||
"}" + | ||
"]" + | ||
"}"; | ||
Assert.Equal(expectedPayload, result); | ||
} | ||
|
||
[Fact] | ||
public void WritingNestedInlinecountWithoutContentTest() | ||
{ | ||
this.containedCollectionNavLink.Count = 42; | ||
ODataItem[] itemsToWrite = new ODataItem[] | ||
{ | ||
new ODataResourceSet(), | ||
this.entryWithOnlyData1, | ||
this.containedCollectionNavLink | ||
}; | ||
|
||
string resourcePath = "EntitySet"; | ||
string result = this.GetWriterOutputForContentTypeAndKnobValue("application/json;odata.metadata=minimal", true, itemsToWrite, Model, EntitySet, EntityType, null, null, resourcePath); | ||
|
||
string expectedPayload = "{" + | ||
"\"@odata.context\":\"http://example.org/odata.svc/$metadata#EntitySet\"," + | ||
"\"value\":[" + | ||
"{" + | ||
"\"ID\":101,\"Name\":\"Alice\"," + | ||
"\"[email protected]\":\"http://example.org/odata.svc/navigation\"," + | ||
"\"[email protected]\":42" + | ||
"}" + | ||
"]" + | ||
"}"; | ||
|
@@ -922,6 +949,50 @@ public void ReadingNestedInlinecountTest() | |
ODataResourceSet topFeed = feedList[1]; | ||
Assert.Null(topFeed.Count); | ||
} | ||
|
||
[Fact] | ||
public void ReadingNestedInlinecountWithoutContentTest() | ||
{ | ||
string payload = "{" + | ||
"\"@odata.context\":\"http://example.org/odata.svc/$metadata#EntitySet\"," + | ||
"\"value\":[" + | ||
"{" + | ||
"\"ID\":101,\"Name\":\"Alice\"," + | ||
"\"[email protected]\":\"http://example.org/odata.svc/$metadata#EntitySet(101)/ContainedCollectionNavProp\"," + | ||
"\"[email protected]\":\"http://example.org/odata.svc/navigation\"," + | ||
"\"[email protected]\":51" + | ||
"}" + | ||
"]" + | ||
"}"; | ||
InMemoryMessage message = new InMemoryMessage(); | ||
message.SetHeader("Content-Type", "application/json;odata.metadata=minimal"); | ||
message.Stream = new MemoryStream(Encoding.UTF8.GetBytes(payload)); | ||
List<ODataResourceSet> feedList = new List<ODataResourceSet>(); | ||
|
||
ODataNestedResourceInfo nestedResourceInfo = null; | ||
using (var messageReader = new ODataMessageReader((IODataResponseMessage)message, null, Model)) | ||
{ | ||
var reader = messageReader.CreateODataResourceSetReader(); | ||
while (reader.Read()) | ||
{ | ||
switch (reader.State) | ||
{ | ||
case ODataReaderState.ResourceSetEnd: | ||
feedList.Add(reader.Item as ODataResourceSet); | ||
break; | ||
|
||
case ODataReaderState.NestedResourceInfoStart: | ||
nestedResourceInfo = reader.Item as ODataNestedResourceInfo; | ||
break; | ||
|
||
} | ||
} | ||
} | ||
|
||
Assert.Single(feedList); // only contains the toplevel | ||
Assert.NotNull(nestedResourceInfo); | ||
Assert.Equal(51, nestedResourceInfo.Count); | ||
} | ||
#endregion Inlinecount Tests | ||
|
||
[Fact] | ||
|
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.
The count parameter should be set to false when calling WriteNavigationLinkMetadata for deferred nested resource info.
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.