Path: redb-route/tests/redb.Route.Tests/Expressions/RegistryRefTests.cs
Snapshot: redb-route, 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-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests/Expressions/RegistryRefTests.cs
----
using AwesomeAssertions;
using redb.Route.Core;
using redb.Route.Expressions;
using redb.Route.Expressions.Ast;
using redb.Route.Predicates;
namespace redb.Route.Tests.Expressions;
/// A registry object the ref: tests read.
public sealed class ChatSettings
{
public string Style { get; set; } = "terse";
public override string ToString() => "style=" + Style;
}
///
/// ref:name of the expression language: the object registered under the whole name (dots and dashes
/// included), as in Apache Camel; nothing is called or read on it; a missing name is an error in the bean: words;
/// refused under the sandbox; looked up once per context; the ternary edge of bean: applies.
///
public sealed class RegistryRefTests : IAsyncLifetime
{
private readonly RouteContext _context = new();
private readonly ChatSettings _settings = new();
public Task InitializeAsync()
{
_context.AddToRegistry("chat.settings", _settings);
_context.AddToRegistry("seen-orders", new List { 1, 2 });
_context.AddToRegistry("limit", 5);
return Task.CompletedTask;
}
public async Task DisposeAsync() => await _context.DisposeAsync();
private Exchange Message(params (string Key, object? Value)[] headers)
{
var exchange = new Exchange(new Message("payload")) { Context = _context };
foreach (var (key, value) in headers)
exchange.In.Headers[key] = value;
return exchange;
}
private static AstNode Parse(string expression) => new Parser(new Tokenizer(expression).GetAllTokens()).Parse();
[Theory]
[InlineData("ref:chat.settings", "chat.settings")]
[InlineData("ref:seen-orders", "seen-orders")]
[InlineData("ref:limit-1", "limit-1")]
public void TheWholeRun_IsTheName(string expression, string name)
{
Parse(expression).Should().BeOfType().Which.Reference.Should().Be(name);
}
[Fact]
public void ASpaceBeforeAMinus_Subtracts()
{
new StringExpression("${ref:limit - 1}").Evaluate