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 NUnit . Framework ;
@@ -22,6 +23,14 @@ namespace MongoDB.DriverUnitTests.Exceptions
22
23
[ TestFixture ]
23
24
public class ExceptionMapperTests
24
25
{
26
+ private MongoServerInstance _primary ;
27
+
28
+ [ TestFixtureSetUp ]
29
+ public void Setup ( )
30
+ {
31
+ _primary = Configuration . TestServer . Primary ;
32
+ }
33
+
25
34
[ Test ]
26
35
public void TestDoesNotThrowExceptionWhenEverythingIsKosherWithAWriteConcernResult ( )
27
36
{
@@ -33,6 +42,7 @@ public void TestDoesNotThrowExceptionWhenEverythingIsKosherWithAWriteConcernResu
33
42
} ;
34
43
35
44
var writeConcernResult = new WriteConcernResult ( response ) ;
45
+ writeConcernResult . ServerInstance = _primary ;
36
46
var ex = ExceptionMapper . Map ( writeConcernResult ) ;
37
47
38
48
Assert . IsNull ( ex ) ;
@@ -64,6 +74,7 @@ public void TestThrowsDuplicateKeyExceptionForMongod(int code)
64
74
} ;
65
75
66
76
var writeConcernResult = new WriteConcernResult ( response ) ;
77
+ writeConcernResult . ServerInstance = _primary ;
67
78
var ex = ExceptionMapper . Map ( writeConcernResult ) ;
68
79
69
80
Assert . IsNotNull ( ex ) ;
@@ -98,6 +109,7 @@ public void TestThrowsDuplicateKeyExceptionForMongos(int code)
98
109
} ;
99
110
100
111
var writeConcernResult = new WriteConcernResult ( response ) ;
112
+ writeConcernResult . ServerInstance = _primary ;
101
113
var ex = ExceptionMapper . Map ( writeConcernResult ) ;
102
114
103
115
Assert . IsNotNull ( ex ) ;
@@ -117,6 +129,7 @@ public void TestThrowsWriteConcernExceptionWhenNotOk()
117
129
} ;
118
130
119
131
var writeConcernResult = new WriteConcernResult ( response ) ;
132
+ writeConcernResult . ServerInstance = _primary ;
120
133
var ex = ExceptionMapper . Map ( writeConcernResult ) ;
121
134
122
135
Assert . IsNotNull ( ex ) ;
@@ -136,12 +149,69 @@ public void TestThrowsWriteConcernExceptionWhenOkButHasLastErrorMessage()
136
149
} ;
137
150
138
151
var writeConcernResult = new WriteConcernResult ( response ) ;
152
+ writeConcernResult . ServerInstance = _primary ;
139
153
var ex = ExceptionMapper . Map ( writeConcernResult ) ;
140
154
141
155
Assert . IsNotNull ( ex ) ;
142
156
Assert . IsInstanceOf < WriteConcernException > ( ex ) ;
143
157
}
144
158
159
+ [ Test ]
160
+ public void TestThrowsWriteConcernExceptionWhenOkButHasWNoteOnPre26Servers ( )
161
+ {
162
+ var response = new BsonDocument
163
+ {
164
+ { "err" , BsonNull . Value } ,
165
+ { "code" , 20 } ,
166
+ { "n" , 0 } ,
167
+ { "connectionId" , 1 } ,
168
+ { "ok" , 1 } ,
169
+ { "wnote" , "oops" }
170
+ } ;
171
+
172
+ var writeConcernResult = new WriteConcernResult ( response ) ;
173
+ writeConcernResult . ServerInstance = _primary ;
174
+ var ex = ExceptionMapper . Map ( writeConcernResult ) ;
175
+
176
+ if ( _primary . BuildInfo . Version < new Version ( 2 , 6 , 0 ) )
177
+ {
178
+ Assert . IsNull ( ex ) ;
179
+ }
180
+ else
181
+ {
182
+ Assert . IsNotNull ( ex ) ;
183
+ Assert . IsInstanceOf < WriteConcernException > ( ex ) ;
184
+ }
185
+ }
186
+
187
+ [ Test ]
188
+ public void TestThrowsWriteConcernExceptionWhenOkButHasJNoteOnPre26Servers ( )
189
+ {
190
+ var response = new BsonDocument
191
+ {
192
+ { "err" , BsonNull . Value } ,
193
+ { "code" , 20 } ,
194
+ { "n" , 0 } ,
195
+ { "connectionId" , 1 } ,
196
+ { "ok" , 1 } ,
197
+ { "jnote" , "oops" }
198
+ } ;
199
+
200
+ var writeConcernResult = new WriteConcernResult ( response ) ;
201
+ writeConcernResult . ServerInstance = _primary ;
202
+ var ex = ExceptionMapper . Map ( writeConcernResult ) ;
203
+
204
+ if ( _primary . BuildInfo . Version < new Version ( 2 , 6 , 0 ) )
205
+ {
206
+ Assert . IsNull ( ex ) ;
207
+ }
208
+ else
209
+ {
210
+ Assert . IsNotNull ( ex ) ;
211
+ Assert . IsInstanceOf < WriteConcernException > ( ex ) ;
212
+ }
213
+ }
214
+
145
215
[ Test ]
146
216
[ TestCase ( 50 ) ]
147
217
[ TestCase ( 13475 ) ]
0 commit comments