Path: redb-route/tests/redb.Route.Tests.Xml/XmlBeanFunctionTests.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.Xml/XmlBeanFunctionTests.cs
----
using AwesomeAssertions;
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.Xml;
namespace redb.Route.Tests.Xml;
/// A declared bean the expression function calls from markup.
public class XmlLoyalty
{
public string Gold { get; set; } = "ann";
public bool IsGold(string? name) => name == Gold;
public string Badge(string name, int points) => $"{name}:{points}";
}
///
/// The bean: expression function in route markup: a bare call in a condition, a call inside a ${...}
/// value, against a bean the document itself declares.
///
public sealed class XmlBeanFunctionTests : IAsyncLifetime
{
private readonly RouteContext _context = new();
public Task InitializeAsync() => Task.CompletedTask;
public async Task DisposeAsync() => await _context.DisposeAsync();
[Fact]
public async Task FilterAndSetBody_CallTheDeclaredBean()
{
_context.AddXmlRoutesFromContent($$"""
""");
await _context.Start();
var producer = _context.GetEndpoint("direct://xml-bean-fn").CreateProducer();
await producer.Start();
var mock = (redb.Route.Components.MockEndpoint)_context.GetEndpoint("mock://gold");
foreach (var name in new[] { "ann", "bob" })
{
var exchange = new Exchange(new Message("in"));
exchange.In.Headers["name"] = name;
exchange.In.Headers["points"] = 7;
await producer.Process(exchange);
}
mock.ReceivedExchanges.Select(e => e.In.Body).Should().Equal("ann:7");
}
}