@@ -985,12 +985,23 @@ public void TestFindAndModifyReplaceWithWriteConcernError()
985
985
VersionReturned = FindAndModifyDocumentVersion . Modified
986
986
} ;
987
987
988
- Action action = ( ) => collection . FindAndModify ( args ) ;
988
+ BsonDocument modifiedDocument ;
989
+ if ( _server . BuildInfo . Version >= new Version ( 3 , 2 , 0 ) )
990
+ {
991
+ Action action = ( ) => collection . FindAndModify ( args ) ;
992
+
993
+ var exception = action . ShouldThrow < MongoWriteConcernException > ( ) . Which ;
994
+ var commandResult = exception . Result ;
995
+ modifiedDocument = commandResult [ "value" ] . AsBsonDocument ;
996
+ }
997
+ else
998
+ {
999
+ var result = collection . FindAndModify ( args ) ;
1000
+
1001
+ modifiedDocument = result . ModifiedDocument ;
1002
+ }
989
1003
990
- var exception = action . ShouldThrow < MongoWriteConcernException > ( ) . Which ;
991
- var commandResult = exception . Result ;
992
- var result = commandResult [ "value" ] . AsBsonDocument ;
993
- result . Should ( ) . Be ( "{ _id : 1, x : 2 }" ) ;
1004
+ modifiedDocument . Should ( ) . Be ( "{ _id : 1, x : 2 }" ) ;
994
1005
}
995
1006
996
1007
[ Test ]
@@ -1011,12 +1022,23 @@ public void TestFindAndModifyUpdateWithWriteConcernError()
1011
1022
VersionReturned = FindAndModifyDocumentVersion . Modified
1012
1023
} ;
1013
1024
1014
- Action action = ( ) => collection . FindAndModify ( args ) ;
1025
+ BsonDocument modifiedDocument ;
1026
+ if ( _server . BuildInfo . Version >= new Version ( 3 , 2 , 0 ) )
1027
+ {
1028
+ Action action = ( ) => collection . FindAndModify ( args ) ;
1029
+
1030
+ var exception = action . ShouldThrow < MongoWriteConcernException > ( ) . Which ;
1031
+ var commandResult = exception . Result ;
1032
+ modifiedDocument = commandResult [ "value" ] . AsBsonDocument ;
1033
+ }
1034
+ else
1035
+ {
1036
+ var result = collection . FindAndModify ( args ) ;
1037
+
1038
+ modifiedDocument = result . ModifiedDocument ;
1039
+ }
1015
1040
1016
- var exception = action . ShouldThrow < MongoWriteConcernException > ( ) . Which ;
1017
- var commandResult = exception . Result ;
1018
- var result = commandResult [ "value" ] . AsBsonDocument ;
1019
- result . Should ( ) . Be ( "{ _id : 1, x : 2 }" ) ;
1041
+ modifiedDocument . Should ( ) . Be ( "{ _id : 1, x : 2 }" ) ;
1020
1042
}
1021
1043
1022
1044
private class FindAndModifyClass
@@ -1120,7 +1142,7 @@ public void TestFindAndRemoveWithMaxTime()
1120
1142
public void TestFindAndRemoveWithWriteConcernError ( )
1121
1143
{
1122
1144
_collection . RemoveAll ( ) ;
1123
- _collection . Insert ( new BsonDocument ( " x", 1 ) ) ;
1145
+ _collection . Insert ( new BsonDocument { { "_id" , 1 } , { " x", 1 } } ) ;
1124
1146
var collectionSettings = new MongoCollectionSettings
1125
1147
{
1126
1148
WriteConcern = new WriteConcern ( 9 )
@@ -1131,12 +1153,23 @@ public void TestFindAndRemoveWithWriteConcernError()
1131
1153
Query = Query . EQ ( "x" , 1 )
1132
1154
} ;
1133
1155
1134
- Action action = ( ) => collection . FindAndRemove ( args ) ;
1156
+ BsonDocument modifiedDocument ;
1157
+ if ( _server . BuildInfo . Version >= new Version ( 3 , 2 , 0 ) )
1158
+ {
1159
+ Action action = ( ) => collection . FindAndRemove ( args ) ;
1135
1160
1136
- var exception = action . ShouldThrow < MongoWriteConcernException > ( ) . Which ;
1137
- var commandResult = exception . Result ;
1138
- var result = commandResult [ "value" ] . AsBsonDocument ;
1139
- result [ "x" ] . Should ( ) . Be ( 1 ) ;
1161
+ var exception = action . ShouldThrow < MongoWriteConcernException > ( ) . Which ;
1162
+ var commandResult = exception . Result ;
1163
+ modifiedDocument = commandResult [ "value" ] . AsBsonDocument ;
1164
+ }
1165
+ else
1166
+ {
1167
+ var result = collection . FindAndRemove ( args ) ;
1168
+
1169
+ modifiedDocument = result . ModifiedDocument ;
1170
+ }
1171
+
1172
+ modifiedDocument . Should ( ) . Be ( "{ _id : 1, x : 1 }" ) ;
1140
1173
_collection . Count ( ) . Should ( ) . Be ( 0 ) ;
1141
1174
}
1142
1175
@@ -2374,7 +2407,7 @@ public void TestInsertDuplicateKey()
2374
2407
}
2375
2408
2376
2409
[ Test ]
2377
- [ RequiresServer ( ClusterTypes = ClusterTypes . ReplicaSet ) ]
2410
+ [ RequiresServer ( MinimumVersion = "3.2.0-rc0" , ClusterTypes = ClusterTypes . ReplicaSet ) ]
2378
2411
public void TestInsertWithWriteConcernError ( )
2379
2412
{
2380
2413
_collection . RemoveAll ( ) ;
@@ -2838,7 +2871,7 @@ public void TestRemoveUnacknowledeged()
2838
2871
}
2839
2872
2840
2873
[ Test ]
2841
- [ RequiresServer ( ClusterTypes = ClusterTypes . ReplicaSet ) ]
2874
+ [ RequiresServer ( MinimumVersion = "3.2.0-rc0" , ClusterTypes = ClusterTypes . ReplicaSet ) ]
2842
2875
public void TestRemoveWithWriteConcernError ( )
2843
2876
{
2844
2877
_collection . RemoveAll ( ) ;
@@ -3097,7 +3130,7 @@ public void TestUpdateUnacknowledged()
3097
3130
}
3098
3131
3099
3132
[ Test ]
3100
- [ RequiresServer ( ClusterTypes = ClusterTypes . ReplicaSet ) ]
3133
+ [ RequiresServer ( MinimumVersion = "3.2.0-rc0" , ClusterTypes = ClusterTypes . ReplicaSet ) ]
3101
3134
public void TestUpdateWithWriteConcernError ( )
3102
3135
{
3103
3136
_collection . RemoveAll ( ) ;
0 commit comments