Path: redb-route/tests/redb.Route.Tests/Processors/DelegateProcessorTests.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/DelegateProcessorTests.cs
----
using AwesomeAssertions;
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.Processors;
namespace redb.Route.Tests.Processors;
/// Tests for .
public class DelegateProcessorTests
{
/// Async delegate receives the exchange.
[Fact]
public async Task Process_AsyncDelegate_Executes()
{
IExchange? captured = null;
var processor = new DelegateProcessor(async (ex, ct) =>
{
captured = ex;
await Task.CompletedTask;
});
var exchange = new Exchange(new Message("hello"));
await processor.Process(exchange);
captured.Should().BeSameAs(exchange);
}
/// Sync delegate receives the exchange.
[Fact]
public async Task Process_SyncDelegate_Executes()
{
object? capturedBody = null;
var processor = new DelegateProcessor(ex =>
{
capturedBody = ex.In.Body;
});
var exchange = new Exchange(new Message("test"));
await processor.Process(exchange);
capturedBody.Should().Be("test");
}
/// Delegate can modify the exchange body.
[Fact]
public async Task Process_CanModifyExchange()
{
var processor = new DelegateProcessor(ex =>
{
ex.In.Body = "modified";
});
var exchange = new Exchange(new Message("original"));
await processor.Process(exchange);
exchange.In.Body.Should().Be("modified");
}
/// Null async delegate throws ArgumentNullException.
[Fact]
public void Constructor_NullAsyncDelegate_Throws()
{
var act = () => new DelegateProcessor((Func)null!);
act.Should().Throw();
}
/// Null sync delegate throws ArgumentNullException.
[Fact]
public void Constructor_NullSyncDelegate_Throws()
{
var act = () => new DelegateProcessor((Action)null!);
act.Should().Throw();
}
/// CancellationToken is passed through to the delegate.
[Fact]
public async Task Process_CancellationToken_PassedThrough()
{
CancellationToken capturedToken = default;
var processor = new DelegateProcessor((ex, ct) =>
{
capturedToken = ct;
return Task.CompletedTask;
});
using var cts = new CancellationTokenSource();
var exchange = new Exchange();
await processor.Process(exchange, cts.Token);
capturedToken.Should().Be(cts.Token);
}
}