Class ProtoMessagingBuilder

Namespace
ProtoTest.Messaging
Assembly
ProtoTest.Messaging.dll
public sealed class ProtoMessagingBuilder
Inheritance
ProtoMessagingBuilder
Inherited Members
Extension Methods

Properties

Services

Gets the service collection the messaging integration registers into.

public IServiceCollection Services { get; }

Property Value

IServiceCollection

Methods

CaptureAttachments(Action<MessagingAttachmentOptions>?)

Enables automatic published and received payload attachments, sanitized and redacted. Repeated calls compose: every callback runs in registration order and configuration binds over the result.

public ProtoMessagingBuilder CaptureAttachments(Action<MessagingAttachmentOptions>? configure = null)

Parameters

configure Action<MessagingAttachmentOptions>

Returns

ProtoMessagingBuilder

Declare(params string[])

Declares the destinations this suite owns, in code, so the adapter creates them on the broker during test setup - before any tap binds and before the act publishes. A suite that owns the broker and publishes its own events uses Declare for the destinations nothing else declares; a destination the application declares stays the application's. Repeated calls compose and skip a value already declared; configuration under ProtoTest:Messaging:DeclaredDestinations still applies over these values. Declaration is idempotent: an adapter leaves an existing destination as it is, a destination is declared once per run, and a repeated declaration is a no-op.

public ProtoMessagingBuilder Declare(params string[] destinations)

Parameters

destinations string[]

Returns

ProtoMessagingBuilder

Remarks

The declaration is configuration, not a runtime call: the builder is consumed when AddMessaging runs, so a destination cannot be declared after a test has prepared. An adapter whose broker has no topology - the in-memory broker, where every destination already exists - treats Declare as a no-op. A queue destination is consumed, not declared: the component that owns the queue creates it, so Declare refuses the queue form.

Exceptions

ArgumentException

destinations is empty, or contains a null, empty or whitespace destination, or a queue destination.

Tap(params string[])

Declares the destinations this suite taps, in code, so the adapter can bind each test's tap during setup rather than at the first await. A destination is an exchange name or a queue destination (Queue(string), consumed directly by an adapter that owns queues). Repeated calls compose; configuration under ProtoTest:Messaging:Destinations still applies over these values, so an environment can add its own.

public ProtoMessagingBuilder Tap(params string[] destinations)

Parameters

destinations string[]

Returns

ProtoMessagingBuilder

Remarks

Tap is a reliability declaration: pre-bind every destination the act publishes to. A destination declared only at the first AwaitAsync is bound then, so it misses every message published before that await.

Exceptions

ArgumentException

destinations is empty, or contains a null, empty or whitespace destination.

UseBroker(Func<IServiceProvider, IProtoMessageBroker>)

Replaces the default in-memory broker with an adapter, for example RabbitMQ. The broker the factory returns is owned by ProtoTest: it is released with the run.

public ProtoMessagingBuilder UseBroker(Func<IServiceProvider, IProtoMessageBroker> factory)

Parameters

factory Func<IServiceProvider, IProtoMessageBroker>

Returns

ProtoMessagingBuilder

UseBroker(Func<IServiceProvider, IProtoMessageBroker>, params string[])

Replaces the default in-memory broker with an adapter that reads its address from addressKeys. The Broker capability is then declared only while at least one key can provide an address - a configured value, or a key registered infrastructure declares and fills when it starts - so a run without one skips instead of failing at setup or first use. An adapter that provides its address without configuration keys keeps the unconditional declaration. The broker the factory returns is owned by ProtoTest: it is released with the run.

public ProtoMessagingBuilder UseBroker(Func<IServiceProvider, IProtoMessageBroker> factory, params string[] addressKeys)

Parameters

factory Func<IServiceProvider, IProtoMessageBroker>
addressKeys string[]

Returns

ProtoMessagingBuilder

UseBrokerWhenInProcess(Func<IServiceProvider, IProtoMessageBroker>, string, params string[])

Replaces the default in-memory broker with an adapter that serves only while application is hosted in-process - an in-process resource whose harness or listener exists only in this process. The Broker capability is declared only while the application's provider chain winner runs it in-process, so a loopback, container or AppHost application drops it and tests skip instead of advertising an adapter that cannot serve; a host whose application declares no chain keeps the configured-keys rule over configuredKeys. The MassTransit bridge over the application's in-process test harness is the example. The broker the factory returns is owned by ProtoTest: it is released with the run.

public ProtoMessagingBuilder UseBrokerWhenInProcess(Func<IServiceProvider, IProtoMessageBroker> factory, string application, params string[] configuredKeys)

Parameters

factory Func<IServiceProvider, IProtoMessageBroker>
application string
configuredKeys string[]

Returns

ProtoMessagingBuilder