@@ -247,60 +247,38 @@ public void RemoveDefaultNullProperties_ShouldRemoveDefaultNullValuesInJsonObjec
247247 Assert . True ( result [ "body" ] ? [ "users" ] [ 0 ] ? [ "metadata" ] ? . ToObject < JObject > ( ) . ContainsKey ( "phone" ) ) ;
248248 }
249249
250+ /*
251+ Test for unescaping json object while maintaining original property definition of values
252+ instead of auto inferencing the type of the value
253+ "fields": "{\r\n \"BasicTag\": \"v2.31.0\",\r\n \"BuildID\": \"3599\",\r\n \"MWSCommitID\": \"a5c7998252f2366c8cbbb03ba46e9b\",\r\n \"MWSTag\": \"v2.21.0\",\r\n \"BasicCommitID\": \"9c3d0f36362dd25caa0da2ecab06a1859ce2\",\r\n \"CustomerCommitID\": \"c40241be9fd2f1cd2f2f2fc961c37f720c\"\r\n}"
254+ */
250255 [ Fact ]
251- public void NumericString_RemainsString ( )
252- {
256+ public void RemoveDefaultNullProperties_ShouldUnescapeJsonString ( ) {
253257 // Arrange
254258 JObject json = JObject . Parse ( @"{
255- ""displayname"": ""Tim"",
256- ""position"": ""123"",
257- ""salary"": 2000000
259+ ""fields"": ""{\r\n \""BasicTag\"": \""v2.31.0\"",\r\n \""BuildID\"": \""3599\"",\r\n \""MWSCommitID\"": \""a5c7998252f2366c8cbbb03ba46e9b\"",\r\n \""MWSTag\"": \""v2.21.0\"",\r\n \""BasicCommitID\"": \""9c3d0f36362dd25caa0da2ecab06a1859ce2\"",\r\n \""CustomerCommitID\"": \""c40241be9fd2f1cd2f2f2fc961c37f720c\""\r\n}""
258260 }" ) ;
259261
260- // Act
261- string cleanedJson = json . ToString ( ) ? . ReplaceAndRemoveSlashes ( ) ;
262- JObject result = JObject . Parse ( cleanedJson ) ;
263-
264- // Assert
265- Assert . Equal ( "123" , result [ "position" ] ? . ToString ( ) ) ;
266- Assert . Equal ( 2000000 , result [ "salary" ] ? . ToObject < int > ( ) ) ;
267- }
268- [ Fact ]
269- public void NumericString_RemainsStringInJsonArray ( )
270- {
271- // Arrange
272- JArray json = JArray . Parse ( @"[
273- { ""displayname"": ""Tim"", ""position"": ""123"" }
274-
275- ]" ) ;
276-
277- // Act
278- string cleanedJson = json . ToString ( ) ? . ReplaceAndRemoveSlashes ( ) ;
279- JArray result = JArray . Parse ( cleanedJson ) ;
280-
281- // Assert
282- Assert . Equal ( "123" , result [ 0 ] ? [ "position" ] ? . ToString ( ) ) ;
283- }
284-
285- [ Fact ]
286- public void NumericString_RemainsStringInNestedJsonObject ( )
287- {
288- // Arrange
289- JObject json = JObject . Parse ( @"{
290- ""body"":{
291- ""users"": [
292- { ""displayname"": ""Tim"", ""position"": ""123"" }
293- ]
262+ String expectedJson = @"{
263+ ""fields"": {
264+ ""BasicTag"": ""v2.31.0"",
265+ ""BuildID"": ""3599"",
266+ ""MWSCommitID"": ""a5c7998252f2366c8cbbb03ba46e9b"",
267+ ""MWSTag"": ""v2.21.0"",
268+ ""BasicCommitID"": ""9c3d0f36362dd25caa0da2ecab06a1859ce2"",
269+ ""CustomerCommitID"": ""c40241be9fd2f1cd2f2f2fc961c37f720c""
294270 }
295- }" ) ;
271+ }" ;
296272
297273 // Act
274+ //Convert Json object to string then pass it to RemoveAndReplaceSlashes method
298275 string cleanedJson = json . ToString ( ) ? . ReplaceAndRemoveSlashes ( ) ;
299- JObject result = JObject . Parse ( cleanedJson ) ;
300276
301277 // Assert
302- Assert . Equal ( "123" , result [ "body" ] ? [ "users" ] [ 0 ] ? [ "position" ] ? . ToString ( ) ) ;
303- Assert . Equal ( "Tim" , result [ "body" ] ? [ "users" ] [ 0 ] ? [ "displayname" ] ? . ToString ( ) ) ;
278+ Assert . Equal ( NormalizeJson ( expectedJson ) , NormalizeJson ( cleanedJson ) ) ;
304279 }
280+
281+
282+
305283}
306284
0 commit comments