@@ -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','Friends@odata.delta':[{'Id':1,'Name':'Friend1','Orders@odata.delta':[{'Id':1,'Price': 10},{'Id':2,'Price':20} ]},{'Id':2,'Name':'Friend2'}]},
55+ {'ID':2,'Name':'Employee2','Friends@odata.delta':[{'Id':3,'Name':'Friend3','Orders@odata.delta' :[{'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','Friends@odata.delta':[{'@odata.removed':{'reason':'changed'},'Id':1}]},
89+ {'ID':2,'Name':'Employee2','Friends@odata.delta':[{'@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