-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #3154: Enable serialize/deserialize navigation property with co…
…unt without content
- Loading branch information
Showing
7 changed files
with
150 additions
and
7 deletions.
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
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] | ||
|