Path: redb-identity/tests/redb.Identity.Tests/Infrastructure/TestExchange.cs
Snapshot: redb-identity, 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-identity
Page: https://redbase.app/src/dev-2026-12-06/redb-identity/tests/redb.Identity.Tests/Infrastructure/TestExchange.cs
----
using redb.Route.Abstractions;
namespace redb.Identity.Tests.Infrastructure;
///
/// Minimal for unit tests.
///
internal sealed class TestMessage : IMessage
{
public object? Body { get; set; }
public string? ContentType { get; set; }
public IDictionary Headers { get; } = new Dictionary();
public T? GetHeader(string key)
=> Headers.TryGetValue(key, out var v) && v is T t ? t : default;
public IMessage Clone()
{
var clone = new TestMessage { Body = Body, ContentType = ContentType };
foreach (var h in Headers)
clone.Headers[h.Key] = h.Value;
return clone;
}
// Test double: the deep-copy distinction (see IMessage.Snapshot) is irrelevant here.
public IMessage Snapshot() => Clone();
}
///
/// Minimal for unit tests.
///
internal sealed class TestExchange : IExchange
{
public IMessage In { get; set; } = new TestMessage();
public IMessage? Out { get; set; }
public ExchangePattern Pattern { get; set; } = ExchangePattern.InOnly;
public IDictionary Properties { get; } = new Dictionary();
public T? GetProperty(string key)
=> Properties.TryGetValue(key, out var v) && v is T t ? t : default;
public Exception? Exception { get; set; }
public bool ExceptionHandled { get; set; }
public string? RouteId { get; set; }
public string ExchangeId { get; } = Guid.NewGuid().ToString();
public bool IsStopped { get; private set; }
public void Stop() => IsStopped = true;
public IExchange Clone() => throw new NotSupportedException("Clone not needed in tests");
public IExchange Snapshot() => throw new NotSupportedException("Snapshot not needed in tests");
public ValueTask DisposeAsync() => default;
}