Skip to content

Commit 65d72c7

Browse files
committed
Add test case verifying a specific complex expression
1 parent 7efc165 commit 65d72c7

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/PgKeyValueDB.Tests/PgKeyValueDBTest.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class Address
2828

2929
public class UserProfile
3030
{
31+
public string? Id { get; set; } // Add this line
3132
public string? Name { get; set; }
3233
public string? DisplayName { get; set; }
3334
public int Age { get; set; }
@@ -37,6 +38,7 @@ public class UserProfile
3738
public Address? SecondaryAddress { get; set; }
3839
public List<string>? Tags { get; set; }
3940
public bool? IsVerified { get; set; }
41+
public List<string>? AdditionalIds { get; set; } // Add this line
4042
}
4143

4244
public class Poco
@@ -548,4 +550,44 @@ public async Task FilterByTagTest()
548550
Assert.AreEqual(1, vipUsers.Count);
549551
Assert.AreEqual("Alice", vipUsers[0].Name);
550552
}
553+
554+
[TestMethod]
555+
public async Task ComplexExpressionTest()
556+
{
557+
var key1 = nameof(ComplexExpressionTest) + "1";
558+
var key2 = nameof(ComplexExpressionTest) + "2";
559+
var pid = nameof(ComplexExpressionTest);
560+
561+
var user1 = new UserProfile
562+
{
563+
Id = "user1",
564+
Name = "Alice",
565+
AdditionalIds = new List<string> { "id1", "id2" }
566+
};
567+
568+
var user2 = new UserProfile
569+
{
570+
Id = "user2",
571+
Name = "Bob",
572+
AdditionalIds = new List<string> { "id3", "id4" }
573+
};
574+
575+
await kv.UpsertAsync(key1, user1, pid);
576+
await kv.UpsertAsync(key2, user2, pid);
577+
578+
// Variables for the expression
579+
bool notIdIsEmpty = false;
580+
string notId = "user3";
581+
string idOrAdditionalId = "id1";
582+
583+
// This query should filter users by the complex expression
584+
Expression<Func<UserProfile, bool>> expr = q =>
585+
(notIdIsEmpty || q.Id != notId) &&
586+
(q.Id == idOrAdditionalId || q.AdditionalIds!.Contains(idOrAdditionalId));
587+
588+
var users = await kv.GetListAsync(pid, expr).ToListAsync();
589+
590+
Assert.AreEqual(1, users.Count);
591+
Assert.AreEqual("Alice", users[0].Name);
592+
}
551593
}

0 commit comments

Comments
 (0)