33using System . Dynamic ;
44using System . IO ;
55using System . Linq ;
6+ using System . Text . Json ;
7+ using System . Text . Json . Nodes ;
68using System . Text . RegularExpressions ;
79using System . Threading . Tasks ;
8- using Newtonsoft . Json . Linq ;
910using NSubstitute ;
1011using Xunit ;
1112
@@ -20,7 +21,7 @@ public void UpdateAll()
2021
2122 var store = new DataStore ( newFilePath ) ;
2223
23- store . UpdateAll ( "{ ' tasks' : [ { 'id' : 0, ' task': ' Commit' } ] }" ) ;
24+ store . UpdateAll ( "{ \" tasks\" : [ { \" id \" : 0, \" task\" : \" Commit\" } ] }" ) ;
2425
2526 var collection = store . GetCollection ( "tasks" ) ;
2627 Assert . Equal ( 1 , collection . Count ) ;
@@ -187,7 +188,7 @@ public async Task Readme_Example2()
187188 } ;
188189
189190 // Example with JSON object
190- var employeeJson = JToken . Parse ( "{ 'id' : 2, ' name': ' Raymond', ' age' : 32 }" ) ;
191+ var employeeJson = JsonNode . Parse ( "{ \" id \" : 2, \" name\" : \" Raymond\" , \" age\" : 32 }" ) ;
191192
192193 // Example with JSON object
193194 var employeeDict = new Dictionary < string , object >
@@ -213,7 +214,7 @@ public async Task Readme_Example2()
213214 var updateData = new { name = "John Doe" } ;
214215 await collection . UpdateOneAsync ( e => e . id == employee . id , updateData ) ;
215216
216- var updateJson = JObject . Parse ( "{ ' name': ' Raymond Doe' }" ) ;
217+ var updateJson = JsonNode . Parse ( "{ \" name\" : \" Raymond Doe\" }" ) ;
217218 await collection . UpdateOneAsync ( e => e . id == 1 , updateJson ) ;
218219
219220 var updateDict = new Dictionary < string , object > { [ "name" ] = "Andy Doe" } ;
@@ -248,7 +249,7 @@ public async Task Insert_CorrectIdWithDynamic()
248249 } ;
249250
250251 // Example with JSON object
251- var employeeJson = JToken . Parse ( "{ 'id' : 200, ' name': ' Raymond', ' age' : 32 }" ) ;
252+ var employeeJson = JsonNode . Parse ( "{ \" id \" : 200, \" name\" : \" Raymond\" , \" age\" : 32 }" ) ;
252253
253254 // Example with JSON object
254255 var employeeDict = new Dictionary < string , object >
@@ -295,7 +296,7 @@ public async Task Insert_CorrectIdWithDynamic_No_InitialId()
295296 } ;
296297
297298 // Example with JSON object
298- var employeeJson = JToken . Parse ( "{ ' name': ' Raymond', ' age' : 32 }" ) ;
299+ var employeeJson = JsonNode . Parse ( "{ \" name\" : \" Raymond\" , \" age\" : 32 }" ) ;
299300
300301 // Example with JSON object
301302 var employeeDict = new Dictionary < string , object >
@@ -315,7 +316,10 @@ public async Task Insert_CorrectIdWithDynamic_No_InitialId()
315316 await collection . InsertOneAsync ( employeeDict ) ;
316317 await collection . InsertOneAsync ( employeeExpando ) ;
317318
318- Assert . Equal ( 1 , employeeJson [ "acc" ] ) ;
319+ // System.Text.Json: JsonNode indexer returns JsonNode, requires explicit GetValue<T>()
320+ // Newtonsoft.Json: JToken had implicit conversion operators, allowed direct comparison
321+ Assert . Equal ( 1 , employeeJson [ "acc" ] . GetValue < int > ( ) ) ;
322+ // Dictionary and ExpandoObject return 'object' (boxed int), which Assert.Equal handles directly
319323 Assert . Equal ( 2 , employeeDict [ "acc" ] ) ;
320324 Assert . Equal ( 3 , ( ( IDictionary < string , object > ) employeeExpando ) [ "acc" ] ) ;
321325
@@ -340,7 +344,7 @@ public async Task Insert_CorrectIdWithDynamic_With_InitialId()
340344 } ;
341345
342346 // Example with JSON object
343- var employeeJson = JToken . Parse ( "{ ' name': ' Raymond', ' age' : 32 }" ) ;
347+ var employeeJson = JsonNode . Parse ( "{ \" name\" : \" Raymond\" , \" age\" : 32 }" ) ;
344348
345349 // Example with JSON object
346350 var employeeDict = new Dictionary < string , object >
@@ -361,7 +365,10 @@ public async Task Insert_CorrectIdWithDynamic_With_InitialId()
361365 await collection . InsertOneAsync ( employeeExpando ) ;
362366
363367 Assert . Equal ( "hello" , employee . acc ) ;
364- Assert . Equal ( "hello0" , employeeJson [ "acc" ] ) ;
368+ // System.Text.Json: JsonNode indexer returns JsonNode, requires explicit GetValue<T>()
369+ // Newtonsoft.Json: JToken had implicit conversion operators, allowed direct comparison
370+ Assert . Equal ( "hello0" , employeeJson [ "acc" ] . GetValue < string > ( ) ) ;
371+ // Dictionary and ExpandoObject return 'object' (boxed string), which Assert.Equal handles directly
365372 Assert . Equal ( "hello1" , employeeDict [ "acc" ] ) ;
366373 Assert . Equal ( "hello2" , ( ( IDictionary < string , object > ) employeeExpando ) [ "acc" ] ) ;
367374
0 commit comments