1- /* Copyright 2010-2014 MongoDB Inc.
1+ /* Copyright 2010-2015 MongoDB Inc.
22*
33* Licensed under the Apache License, Version 2.0 (the "License");
44* you may not use this file except in compliance with the License.
@@ -87,7 +87,7 @@ public void TestQueryWithProjectionHasIndexNameHint()
8787 [ Test ]
8888 public void TestQueryWithConditionHasIndexNameHint ( )
8989 {
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" ) ;
9191 var selectQuery = ( SelectQuery ) MongoQueryTranslator . Translate ( query ) ;
9292 Assert . AreEqual ( "i" , selectQuery . IndexHint . AsString ) ;
9393 Assert . AreEqual ( "{ \" a\" : 1, \" b\" : 3 }" , selectQuery . BuildQuery ( ) . ToJson ( ) ) ;
@@ -115,7 +115,7 @@ public void TestIndexNameHintIsUsedInQuery()
115115 {
116116 var winningPlan = plan [ "queryPlanner" ] [ "winningPlan" ] . AsBsonDocument ;
117117 var stage = winningPlan [ "stage" ] . AsString ;
118- Assert . That ( stage , Is . EqualTo ( "COLLSCAN " ) ) ;
118+ Assert . That ( stage , Is . Not . EqualTo ( "IXSCAN " ) ) ;
119119 }
120120
121121 // Now check that we can force it to use our index
@@ -128,6 +128,10 @@ public void TestIndexNameHintIsUsedInQuery()
128128 else
129129 {
130130 var winningPlan = plan [ "queryPlanner" ] [ "winningPlan" ] . AsBsonDocument ;
131+ if ( winningPlan . Contains ( "shards" ) )
132+ {
133+ winningPlan = winningPlan [ "shards" ] [ 0 ] [ "winningPlan" ] . AsBsonDocument ;
134+ }
131135 var inputStage = winningPlan [ "inputStage" ] . AsBsonDocument ;
132136 var stage = inputStage [ "stage" ] . AsString ;
133137 var keyPattern = inputStage [ "keyPattern" ] . AsBsonDocument ;
@@ -196,7 +200,7 @@ public void TestIndexDocumentHintIsUsedInQuery()
196200 {
197201 var winningPlan = plan [ "queryPlanner" ] [ "winningPlan" ] . AsBsonDocument ;
198202 var stage = winningPlan [ "stage" ] . AsString ;
199- Assert . That ( stage , Is . EqualTo ( "COLLSCAN " ) ) ;
203+ Assert . That ( stage , Is . Not . EqualTo ( "IXSCAN " ) ) ;
200204 }
201205
202206 // Now check that we can force it to use our index
@@ -211,6 +215,10 @@ public void TestIndexDocumentHintIsUsedInQuery()
211215 else
212216 {
213217 var winningPlan = plan [ "queryPlanner" ] [ "winningPlan" ] . AsBsonDocument ;
218+ if ( winningPlan . Contains ( "shards" ) )
219+ {
220+ winningPlan = winningPlan [ "shards" ] [ 0 ] [ "winningPlan" ] . AsBsonDocument ;
221+ }
214222 var inputStage = winningPlan [ "inputStage" ] . AsBsonDocument ;
215223 var stage = inputStage [ "stage" ] . AsString ;
216224 var keyPattern = inputStage [ "keyPattern" ] . AsBsonDocument ;
@@ -229,13 +237,13 @@ public void TestWithIndexCannotBeBeforeDistinct()
229237 [ Test ]
230238 public void TestWithIndexCannotBeAfterDistinct ( )
231239 {
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 ( ) ) ;
233241 }
234242
235243 [ Test ]
236244 public void TestThereCanOnlyBeOneIndexHint ( )
237245 {
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 ( ) ) ;
239247 }
240248
241249 }
0 commit comments