-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retrieve the navigation properties if there's on $expand for delta se…
…rializer
- Loading branch information
Showing
2 changed files
with
64 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,69 @@ protected override void UpdateConfiguration(WebRouteConfiguration configuration) | |
} | ||
|
||
#region Update | ||
|
||
|
||
[Fact] | ||
public async Task PatchEmployee_WithNestedFriends_WithNestedOrders_IsSerializedSuccessfully() | ||
{ | ||
//Arrange | ||
string requestUri = this.BaseAddress + "/convention/Employees"; | ||
var content = @"{ | ||
'@odata.context':'http://host/service/$metadata#Employees/$delta', | ||
'value':[ | ||
{'ID':1,'Name':'Employee1','[email protected]':[{'Id':1,'Name':'Friend1','[email protected]':[{'Id':1,'Price': 10},{'Id':2,'Price':20} ]},{'Id':2,'Name':'Friend2'}]}, | ||
{'ID':2,'Name':'Employee2','[email protected]':[{'Id':3,'Name':'Friend3','[email protected]' :[{'Id':3,'Price': 30}, {'Id':4,'Price': 40} ]},{'Id':4,'Name':'Friend4'}]} | ||
]}"; | ||
|
||
var requestForPatch = new HttpRequestMessage(new HttpMethod("PATCH"), requestUri); | ||
|
||
string expectedResponse = "{" + | ||
"\"@context\":\"" + this.BaseAddress + "/convention/$metadata#Employees/$delta\"," + | ||
"\"value\":[" + | ||
"{\"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}]}," + | ||
"{\"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}]}]}"; | ||
StringContent stringContent = new StringContent(content: content, encoding: Encoding.UTF8, mediaType: "application/json"); | ||
requestForPatch.Content = stringContent; | ||
|
||
// Act & Assert | ||
using (HttpResponseMessage response = await this.Client.SendAsync(requestForPatch)) | ||
{ | ||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
var json = response.Content.ReadAsStringAsync().Result; | ||
Assert.Equal(expectedResponse.ToString().ToLower(), json.ToString().ToLower()); | ||
Assert.Contains("Employee1", json); | ||
Assert.Contains("Employee2", json); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task PatchEmployee_WithDeletedAndODataId_IsSerializedSuccessfully() | ||
{ | ||
//Arrange | ||
string requestUri = this.BaseAddress + "/convention/Employees"; | ||
|
||
var content = @"{ | ||
'@odata.context':'http://host/service/$metadata#Employees/$delta', | ||
'value':[ | ||
{'ID':1,'Name':'Employee1','[email protected]':[{'@odata.removed':{'reason':'changed'},'Id':1}]}, | ||
{'ID':2,'Name':'Employee2','[email protected]':[{'@odata.id':'Friends(1)'}]} | ||
]}"; | ||
|
||
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}]}]}"; | ||
|
||
var requestForUpdate = new HttpRequestMessage(new HttpMethod("PATCH"), requestUri); | ||
|
||
StringContent stringContent = new StringContent(content: content, encoding: Encoding.UTF8, mediaType: "application/json"); | ||
requestForUpdate.Content = stringContent; | ||
|
||
//Act & Assert | ||
using (HttpResponseMessage response = await this.Client.SendAsync(requestForUpdate)) | ||
{ | ||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
var json = response.Content.ReadAsStringAsync().Result; | ||
Assert.Equal(expectedResponse.ToString().ToLower(), json.ToString().ToLower()); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task PatchEmployee_WithUpdates() | ||
{ | ||
|