Path: redb-route/tests/redb.Route.Tests.TestKit/AdviceWithTests.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.TestKit/AdviceWithTests.cs
----
using redb.Route.Abstractions;
using redb.Route.Components;
using redb.Route.Core;
using redb.Route.Definitions;
using redb.Route.TestKit;
namespace redb.Route.Tests.TestKit;
///
/// AdviceWith: the route under test is written against real endpoints (kafka, sql) whose components
/// are not even registered in this test process — exactly the "no broker" situation the kit is for.
///
public class AdviceWithTests
{
private sealed class OrdersRoutes : RouteBuilder
{
protected override void Configure()
{
From("kafka://orders").RouteId("orders")
.Choice()
.When((IExchange e) => e.In.Headers.TryGetValue("priority", out var p) && Equals(p, "high")).To("kafka://orders-vip")
.Otherwise().To("kafka://orders-std")
.EndChoice()
.To("sql:INSERT INTO audit").Id("audit");
}
}
[Fact]
public async Task WithoutAdvice_RouteOnUnregisteredScheme_DoesNotStart()
{
await using var ctx = new RouteContext().AddRoutes(new OrdersRoutes());
var act = () => ctx.Start();
await act.Should().ThrowAsync().WithMessage("*kafka*");
}
[Fact]
public async Task ReplaceFrom_And_MockEndpoints_RunTheRouteWithoutBrokers()
{
await using var ctx = new RouteContext().AddRoutes(new OrdersRoutes());
ctx.AdviceRoute("orders", a => a
.ReplaceFrom("direct://test-in")
.MockEndpoints("kafka://*", "sql:*"));
await ctx.Start();
var vip = ctx.Mock("kafka://orders-vip").ExpectMessageCount(1).ExpectHeader("priority", "high");
var std = ctx.Mock("kafka://orders-std").ExpectMessageCount(0);
var audit = ctx.Mock("sql:INSERT INTO audit").ExpectMessageCount(1);
await ctx.SendBodyAndHeader("direct://test-in", "order-1", "priority", "high");
await vip.AssertIsSatisfiedAsync(TimeSpan.FromSeconds(2));
await std.AssertIsSatisfiedAsync(TimeSpan.FromSeconds(1));
await audit.AssertIsSatisfiedAsync(TimeSpan.FromSeconds(1));
}
[Fact]
public async Task MockEndpoints_ReachesTo_InsideSplit()
{
await using var ctx = new RouteContext().AddRoutes(b => b
.From("direct://split-in").RouteId("split")
.Split(e => (IEnumerable