@@ -1993,37 +1993,14 @@ public void TestHashedIndex()
19931993 if ( _server . BuildInfo . Version >= new Version ( 2 , 4 , 0 ) )
19941994 {
19951995 if ( _collection . Exists ( ) ) { _collection . Drop ( ) ; }
1996- _collection . Insert ( new BsonDocument { { "x" , "abc" } } ) ;
1997- _collection . Insert ( new BsonDocument { { "x" , "def" } } ) ;
1998- _collection . Insert ( new BsonDocument { { "x" , "ghi" } } ) ;
1999- _collection . CreateIndex ( IndexKeys . Hashed ( "x" ) ) ;
2000-
2001- var query = Query . EQ ( "x" , "abc" ) ;
2002- var cursor = _collection . FindAs < BsonDocument > ( query ) ;
2003- var documents = cursor . ToArray ( ) ;
1996+ var expectedName = "x_hashed" ;
1997+ var expectedKey = "{ x : \" hashed\" }" ;
20041998
2005- Assert . AreEqual ( 1 , documents . Length ) ;
2006- Assert . AreEqual ( "abc" , documents [ 0 ] [ "x" ] . AsString ) ;
1999+ _collection . CreateIndex ( IndexKeys . Hashed ( "x" ) ) ;
20072000
2008- var plan = cursor . Explain ( ) ;
2009- if ( _server . BuildInfo . Version < new Version ( 2 , 7 , 0 ) )
2010- {
2011- Assert . AreEqual ( "BtreeCursor x_hashed" , plan [ "cursor" ] . AsString ) ;
2012- }
2013- else
2014- {
2015- var winningPlan = plan [ "queryPlanner" ] [ "winningPlan" ] . AsBsonDocument ;
2016- var inputStage = winningPlan [ "inputStage" ] . AsBsonDocument ;
2017- // working around a server bug were sometimes the inputStage is nested inside the inputStage
2018- if ( inputStage . Contains ( "inputStage" ) )
2019- {
2020- inputStage = inputStage [ "inputStage" ] . AsBsonDocument ;
2021- }
2022- var stage = inputStage [ "stage" ] . AsString ;
2023- var keyPattern = inputStage [ "keyPattern" ] . AsBsonDocument ;
2024- Assert . That ( stage , Is . EqualTo ( "IXSCAN" ) ) ;
2025- Assert . That ( keyPattern , Is . EqualTo ( BsonDocument . Parse ( "{ x : \" hashed\" }" ) ) ) ;
2026- }
2001+ var index = _collection . GetIndexes ( ) . FirstOrDefault ( x => x . Name == expectedName ) ;
2002+ Assert . IsNotNull ( index ) ;
2003+ Assert . AreEqual ( BsonDocument . Parse ( expectedKey ) , index . Key ) ;
20272004 }
20282005 }
20292006
0 commit comments