File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed 
tests/MongoDB.Bson.Tests/IO Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -1961,13 +1961,13 @@ private BsonValue ParseTimestampConstructor()
19611961            VerifyToken ( "," ) ; 
19621962            int  increment ; 
19631963            var  incrementToken  =  PopToken ( ) ; 
1964-             if  ( secondsSinceEpochToken . IsNumber ) 
1964+             if  ( incrementToken . IsNumber ) 
19651965            { 
19661966                increment  =  incrementToken . Int32Value ; 
19671967            } 
19681968            else 
19691969            { 
1970-                 var  message  =  string . Format ( "JSON reader expected a number but found '{0}'." ,  secondsSinceEpochToken . Lexeme ) ; 
1970+                 var  message  =  string . Format ( "JSON reader expected a number but found '{0}'." ,  incrementToken . Lexeme ) ; 
19711971                throw  new  FormatException ( message ) ; 
19721972            } 
19731973            VerifyToken ( ")" ) ; 
Original file line number Diff line number Diff line change @@ -1396,6 +1396,26 @@ public void TestTimestampConstructor()
13961396            Assert . Equal ( json ,  BsonSerializer . Deserialize < BsonTimestamp > ( new  StringReader ( json ) ) . ToJson ( ) ) ; 
13971397        } 
13981398
1399+         [ Theory ] 
1400+         // truncated input 
1401+         [ InlineData ( "Timestamp(" ) ] 
1402+         [ InlineData ( "Timestamp()" ) ] 
1403+         [ InlineData ( "Timestamp(1" ) ] 
1404+         [ InlineData ( "Timestamp(1," ) ] 
1405+         [ InlineData ( "Timestamp(1, 2" ) ] 
1406+         // valid JSON but not a valid extended JSON BsonTimestamp 
1407+         [ InlineData ( "Timestamp('abc', 2)" ) ] 
1408+         [ InlineData ( "Timestamp(2, 'abc')" ) ] 
1409+         public  void  TestTimestampConstructorWhenInvalid ( string  json ) 
1410+         { 
1411+             using  ( _bsonReader  =  new  JsonReader ( json ) ) 
1412+             { 
1413+                 var  exception  =  Record . Exception ( ( )  =>  _bsonReader . ReadBsonType ( ) ) ; 
1414+ 
1415+                 exception . Should ( ) . BeOfType < FormatException > ( ) ; 
1416+             } 
1417+         } 
1418+ 
13991419        [ Theory ] 
14001420        [ InlineData ( "{ \" $timestamp\"  : { \" t\"  : 1, \" i\"  : 2 } }" ) ] 
14011421        [ InlineData ( "{ \" $timestamp\"  : { \" i\"  : 2, \" t\"  : 1 } }" ) ] 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments