Path: redb/redb.Tests.Integration/Tests/Base/FilterFieldPathTestsBase.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Tests.Integration/Tests/Base/FilterFieldPathTestsBase.cs
----
using System.Linq.Expressions;
using redb.Core;
using redb.Core.Models.Entities;
using redb.Core.Query;
using redb.Tests.Integration.Models;
namespace redb.Tests.Integration.Tests.Base;
///
/// The field path of a filter is a chain of fields of the queried object. A method call inside the path is refused with
/// one message, and so is an array or list element by index on the free providers: the parser used to drop the part
/// before them, so Items[0].Name == "top" filtered by the field Name of the object itself and returned it.
/// redb Pro reads the element (ElementIndexFilterTestsBase has the full set).
/// The paths that are supported keep answering: a field, a field of a nested class, Nullable Value and HasValue,
/// Length and Count, a dictionary entry by key (Contains over an array of simple values and Any over an array of list
/// items have their own classes: ArrayTestsBase, ListTestsBase).
///
/// One object per test, read by its id: Name "top", Rank 1; Items[0] and Parts[0] have Name "inner", Rank 7.
///
public abstract class FilterFieldPathTestsBase
{
protected readonly IRedbService Redb;
protected FilterFieldPathTestsBase(IRedbService redb) => Redb = redb;
private async Task> SeedAsync()
{
await Redb.SyncSchemeAsync();
var obj = new RedbObject
{
name = "fp-" + Guid.NewGuid().ToString("N")[..8],
Props = new FieldPathProps
{
Name = "top",
Rank = 1,
Items = [new FieldPathItem { Name = "inner", Rank = 7 }],
Parts = [new FieldPathItem { Name = "inner", Rank = 7 }],
ByKey = new Dictionary { ["k"] = new() { Name = "entry", Rank = 5 } },
Main = new FieldPathItem { Name = "main", Rank = 3, Score = 4 },
Scores = new Dictionary { ["a"] = 1, ["n"] = null }
}
};
var id = await Redb.SaveAsync(obj);
return Redb.Query().WhereRedb(o => o.Id == id);
}
/// redb Pro reads an element by index in a filter; the free providers refuse it.
protected virtual bool ReadsElementsByIndex => false;
public static IEnumerable