Path: redb-route/tests/redb.Route.Tests/Processors/DynamicRouterProcessorTests.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/Processors/DynamicRouterProcessorTests.cs
----
using AwesomeAssertions;
using NSubstitute;
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.Processors;
namespace redb.Route.Tests.Processors;
/// Tests for .
public class DynamicRouterProcessorTests
{
private static (IRouteContext context, Dictionary> received) SetupContext(
params string[] uris)
{
var received = new Dictionary>();
var context = Substitute.For();
foreach (var uri in uris)
{
received[uri] = [];
var capturedUri = uri;
var producer = Substitute.For();
producer.When(p => p.Process(Arg.Any(), Arg.Any()))
.Do(ci => received[capturedUri].Add(ci.Arg()));
var endpoint = Substitute.For();
endpoint.CreateProducer().Returns(producer);
context.GetEndpoint(uri).Returns(endpoint);
}
return (context, received);
}
[Fact]
public async Task Process_SingleHop_RoutesToUri()
{
var (context, received) = SetupContext("direct://step1");
var callCount = 0;
var router = new DynamicRouterProcessor(context, _ =>
{
callCount++;
return callCount == 1 ? "direct://step1" : null;
});
await router.Process(new Exchange(new Message("data")));
received["direct://step1"].Should().HaveCount(1);
}
[Fact]
public async Task Process_MultipleHops_VisitsEachUri()
{
var (context, received) = SetupContext("direct://a", "direct://b", "direct://c");
var hops = new Queue(["direct://a", "direct://b", "direct://c", null]);
var router = new DynamicRouterProcessor(context, _ => hops.Dequeue());
await router.Process(new Exchange(new Message("slip")));
received["direct://a"].Should().HaveCount(1);
received["direct://b"].Should().HaveCount(1);
received["direct://c"].Should().HaveCount(1);
}
[Fact]
public async Task Process_NullOnFirstCall_DoesNothing()
{
var context = Substitute.For();
var router = new DynamicRouterProcessor(context, _ => null);
await router.Process(new Exchange());
context.DidNotReceive().GetEndpoint(Arg.Any());
}
[Fact]
public async Task Process_RoutingFunctionSeesModifiedExchange()
{
var bodies = new List