Skip to content

Commit 714f065

Browse files
committed
Retrieve the navigation properties if there's on $expand for delta serializer
1 parent bf26422 commit 714f065

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

src/Microsoft.AspNet.OData.Shared/Formatter/Serialization/ODataResourceSerializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1808,7 +1808,7 @@ private IEnumerable<KeyValuePair<IEdmNavigationProperty, Type>> GetNavigationPro
18081808

18091809
if (navigationProperties == null)
18101810
{
1811-
yield break;
1811+
navigationProperties = resourceContext.StructuredType.DeclaredNavigationProperties();
18121812
}
18131813

18141814
if (resourceContext.EdmObject is IDelta changedObject)

test/E2ETest/Microsoft.Test.E2E.AspNet.OData/BulkOperation/BulkOperationTest.cs

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,69 @@ protected override void UpdateConfiguration(WebRouteConfiguration configuration)
4242
}
4343

4444
#region Update
45-
45+
46+
[Fact]
47+
public async Task PatchEmployee_WithNestedFriends_WithNestedOrders_IsSerializedSuccessfully()
48+
{
49+
//Arrange
50+
string requestUri = this.BaseAddress + "/convention/Employees";
51+
var content = @"{
52+
'@odata.context':'http://host/service/$metadata#Employees/$delta',
53+
'value':[
54+
{'ID':1,'Name':'Employee1','[email protected]':[{'Id':1,'Name':'Friend1','[email protected]':[{'Id':1,'Price': 10},{'Id':2,'Price':20} ]},{'Id':2,'Name':'Friend2'}]},
55+
{'ID':2,'Name':'Employee2','[email protected]':[{'Id':3,'Name':'Friend3','[email protected]' :[{'Id':3,'Price': 30}, {'Id':4,'Price': 40} ]},{'Id':4,'Name':'Friend4'}]}
56+
]}";
57+
58+
var requestForPatch = new HttpRequestMessage(new HttpMethod("PATCH"), requestUri);
59+
60+
string expectedResponse = "{" +
61+
"\"@context\":\"" + this.BaseAddress + "/convention/$metadata#Employees/$delta\"," +
62+
"\"value\":[" +
63+
"{\"ID\":1,\"Name\":\"Employee1\",\"SkillSet\":[],\"Gender\":\"0\",\"AccessLevel\":\"0\",\"FavoriteSports\":null,\"Friends@delta\":[{\"Id\":1,\"Name\":\"Friend1\",\"Age\":0,\"Orders@delta\":[{\"Id\":1,\"Price\":10},{\"Id\":2,\"Price\":20}]},{\"Id\":2,\"Name\":\"Friend2\",\"Age\":0}]}," +
64+
"{\"ID\":2,\"Name\":\"Employee2\",\"SkillSet\":[],\"Gender\":\"0\",\"AccessLevel\":\"0\",\"FavoriteSports\":null,\"Friends@delta\":[{\"Id\":3,\"Name\":\"Friend3\",\"Age\":0,\"Orders@delta\":[{\"Id\":3,\"Price\":30},{\"Id\":4,\"Price\":40}]},{\"Id\":4,\"Name\":\"Friend4\",\"Age\":0}]}]}";
65+
StringContent stringContent = new StringContent(content: content, encoding: Encoding.UTF8, mediaType: "application/json");
66+
requestForPatch.Content = stringContent;
67+
68+
// Act & Assert
69+
using (HttpResponseMessage response = await this.Client.SendAsync(requestForPatch))
70+
{
71+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
72+
var json = response.Content.ReadAsStringAsync().Result;
73+
Assert.Equal(expectedResponse.ToString().ToLower(), json.ToString().ToLower());
74+
Assert.Contains("Employee1", json);
75+
Assert.Contains("Employee2", json);
76+
}
77+
}
78+
79+
[Fact]
80+
public async Task PatchEmployee_WithDeletedAndODataId_IsSerializedSuccessfully()
81+
{
82+
//Arrange
83+
string requestUri = this.BaseAddress + "/convention/Employees";
84+
85+
var content = @"{
86+
'@odata.context':'http://host/service/$metadata#Employees/$delta',
87+
'value':[
88+
{'ID':1,'Name':'Employee1','[email protected]':[{'@odata.removed':{'reason':'changed'},'Id':1}]},
89+
{'ID':2,'Name':'Employee2','[email protected]':[{'@odata.id':'Friends(1)'}]}
90+
]}";
91+
92+
string expectedResponse = "{\"@context\":\"" + this.BaseAddress + "/convention/$metadata#Employees/$delta\",\"value\":[{\"ID\":1,\"Name\":\"Employee1\",\"SkillSet\":[],\"Gender\":\"0\",\"AccessLevel\":\"0\",\"FavoriteSports\":null,\"Friends@delta\":[{\"@removed\":{\"reason\":\"changed\"},\"@id\":\"http://host/service/Friends(1)\",\"Id\":1,\"Name\":null,\"Age\":0}]},{\"ID\":2,\"Name\":\"Employee2\",\"SkillSet\":[],\"Gender\":\"0\",\"AccessLevel\":\"0\",\"FavoriteSports\":null,\"Friends@delta\":[{\"Id\":0,\"Name\":null,\"Age\":0}]}]}";
93+
94+
var requestForUpdate = new HttpRequestMessage(new HttpMethod("PATCH"), requestUri);
95+
96+
StringContent stringContent = new StringContent(content: content, encoding: Encoding.UTF8, mediaType: "application/json");
97+
requestForUpdate.Content = stringContent;
98+
99+
//Act & Assert
100+
using (HttpResponseMessage response = await this.Client.SendAsync(requestForUpdate))
101+
{
102+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
103+
var json = response.Content.ReadAsStringAsync().Result;
104+
Assert.Equal(expectedResponse.ToString().ToLower(), json.ToString().ToLower());
105+
}
106+
}
107+
46108
[Fact]
47109
public async Task PatchEmployee_WithUpdates()
48110
{

0 commit comments

Comments
 (0)