1
- /* Copyright 2010-2014 MongoDB Inc.
1
+ /* Copyright 2010-2015 MongoDB Inc.
2
2
*
3
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
4
* you may not use this file except in compliance with the License.
@@ -87,7 +87,7 @@ public void TestQueryWithProjectionHasIndexNameHint()
87
87
[ Test ]
88
88
public void TestQueryWithConditionHasIndexNameHint ( )
89
89
{
90
- var query = _collection . AsQueryable ( ) . Where ( o=> o . a == 1 && o . b == 3 ) . WithIndex ( "i" ) ;
90
+ var query = _collection . AsQueryable ( ) . Where ( o => o . a == 1 && o . b == 3 ) . WithIndex ( "i" ) ;
91
91
var selectQuery = ( SelectQuery ) MongoQueryTranslator . Translate ( query ) ;
92
92
Assert . AreEqual ( "i" , selectQuery . IndexHint . AsString ) ;
93
93
Assert . AreEqual ( "{ \" a\" : 1, \" b\" : 3 }" , selectQuery . BuildQuery ( ) . ToJson ( ) ) ;
@@ -115,7 +115,7 @@ public void TestIndexNameHintIsUsedInQuery()
115
115
{
116
116
var winningPlan = plan [ "queryPlanner" ] [ "winningPlan" ] . AsBsonDocument ;
117
117
var stage = winningPlan [ "stage" ] . AsString ;
118
- Assert . That ( stage , Is . EqualTo ( "COLLSCAN " ) ) ;
118
+ Assert . That ( stage , Is . Not . EqualTo ( "IXSCAN " ) ) ;
119
119
}
120
120
121
121
// Now check that we can force it to use our index
@@ -128,6 +128,10 @@ public void TestIndexNameHintIsUsedInQuery()
128
128
else
129
129
{
130
130
var winningPlan = plan [ "queryPlanner" ] [ "winningPlan" ] . AsBsonDocument ;
131
+ if ( winningPlan . Contains ( "shards" ) )
132
+ {
133
+ winningPlan = winningPlan [ "shards" ] [ 0 ] [ "winningPlan" ] . AsBsonDocument ;
134
+ }
131
135
var inputStage = winningPlan [ "inputStage" ] . AsBsonDocument ;
132
136
var stage = inputStage [ "stage" ] . AsString ;
133
137
var keyPattern = inputStage [ "keyPattern" ] . AsBsonDocument ;
@@ -196,7 +200,7 @@ public void TestIndexDocumentHintIsUsedInQuery()
196
200
{
197
201
var winningPlan = plan [ "queryPlanner" ] [ "winningPlan" ] . AsBsonDocument ;
198
202
var stage = winningPlan [ "stage" ] . AsString ;
199
- Assert . That ( stage , Is . EqualTo ( "COLLSCAN " ) ) ;
203
+ Assert . That ( stage , Is . Not . EqualTo ( "IXSCAN " ) ) ;
200
204
}
201
205
202
206
// Now check that we can force it to use our index
@@ -211,6 +215,10 @@ public void TestIndexDocumentHintIsUsedInQuery()
211
215
else
212
216
{
213
217
var winningPlan = plan [ "queryPlanner" ] [ "winningPlan" ] . AsBsonDocument ;
218
+ if ( winningPlan . Contains ( "shards" ) )
219
+ {
220
+ winningPlan = winningPlan [ "shards" ] [ 0 ] [ "winningPlan" ] . AsBsonDocument ;
221
+ }
214
222
var inputStage = winningPlan [ "inputStage" ] . AsBsonDocument ;
215
223
var stage = inputStage [ "stage" ] . AsString ;
216
224
var keyPattern = inputStage [ "keyPattern" ] . AsBsonDocument ;
@@ -229,13 +237,13 @@ public void TestWithIndexCannotBeBeforeDistinct()
229
237
[ Test ]
230
238
public void TestWithIndexCannotBeAfterDistinct ( )
231
239
{
232
- Assert . Throws < NotSupportedException > ( ( ) => _collection . AsQueryable ( ) . Select ( o => o . a ) . Distinct ( ) . WithIndex ( "i" ) . ToList ( ) ) ;
240
+ Assert . Throws < NotSupportedException > ( ( ) => _collection . AsQueryable ( ) . Select ( o => o . a ) . Distinct ( ) . WithIndex ( "i" ) . ToList ( ) ) ;
233
241
}
234
242
235
243
[ Test ]
236
244
public void TestThereCanOnlyBeOneIndexHint ( )
237
245
{
238
- Assert . Throws < NotSupportedException > ( ( ) => _collection . AsQueryable ( ) . WithIndex ( "i" ) . WithIndex ( new BsonDocument ( "a" , 1 ) ) . ToList ( ) ) ;
246
+ Assert . Throws < NotSupportedException > ( ( ) => _collection . AsQueryable ( ) . WithIndex ( "i" ) . WithIndex ( new BsonDocument ( "a" , 1 ) ) . ToList ( ) ) ;
239
247
}
240
248
241
249
}
0 commit comments