Path: redb/redb.Tests.Integration/Tests/Base/UnregisteredTreeTargetTestsBase.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/UnregisteredTreeTargetTestsBase.cs
----
using redb.Core;
using redb.Core.Models.Entities;
using redb.Tests.Integration.Models;
namespace redb.Tests.Integration.Tests.Base;
///
/// WhereHasAncestor / WhereHasDescendant over a type that has no scheme fail at the query, naming the type, as
/// Query<T>() fails for it. Pro dropped the filter and returned every node; Free ran into a removed legacy path
/// ("Legacy ... SQL path is removed").
///
public abstract class UnregisteredTreeTargetTestsBase
{
/// A plain class: no [RedbScheme], never synced.
public sealed class NotAScheme
{
public string Name { get; set; } = "";
}
protected readonly IRedbService Redb;
protected UnregisteredTreeTargetTestsBase(IRedbService redb) => Redb = redb;
private async Task SeedRootAsync()
{
await Redb.SyncSchemeAsync();
var tag = "utt-" + Guid.NewGuid().ToString("N")[..8];
var root = new TreeRedbObject { name = tag, Props = new SimpleProps { Title = tag } };
return await Redb.SaveAsync(root);
}
[Fact]
public async Task WhereHasAncestor_TypeWithoutScheme_FailsNamingTheType()
{
var root = await SeedRootAsync();
var unrooted = () => Redb.TreeQuery().WhereHasAncestor(a => a.Name == "x");
var rooted = () => Redb.TreeQuery(root).WhereHasAncestor(a => a.Name == "x");
unrooted.Should().Throw().WithMessage("WhereHasAncestor: scheme for type 'NotAScheme' not found*");
rooted.Should().Throw().WithMessage("WhereHasAncestor:*");
}
[Fact]
public async Task WhereHasDescendant_TypeWithoutScheme_FailsNamingTheType()
{
var root = await SeedRootAsync();
var unrooted = () => Redb.TreeQuery().WhereHasDescendant(a => a.Name == "x");
var rooted = () => Redb.TreeQuery(root).WhereHasDescendant(a => a.Name == "x");
unrooted.Should().Throw().WithMessage("WhereHasDescendant: scheme for type 'NotAScheme' not found*");
rooted.Should().Throw().WithMessage("WhereHasDescendant:*");
}
/// The same type in a plain query fails the same way: same exception type, same words.
[Fact]
public void Query_TypeWithoutScheme_FailsTheSameWay()
{
var act = () => Redb.Query();
act.Should().Throw().WithMessage("*for type 'NotAScheme' not found*");
}
}