@@ -87,6 +87,34 @@ public void Deserialize_should_return_expected_result(string json, string expect
87
87
result . Should ( ) . Be ( DateTimeOffset . Parse ( expectedResult ) ) ;
88
88
}
89
89
90
+ [ Theory ]
91
+ [ InlineData ( "{ x : [{ $numberDouble : '0' }, { $numberDouble : '0' }] }" , "0001-01-01T00:00:00+00:00" ) ]
92
+ [ InlineData ( "{ x : [{ $numberDouble : '621355968000000000' }, { $numberDouble : '0' }] }" , "1970-01-01T00:00:00+00:00" ) ]
93
+ [ InlineData ( "{ x : [{ $numberDouble : '621355968000000000' }, { $numberDouble : '60' }] }" , "1970-01-01T00:00:00+01:00" ) ]
94
+ [ InlineData ( "{ x : [{ $numberDouble : '621355968000000000' }, { $numberDouble : '-60' }] }" , "1970-01-01T00:00:00-01:00" ) ]
95
+ [ InlineData ( "{ x : { DateTime : 'ignored', Ticks : { $numberDouble : 0 }, Offset : { $numberDouble : '0' } } }" , "0001-01-01T00:00:00Z" ) ]
96
+ [ InlineData ( "{ x : { DateTime : 'ignored', Ticks : { $numberDouble : '621355968000000000' }, Offset : { $numberDouble : '0' } } }" , "1970-01-01T00:00:00Z" ) ]
97
+ [ InlineData ( "{ x : { DateTime : 'ignored', Ticks : { $numberDouble : '621355968000000000' }, Offset : { $numberDouble : '60' } } }" , "1970-01-01T00:00:00+01:00" ) ]
98
+ [ InlineData ( "{ x : { DateTime : 'ignored', Ticks : { $numberDouble : '621355968000000000' }, Offset : { $numberDouble : '-60' } } }" , "1970-01-01T00:00:00-01:00" ) ]
99
+ public void Deserialize_should_be_forgiving_of_actual_numeric_types ( string json , string expectedResult )
100
+ {
101
+ var x = DateTimeOffset . Parse ( expectedResult ) ;
102
+ var m = BsonUtils . ToMillisecondsSinceEpoch ( x . UtcDateTime ) ;
103
+ var subject = new DateTimeOffsetSerializer ( ) ;
104
+
105
+ DateTimeOffset result ;
106
+ using ( var reader = new JsonReader ( json ) )
107
+ {
108
+ reader . ReadStartDocument ( ) ;
109
+ reader . ReadName ( "x" ) ;
110
+ var context = BsonDeserializationContext . CreateRoot ( reader ) ;
111
+ result = subject . Deserialize ( context ) ;
112
+ reader . ReadEndDocument ( ) ;
113
+ }
114
+
115
+ result . Should ( ) . Be ( DateTimeOffset . Parse ( expectedResult ) ) ;
116
+ }
117
+
90
118
[ Theory ]
91
119
[ InlineData ( BsonType . Array , "0001-01-01T00:00:00Z" , "{ \" x\" : [{ \" $numberLong\" : \" 0\" }, { \" $numberInt\" : \" 0\" }] }" ) ]
92
120
[ InlineData ( BsonType . Array , "1970-01-01T00:00:00Z" , "{ \" x\" : [{ \" $numberLong\" : \" 621355968000000000\" }, { \" $numberInt\" : \" 0\" }] }" ) ]
0 commit comments