13
13
* limitations under the License.
14
14
*/
15
15
16
+ using System ;
16
17
using MongoDB . Bson ;
17
18
using MongoDB . Driver ;
18
19
using MongoDB . Driver . Builders ;
@@ -26,33 +27,38 @@ public class CSharp358Tests
26
27
[ Test ]
27
28
public void TestInsertUpdateAndSaveWithElementNameStartingWithDollarSign ( )
28
29
{
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
29
32
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 ) )
35
34
{
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 ) ;
43
48
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 ) ;
51
56
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
+ }
56
62
}
57
63
}
58
64
}
0 commit comments