@@ -49,7 +49,7 @@ public void JsonWriter_should_support_writing_multiple_documents(
49
49
string documentSeparator )
50
50
{
51
51
var document = new BsonDocument ( "x" , 1 ) ;
52
- var json = document . ToJson ( ) ;
52
+ var json = document . ToJson ( writerSettings : new JsonWriterSettings { OutputMode = JsonOutputMode . Shell } ) ;
53
53
var expectedResult = Enumerable . Repeat ( json , numberOfDocuments ) . Aggregate ( "" , ( a , j ) => a + j + documentSeparator ) ;
54
54
55
55
using ( var stringWriter = new StringWriter ( ) )
@@ -69,11 +69,20 @@ public void JsonWriter_should_support_writing_multiple_documents(
69
69
}
70
70
}
71
71
72
+ [ Fact ]
73
+ public void JsonWriter_should_have_relaxed_extended_json_as_default ( )
74
+ {
75
+ using var stringWriter = new StringWriter ( ) ;
76
+ using var jsonWriter = new JsonWriter ( stringWriter ) ;
77
+
78
+ jsonWriter . Settings . OutputMode . Should ( ) . Be ( JsonOutputMode . RelaxedExtendedJson ) ;
79
+ }
80
+
72
81
[ Fact ]
73
82
public void TestEmptyDocument ( )
74
83
{
75
84
BsonDocument document = new BsonDocument ( ) ;
76
- string json = document . ToJson ( ) ;
85
+ string json = document . ToJson ( writerSettings : new JsonWriterSettings { OutputMode = JsonOutputMode . Shell } ) ;
77
86
string expected = "{ }" ;
78
87
Assert . Equal ( expected , json ) ;
79
88
}
@@ -82,7 +91,7 @@ public void TestEmptyDocument()
82
91
public void TestSingleString ( )
83
92
{
84
93
BsonDocument document = new BsonDocument ( ) { { "abc" , "xyz" } } ;
85
- string json = document . ToJson ( ) ;
94
+ string json = document . ToJson ( writerSettings : new JsonWriterSettings { OutputMode = JsonOutputMode . Shell } ) ;
86
95
string expected = "{ \" abc\" : \" xyz\" }" ;
87
96
Assert . Equal ( expected , json ) ;
88
97
}
@@ -139,7 +148,7 @@ public void TestDecimal128Shell()
139
148
} ;
140
149
foreach ( var test in tests )
141
150
{
142
- var json = new BsonDecimal128 ( test . Value ) . ToJson ( ) ;
151
+ var json = new BsonDecimal128 ( test . Value ) . ToJson ( writerSettings : new JsonWriterSettings { OutputMode = JsonOutputMode . Shell } ) ;
143
152
Assert . Equal ( test . Expected , json ) ;
144
153
Assert . Equal ( test . Value , BsonSerializer . Deserialize < Decimal128 > ( json ) ) ;
145
154
}
@@ -207,7 +216,7 @@ public void TestDouble()
207
216
} ;
208
217
foreach ( var test in tests )
209
218
{
210
- var json = test . Value . ToJson ( ) ;
219
+ var json = test . Value . ToJson ( writerSettings : new JsonWriterSettings { OutputMode = JsonOutputMode . Shell } ) ;
211
220
Assert . Equal ( test . Expected , json ) ;
212
221
Assert . Equal ( test . Value , BsonSerializer . Deserialize < double > ( json ) ) ;
213
222
}
@@ -219,7 +228,7 @@ public void TestDoubleRoundTripOn64BitProcess()
219
228
RequireProcess . Check ( ) . Bits ( 64 ) ;
220
229
var value = 0.6822871999174 ; // see: https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx#RFormatString
221
230
222
- var json = value . ToJson ( ) ;
231
+ var json = value . ToJson ( writerSettings : new JsonWriterSettings { OutputMode = JsonOutputMode . Shell } ) ;
223
232
var rehydrated = BsonSerializer . Deserialize < double > ( json ) ;
224
233
225
234
rehydrated . Should ( ) . Be ( value ) ;
@@ -240,7 +249,7 @@ public void TestInt64Shell()
240
249
} ;
241
250
foreach ( var test in tests )
242
251
{
243
- var json = test . Value . ToJson ( ) ;
252
+ var json = test . Value . ToJson ( writerSettings : new JsonWriterSettings { OutputMode = JsonOutputMode . Shell } ) ;
244
253
Assert . Equal ( test . Expected , json ) ;
245
254
Assert . Equal ( test . Value , BsonSerializer . Deserialize < long > ( json ) ) ;
246
255
}
@@ -277,7 +286,7 @@ public void TestEmbeddedDocument()
277
286
{
278
287
{ "doc" , new BsonDocument { { "a" , 1 } , { "b" , 2 } } }
279
288
} ;
280
- string json = document . ToJson ( ) ;
289
+ string json = document . ToJson ( writerSettings : new JsonWriterSettings { OutputMode = JsonOutputMode . Shell } ) ;
281
290
string expected = "{ \" doc\" : { \" a\" : 1, \" b\" : 2 } }" ;
282
291
Assert . Equal ( expected , json ) ;
283
292
}
@@ -302,7 +311,7 @@ public void TestArray()
302
311
{
303
312
{ "array" , new BsonArray { 1 , 2 , 3 } }
304
313
} ;
305
- string json = document . ToJson ( ) ;
314
+ string json = document . ToJson ( writerSettings : new JsonWriterSettings { OutputMode = JsonOutputMode . Shell } ) ;
306
315
string expected = "{ \" array\" : [1, 2, 3] }" ;
307
316
Assert . Equal ( expected , json ) ;
308
317
}
@@ -321,7 +330,7 @@ public void TestBinaryShell()
321
330
} ;
322
331
foreach ( var test in tests )
323
332
{
324
- var json = test . Value . ToJson ( new JsonWriterSettings ( ) ) ;
333
+ var json = test . Value . ToJson ( new JsonWriterSettings { OutputMode = JsonOutputMode . Shell } ) ;
325
334
Assert . Equal ( test . Expected , json ) ;
326
335
Assert . Equal ( test . Value , BsonSerializer . Deserialize < BsonBinaryData > ( json ) ) ;
327
336
}
@@ -368,7 +377,7 @@ public void TestDateTimeShell()
368
377
} ;
369
378
foreach ( var test in tests )
370
379
{
371
- var json = test . Value . ToJson ( ) ;
380
+ var json = test . Value . ToJson ( writerSettings : new JsonWriterSettings { OutputMode = JsonOutputMode . Shell } ) ;
372
381
Assert . Equal ( test . Expected , json ) ;
373
382
Assert . Equal ( test . Value , BsonSerializer . Deserialize < BsonDateTime > ( json ) ) ;
374
383
}
@@ -410,7 +419,7 @@ public void TestJavaScript()
410
419
{ "f" , new BsonJavaScript ( "function f() { return 1; }" ) }
411
420
} ;
412
421
string expected = "{ \" f\" : { \" $code\" : \" function f() { return 1; }\" } }" ;
413
- string actual = document . ToJson ( ) ;
422
+ string actual = document . ToJson ( writerSettings : new JsonWriterSettings { OutputMode = JsonOutputMode . Shell } ) ;
414
423
Assert . Equal ( expected , actual ) ;
415
424
}
416
425
@@ -422,7 +431,7 @@ public void TestJavaScriptWithScope()
422
431
{ "f" , new BsonJavaScriptWithScope ( "function f() { return n; }" , new BsonDocument ( "n" , 1 ) ) }
423
432
} ;
424
433
string expected = "{ \" f\" : { \" $code\" : \" function f() { return n; }\" , \" $scope\" : { \" n\" : 1 } } }" ;
425
- string actual = document . ToJson ( ) ;
434
+ string actual = document . ToJson ( writerSettings : new JsonWriterSettings { OutputMode = JsonOutputMode . Shell } ) ;
426
435
Assert . Equal ( expected , actual ) ;
427
436
}
428
437
@@ -433,7 +442,7 @@ public void TestUuidStandardWhenGuidRepresentationIsUnspecified()
433
442
var guidBytes = GuidConverter . ToBytes ( guid , GuidRepresentation . Standard ) ;
434
443
435
444
var binary = new BsonBinaryData ( guidBytes , BsonBinarySubType . UuidStandard ) ; // GuidRepresentation is Unspecified
436
- var result = binary . ToJson ( writerSettings : new JsonWriterSettings ( ) ) ;
445
+ var result = binary . ToJson ( writerSettings : new JsonWriterSettings { OutputMode = JsonOutputMode . Shell } ) ;
437
446
result . Should ( ) . Be ( "UUID(\" 00112233-4455-6677-8899-aabbccddeeff\" )" ) ;
438
447
}
439
448
@@ -445,7 +454,7 @@ public void TestMaxKey()
445
454
{ "maxkey" , BsonMaxKey . Value }
446
455
} ;
447
456
string expected = "{ \" maxkey\" : MaxKey }" ;
448
- string actual = document . ToJson ( ) ;
457
+ string actual = document . ToJson ( writerSettings : new JsonWriterSettings { OutputMode = JsonOutputMode . Shell } ) ;
449
458
Assert . Equal ( expected , actual ) ;
450
459
}
451
460
@@ -457,7 +466,7 @@ public void TestMinKey()
457
466
{ "minkey" , BsonMinKey . Value }
458
467
} ;
459
468
string expected = "{ \" minkey\" : MinKey }" ;
460
- string actual = document . ToJson ( ) ;
469
+ string actual = document . ToJson ( writerSettings : new JsonWriterSettings { OutputMode = JsonOutputMode . Shell } ) ;
461
470
Assert . Equal ( expected , actual ) ;
462
471
}
463
472
@@ -469,15 +478,15 @@ public void TestNull()
469
478
{ "null" , BsonNull . Value }
470
479
} ;
471
480
string expected = "{ \" null\" : null }" ;
472
- string actual = document . ToJson ( ) ;
481
+ string actual = document . ToJson ( writerSettings : new JsonWriterSettings { OutputMode = JsonOutputMode . Shell } ) ;
473
482
Assert . Equal ( expected , actual ) ;
474
483
}
475
484
476
485
[ Fact ]
477
486
public void TestObjectIdShell ( )
478
487
{
479
488
var objectId = new ObjectId ( "4d0ce088e447ad08b4721a37" ) ;
480
- var json = objectId . ToJson ( ) ;
489
+ var json = objectId . ToJson ( writerSettings : new JsonWriterSettings { OutputMode = JsonOutputMode . Shell } ) ;
481
490
var expected = "ObjectId(\" 4d0ce088e447ad08b4721a37\" )" ;
482
491
Assert . Equal ( expected , json ) ;
483
492
Assert . Equal ( objectId , BsonSerializer . Deserialize < ObjectId > ( json ) ) ;
@@ -513,7 +522,7 @@ public void TestRegularExpressionShell()
513
522
} ;
514
523
foreach ( var test in tests )
515
524
{
516
- var json = test . Value . ToJson ( ) ;
525
+ var json = test . Value . ToJson ( writerSettings : new JsonWriterSettings { OutputMode = JsonOutputMode . Shell } ) ;
517
526
Assert . Equal ( test . Expected , json ) ;
518
527
Assert . Equal ( test . Value , BsonSerializer . Deserialize < BsonRegularExpression > ( json ) ) ;
519
528
}
@@ -573,7 +582,7 @@ public void TestString()
573
582
} ;
574
583
foreach ( var test in tests )
575
584
{
576
- var json = test . Value . ToJson ( ) ;
585
+ var json = test . Value . ToJson ( writerSettings : new JsonWriterSettings { OutputMode = JsonOutputMode . Shell } ) ;
577
586
Assert . Equal ( test . Expected , json ) ;
578
587
Assert . Equal ( test . Value , BsonSerializer . Deserialize < string > ( json ) ) ;
579
588
}
@@ -587,7 +596,7 @@ public void TestSymbol()
587
596
{ "symbol" , BsonSymbolTable . Lookup ( "name" ) }
588
597
} ;
589
598
string expected = "{ \" symbol\" : { \" $symbol\" : \" name\" } }" ;
590
- string actual = document . ToJson ( ) ;
599
+ string actual = document . ToJson ( writerSettings : new JsonWriterSettings { OutputMode = JsonOutputMode . Shell } ) ;
591
600
Assert . Equal ( expected , actual ) ;
592
601
}
593
602
@@ -599,7 +608,7 @@ public void TestTimestamp()
599
608
{ "timestamp" , new BsonTimestamp ( 1 , 2 ) }
600
609
} ;
601
610
string expected = "{ \" timestamp\" : Timestamp(1, 2) }" ;
602
- string actual = document . ToJson ( ) ;
611
+ string actual = document . ToJson ( writerSettings : new JsonWriterSettings { OutputMode = JsonOutputMode . Shell } ) ;
603
612
Assert . Equal ( expected , actual ) ;
604
613
}
605
614
@@ -611,7 +620,7 @@ public void TestUndefined()
611
620
{ "undefined" , BsonUndefined . Value }
612
621
} ;
613
622
string expected = "{ \" undefined\" : undefined }" ;
614
- string actual = document . ToJson ( ) ;
623
+ string actual = document . ToJson ( writerSettings : new JsonWriterSettings { OutputMode = JsonOutputMode . Shell } ) ;
615
624
Assert . Equal ( expected , actual ) ;
616
625
}
617
626
0 commit comments