@@ -49,18 +49,13 @@ public class PgKeyValueDBTest
4949{ 
5050    private  static PgServer  pg  =  null ! ; 
5151    private  static PgKeyValueDB  kv  =  null ! ; 
52-     private  const  string  TestPid  =  "AdvancedTest" ; 
53-     private  static TestContext  testContext  =  null ! ; 
54-     private  static string  connectionString  =  null ! ; 
5552
5653    [ ClassInitialize ] 
5754    public  static void  ClassInit ( TestContext  context ) 
5855    { 
59-         testContext  =  context ; 
6056        IServiceCollection  services  =  new  ServiceCollection ( ) ; 
6157        pg  =  new  PgServer ( "16.2.0" ,  clearWorkingDirOnStart :  true ,  clearInstanceDirOnStop :  true ) ; 
6258        pg . Start ( ) ; 
63-         connectionString  =  $ "Host=localhost;Port={ pg . PgPort } ;Username=postgres;Password=postgres;Database=postgres"; 
6459        services . AddPgKeyValueDB ( $ "Host=localhost;Port={ pg . PgPort } ;Username=postgres;Password=postgres;Database=postgres",  b => 
6560        { 
6661            b . SchemaName  =  "pgkeyvaluetest" ; 
@@ -77,57 +72,6 @@ public static void ClassCleanup()
7772        pg ? . Dispose ( ) ; 
7873    } 
7974
80-     private  static async  Task  SetupTestData ( ) 
81-     { 
82-         var  users  =  new [ ] 
83-         { 
84-             new  UserProfile 
85-             { 
86-                 Name  =  "John Doe" , 
87-                 Age  =  30 , 
88-                 Status  =  UserStatus . Active , 
89-                 Role  =  UserRole . Admin , 
90-                 PrimaryAddress  =  new  Address 
91-                 { 
92-                     Street  =  "123 Main St" , 
93-                     City  =  "New York" , 
94-                     Country  =  "USA" , 
95-                     ZipCode  =  10001 
96-                 } , 
97-                 SecondaryAddress  =  new  Address 
98-                 { 
99-                     Street  =  "456 Park Ave" , 
100-                     City  =  "Boston" , 
101-                     Country  =  "USA" , 
102-                     ZipCode  =  02108 
103-                 } , 
104-                 Tags  =  [ "vip" ,  "early-adopter" ] , 
105-                 IsVerified  =  true 
106-             } , 
107-             new  UserProfile 
108-             { 
109-                 Name  =  "Jane Smith" , 
110-                 Age  =  25 , 
111-                 Status  =  UserStatus . Pending , 
112-                 Role  =  UserRole . User , 
113-                 PrimaryAddress  =  new  Address 
114-                 { 
115-                     Street  =  "789 Oak Rd" , 
116-                     City  =  "San Francisco" , 
117-                     Country  =  "USA" , 
118-                     ZipCode  =  94102 
119-                 } , 
120-                 Tags  =  [ "beta-tester" ] , 
121-                 IsVerified  =  false 
122-             } 
123-         } ; 
124- 
125-         for  ( int  i  =  0 ;  i  <  users . Length ;  i ++ ) 
126-         { 
127-             await  kv . UpsertAsync ( $ "user_{ i } ",  users [ i ] ,  TestPid ) ; 
128-         } 
129-     } 
130- 
13175    [ TestMethod ] 
13276    public  void  BasicTest ( ) 
13377    { 
@@ -561,4 +505,34 @@ public async Task FilterWithStringParameterTest()
561505        Assert . IsTrue ( results . Any ( u =>  u . Name  ==  "John Smith" ) ) ; 
562506        Assert . IsTrue ( results . Any ( u =>  u . DisplayName  ==  "Johnny" ) ) ; 
563507    } 
508+ 
509+     [ TestMethod ] 
510+     public  async  Task  FilterByTagTest ( ) 
511+     { 
512+         var  key1  =  nameof ( FilterByTagTest )  +  "1" ; 
513+         var  key2  =  nameof ( FilterByTagTest )  +  "2" ; 
514+         var  pid  =  nameof ( FilterByTagTest ) ; 
515+ 
516+         var  user1  =  new  UserProfile 
517+         { 
518+             Name  =  "Alice" , 
519+             Tags  =  new  List < string >  {  "vip" ,  "early-adopter"  } 
520+         } ; 
521+ 
522+         var  user2  =  new  UserProfile 
523+         { 
524+             Name  =  "Bob" , 
525+             Tags  =  new  List < string >  {  "regular" ,  "new-user"  } 
526+         } ; 
527+ 
528+         await  kv . UpsertAsync ( key1 ,  user1 ,  pid ) ; 
529+         await  kv . UpsertAsync ( key2 ,  user2 ,  pid ) ; 
530+ 
531+         // This query should filter users by the "vip" tag 
532+         Expression < Func < UserProfile ,  bool > >  expr  =  u =>  u . Tags ! . Contains ( "vip" ) ; 
533+         var  vipUsers  =  await  kv . GetListAsync ( pid ,  expr ) . ToListAsync ( ) ; 
534+ 
535+         Assert . AreEqual ( 1 ,  vipUsers . Count ) ; 
536+         Assert . AreEqual ( "Alice" ,  vipUsers [ 0 ] . Name ) ; 
537+     } 
564538} 
0 commit comments