Class MockResponse

Assembly: redb.Route.dll

Scripted behaviour of a for one message ()
or for every message (): set the reply body or a header,
delay, throw, or run arbitrary code. Actions run in the order they were added, after the exchange
has been recorded, so a throwing mock still counts the message it rejected.

This is what makes mock:// usable behind Enrich / PollEnrich / request-reply:
the reply body is whatever left in the exchange.

public sealed class MockResponse

Inheritance

Object→MockResponse

Properties

MessageNumber

1-based ordinal of the message this response applies to; null = every message.

public int? MessageNumber { get; }

Methods

Delay(TimeSpan)

Waits before continuing — simulates a slow downstream system.

public MockResponse Delay(TimeSpan delay)

Do(Action<IExchange>)

Runs arbitrary synchronous code against the exchange.

public MockResponse Do(Action<IExchange> action)

Do(Func<IExchange, CancellationToken, Task>)

Runs arbitrary asynchronous code against the exchange.

public MockResponse Do(Func<IExchange, CancellationToken, Task> action)

SetBody(object?)

Replaces the message body (the reply seen by Enrich / request-reply callers).

public MockResponse SetBody(object? body)

SetHeader(string, object?)

Sets a header on the message.

public MockResponse SetHeader(string name, object? value)

Throw(Exception)

Throws the given exception — simulates a failing downstream system.

public MockResponse Throw(Exception exception)

Throw<TException>(string)

Throws a new TException with the given message.

public MockResponse Throw<TException>(string message) where TException : Exception