Path: redb/redb.Tests.Integration/Tests/Base/AggregatePathTestsBase.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/AggregatePathTestsBase.cs
----
using redb.Core;
using redb.Core.Models.Entities;
using redb.Core.Query;
using redb.Core.Query.Aggregation;
using redb.Core.Query.Window;
using redb.Tests.Integration.Models;
namespace redb.Tests.Integration.Tests.Base;
///
/// The field path of an aggregate, a group key and a window key follows the filter's rule: a dictionary entry and the
/// Value of a nullable read the entry and the value, and a path that cannot be read is refused with
/// NotSupportedException. It must never fall back to another field (Items[0].Rank read as the object's own Rank).
///
/// Two objects of one tag, both Name "top", Rank 1; Items[0] is { "inner", 7 } and { "other", 7 };
/// Items[1] is { "zz-second", 70 }; ByKey["k"] is { "entry", 5 }, ByKey["z"] is { "zz-other-entry", 50 }; Main.Score
/// is 4; Scores is { a: 1, n: null, z: 90 }. The second element and the other entries hold larger values and names
/// that sort last, so an answer that reads the wrong element or entry (a MAX over all of them) does not match.
///
public abstract class AggregatePathTestsBase
{
protected readonly IRedbService Redb;
protected AggregatePathTestsBase(IRedbService redb) => Redb = redb;
private static FieldPathProps Row(string inner) => new()
{
Name = "top",
Rank = 1,
Items = [new FieldPathItem { Name = inner, Rank = 7 }, new FieldPathItem { Name = "zz-second", Rank = 70 }],
Parts = [new FieldPathItem { Name = inner, Rank = 7 }],
ByKey = new Dictionary
{
["k"] = new() { Name = "entry", Rank = 5 },
["z"] = new() { Name = "zz-other-entry", Rank = 50 }
},
Main = new FieldPathItem { Name = "main", Rank = 3, Score = 4 },
Scores = new Dictionary { ["a"] = 1, ["n"] = null, ["z"] = 90 }
};
///
/// The two objects, as a flat query by their ids, or as the subtree of a root (TreeQuery) whose own values differ,
/// so an answer that took the root in would not match either.
///
private async Task> SeedAsync(bool tree)
{
await Redb.SyncSchemeAsync();
var tag = "ap-" + Guid.NewGuid().ToString("N")[..8];
if (tree)
{
var root = new TreeRedbObject { name = tag + "-root", Props = Row("root") };
root.Props.Rank = 100;
root.Props.Items![0].Rank = 100;
root.id = await Redb.SaveAsync(root);
foreach (var inner in new[] { "inner", "other" })
await Redb.CreateChildAsync(new TreeRedbObject { name = $"{tag}-{inner}", Props = Row(inner) }, root);
return Redb.TreeQuery(root.id);
}
var ids = new List();
foreach (var inner in new[] { "inner", "other" })
ids.Add(await Redb.SaveAsync(new RedbObject { name = $"{tag}-{inner}", Props = Row(inner) }));
var a = ids[0];
var b = ids[1];
return Redb.Query().WhereRedb(o => o.Id == a || o.Id == b);
}
public delegate Task