@@ -909,5 +909,62 @@ public async Task TestTimeStampRangesHash()
909909 CompareTimestamps ( timestamp , first . NullableTimestamp . Value ) ;
910910 Assert . Equal ( obj . Id , first . Id ) ;
911911 }
912+
913+ [ Fact ]
914+ public async Task TestBulkInsert ( )
915+ {
916+ var collection = new RedisCollection < Person > ( _connection ) ;
917+ var persons = new List < Person > ( ) {
918+ new Person ( ) { Name = "Alice" , Age = 51 , NickNames = new [ ] { "Ally" , "Alie" , "Al" } , } ,
919+ new Person ( ) { Name = "Robert" , Age = 37 , NickNames = new [ ] { "Bobby" , "Rob" , "Bob" } , } ,
920+ new Person ( ) { Name = "Jeeva" , Age = 22 , NickNames = new [ ] { "Jee" , "Jeev" , "J" } , } ,
921+ new Person ( ) { Name = "Martin" , Age = 60 , NickNames = new [ ] { "Mart" , "Mat" , "tin" } , }
922+ } ;
923+ var keys = await collection . Insert ( persons ) ;
924+ var people = collection . Where ( x => x . NickNames . Contains ( "Bob" ) || x . NickNames . Contains ( "Alie" ) ) . ToList ( ) ;
925+ Assert . Contains ( people , x => x . Name == persons . First ( ) . Name ) ;
926+ }
927+
928+ [ Fact ]
929+ public async Task TestBulkInsertWithSameIds ( )
930+ {
931+ var collection = new RedisCollection < Person > ( _connection ) ;
932+ var persons = new List < Person > ( ) {
933+ new Person ( ) { Id = "01GFZ9Y6CTEDHHXKT055N1YP3A" , Name = "Alice" , Age = 51 , NickNames = new [ ] { "Ally" , "Alie" , "Al" } , } ,
934+ new Person ( ) { Id = "01GFZ9Y6CTEDHHXKT055N1YP3A" , Name = "Robert" , Age = 37 , NickNames = new [ ] { "Bobby" , "Rob" , "Bob" } , } ,
935+ new Person ( ) { Name = "Jeeva" , Age = 22 , NickNames = new [ ] { "Jee" , "Jeev" , "J" } , } ,
936+ new Person ( ) { Name = "Martin" , Age = 60 , NickNames = new [ ] { "Mart" , "Mat" , "tin" } , }
937+ } ;
938+ await collection . Insert ( persons ) ;
939+ var people = await collection . Where ( x => x . NickNames . Contains ( "Bob" ) || x . NickNames . Contains ( "Alie" ) ) . ToListAsync ( ) ;
940+ Assert . Equal ( people . Count , persons . Count - 3 ) ;
941+ Assert . False ( people . First ( ) . Name == persons . First ( ) . Name ) ; // this fails because the Name field of people doesn't contains the Name value Alice
942+ }
943+
944+ [ Fact ]
945+ public async Task BulkInsert50Records ( )
946+ {
947+ var collection = new RedisCollection < Person > ( _connection ) ;
948+
949+ var names = new [ ] { "Stever" , "Martin" , "Aegorn" , "Robert" , "Mary" , "Joe" , "Mark" , "Otto" } ;
950+ var rand = new Random ( ) ;
951+ var people = new List < Person > ( ) ;
952+ for ( var i = 0 ; i < 50 ; i ++ )
953+ {
954+ people . Add ( new Person
955+ {
956+ Name = names [ rand . Next ( 0 , names . Length ) ] ,
957+ DepartmentNumber = rand . Next ( 1 , 4 ) ,
958+ Sales = rand . Next ( 50000 , 1000000 ) ,
959+ Age = rand . Next ( 17 , 21 ) ,
960+ Height = 58.0 + rand . NextDouble ( ) * 15 ,
961+ SalesAdjustment = rand . NextDouble ( )
962+ }
963+ ) ;
964+ }
965+ await collection . Insert ( people ) ;
966+ var countPeople = collection . Where ( x => x . Age >= 17 && x . Age <= 21 ) . ToList ( ) . Count ;
967+ Assert . Equal ( people . Count , countPeople ) ;
968+ }
912969 }
913- }
970+ }
0 commit comments