1313* limitations under the License.
1414*/
1515
16+ using System ;
1617using MongoDB . Bson ;
1718using MongoDB . Driver ;
1819using MongoDB . Driver . Builders ;
@@ -26,33 +27,38 @@ public class CSharp358Tests
2627 [ Test ]
2728 public void TestInsertUpdateAndSaveWithElementNameStartingWithDollarSign ( )
2829 {
30+ // starting with version 2.5.2 the server got stricter about dollars in element names
31+ // so this test should only be run when testing against older servers
2932 var server = Configuration . TestServer ;
30- var database = Configuration . TestDatabase ;
31- var collection = Configuration . TestCollection ;
32- collection . Drop ( ) ;
33-
34- var document = new BsonDocument
33+ if ( server . BuildInfo . Version < new Version ( 2 , 5 , 2 ) )
3534 {
36- { "_id" , 1 } ,
37- { "v" , new BsonDocument ( "$x" , 1 ) } // server doesn't allow "$" at top level
38- } ;
39- var insertOptions = new MongoInsertOptions { CheckElementNames = false } ;
40- collection . Insert ( document , insertOptions ) ;
41- document = collection . FindOne ( ) ;
42- Assert . AreEqual ( 1 , document [ "v" ] [ "$x" ] . AsInt32 ) ;
35+ var database = Configuration . TestDatabase ;
36+ var collection = Configuration . TestCollection ;
37+ collection . Drop ( ) ;
38+
39+ var document = new BsonDocument
40+ {
41+ { "_id" , 1 } ,
42+ { "v" , new BsonDocument ( "$x" , 1 ) } // server doesn't allow "$" at top level
43+ } ;
44+ var insertOptions = new MongoInsertOptions { CheckElementNames = false } ;
45+ collection . Insert ( document , insertOptions ) ;
46+ document = collection . FindOne ( ) ;
47+ Assert . AreEqual ( 1 , document [ "v" ] [ "$x" ] . AsInt32 ) ;
4348
44- document [ "v" ] [ "$x" ] = 2 ;
45- var query = Query . EQ ( "_id" , 1 ) ;
46- var update = Update . Replace ( document ) ;
47- var updateOptions = new MongoUpdateOptions { CheckElementNames = false } ;
48- collection . Update ( query , update , updateOptions ) ;
49- document = collection . FindOne ( ) ;
50- Assert . AreEqual ( 2 , document [ "v" ] [ "$x" ] . AsInt32 ) ;
49+ document [ "v" ] [ "$x" ] = 2 ;
50+ var query = Query . EQ ( "_id" , 1 ) ;
51+ var update = Update . Replace ( document ) ;
52+ var updateOptions = new MongoUpdateOptions { CheckElementNames = false } ;
53+ collection . Update ( query , update , updateOptions ) ;
54+ document = collection . FindOne ( ) ;
55+ Assert . AreEqual ( 2 , document [ "v" ] [ "$x" ] . AsInt32 ) ;
5156
52- document [ "v" ] [ "$x" ] = 3 ;
53- collection . Save ( document , insertOptions ) ;
54- document = collection . FindOne ( ) ;
55- Assert . AreEqual ( 3 , document [ "v" ] [ "$x" ] . AsInt32 ) ;
57+ document [ "v" ] [ "$x" ] = 3 ;
58+ collection . Save ( document , insertOptions ) ;
59+ document = collection . FindOne ( ) ;
60+ Assert . AreEqual ( 3 , document [ "v" ] [ "$x" ] . AsInt32 ) ;
61+ }
5662 }
5763 }
5864}
0 commit comments