@@ -19,41 +19,27 @@ public class SearchTests(EndpointsFixture endpointsFixture) : AbstractNRedisStac
1919
2020 private void AddDocument ( IDatabase db , Document doc )
2121 {
22- string key = doc . Id ;
23- var properties = doc . GetProperties ( ) ;
24- // HashEntry[] hash = new HashEntry[properties.Count()];
25- // for(int i = 0; i < properties.Count(); i++)
26- // {
27- // var property = properties.ElementAt(i);
28- // hash[i] = new HashEntry(property.Key, property.Value);
29- // }
30- // db.HashSet(key, hash);
31- var nameValue = new List < object > ( ) { key } ;
32- foreach ( var item in properties )
33- {
34- nameValue . Add ( item . Key ) ;
35- nameValue . Add ( item . Value ) ;
36- }
37- db . Execute ( "HSET" , nameValue ) ;
22+ var hash = doc . GetProperties ( )
23+ . Select ( pair => new HashEntry ( pair . Key , pair . Value ) )
24+ . ToArray ( ) ;
25+ db . HashSet ( doc . Id , hash ) ;
3826 }
3927
4028 private void AddDocument ( IDatabase db , string key , Dictionary < string , object > objDictionary )
4129 {
4230 Dictionary < string , string > strDictionary = new ( ) ;
43- // HashEntry[] hash = new HashEntry[objDictionary.Count()];
44- // for(int i = 0; i < objDictionary.Count(); i++)
45- // {
46- // var property = objDictionary.ElementAt(i);
47- // hash[i] = new HashEntry(property.Key, property.Value.ToString());
48- // }
49- // db.HashSet(key, hash);
50- var nameValue = new List < object > ( ) { key } ;
51- foreach ( var item in objDictionary )
52- {
53- nameValue . Add ( item . Key ) ;
54- nameValue . Add ( item . Value ) ;
55- }
56- db . Execute ( "HSET" , nameValue ) ;
31+ var hash = objDictionary
32+ . Select ( pair => new HashEntry ( pair . Key , pair . Value switch
33+ {
34+ string s => ( RedisValue ) s ,
35+ byte [ ] b => b ,
36+ int i => i ,
37+ long l => l ,
38+ double d => d ,
39+ _ => throw new ArgumentException ( $ "Unsupported type: { pair . Value . GetType ( ) } ") ,
40+ } ) )
41+ . ToArray ( ) ;
42+ db . HashSet ( key , hash ) ;
5743 }
5844
5945 [ SkipIfRedisTheory ( Is . Enterprise ) ]
@@ -1444,7 +1430,16 @@ public void TestDropIndex(string endpointId)
14441430 {
14451431 Assert . Contains ( "no such index" , ex . Message , StringComparison . OrdinalIgnoreCase ) ;
14461432 }
1447- Assert . Equal ( "100" , db . Execute ( "DBSIZE" ) . ToString ( ) ) ;
1433+
1434+ var count = 0L ;
1435+ foreach ( var server in db . Multiplexer . GetServers ( ) )
1436+ {
1437+ if ( ! server . IsReplica )
1438+ {
1439+ count += server . DatabaseSize ( ) ;
1440+ }
1441+ }
1442+ Assert . Equal ( 100 , count ) ;
14481443 }
14491444
14501445 [ SkippableTheory ]
0 commit comments