Definition
Assembly: CloudNimble.SimpleMessageBus.Breakdance.dll Namespace: CloudNimble.SimpleMessageBus.Breakdance Inheritance: System.ObjectSyntax
Summary
A test double for IMessagePublisher that captures published messages for assertions. Used in testing scenarios to verify that expected messages were published correctly.Remarks
The TestableMessagePublisher is designed for unit and integration testing of message publishing scenarios. It implements the IMessagePublisher interface but instead of sending messages to actual queues, it captures them in memory for verification. This enables testing of message publishing behavior without requiring real message queue infrastructure. Key testing features:- Captures all published messages for assertion
- Supports configurable actions to simulate publish behavior
- Provides methods to reset state between tests
- Maintains message order for sequence verification
Examples
Constructors
.ctor
Initializes a new instance of the TestableMessagePublisher class. Creates an empty publisher with no published messages or configured actions.Syntax
.ctor Inherited
Inherited from
objectSyntax
Properties
PublishedMessages
Gets a read-only list of all messages that have been published via this publisher. This collection can be used in test assertions to verify published message content.Syntax
Property Value
Type:System.Collections.Generic.IReadOnlyList<CloudNimble.SimpleMessageBus.Core.IMessage>
A read-only list containing all messages published through this publisher in the order they were published.
The collection is empty when the publisher is first created or after TestableMessagePublisher.ClearMessages is called.
Examples
Remarks
This property provides access to all messages captured during testing. Messages are stored in publication order, allowing verification of both message content and sequence. The returned collection is read-only to prevent external modification of the test state. Use this property in test assertions to verify:- The correct number of messages were published
- The right message types were published
- Messages contain expected data
- Messages were published in the correct order
Methods
ClearMessages
Clears all published messages from the internal collection. Use this method to reset the state between tests.Syntax
Examples
Remarks
This method is typically called in test setup or teardown to ensure each test starts with a clean state. After calling this method, the TestableMessagePublisher.PublishedMessages collection will be empty until new messages are published. This prevents test interference where one test’s published messages affect another test’s assertions.Equals Inherited Virtual
Inherited from
objectSyntax
Parameters
| Name | Type | Description |
|---|---|---|
obj | object? | - |
Returns
Type:bool
Equals Inherited
Inherited from
objectSyntax
Parameters
| Name | Type | Description |
|---|---|---|
objA | object? | - |
objB | object? | - |
Returns
Type:bool
GetHashCode Inherited Virtual
Inherited from
objectSyntax
Returns
Type:int
GetType Inherited
Inherited from
objectSyntax
Returns
Type:System.Type
MemberwiseClone Inherited
Inherited from
objectSyntax
Returns
Type:object
PublishAsync
Implements the IMessagePublisher interface method by capturing the published message for later assertion and optionally invoking a configured action.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
message | CloudNimble.SimpleMessageBus.Core.IMessage | The message to publish. |
isSystemGenerated | bool | Indicates whether the message is system-generated. |
Returns
Type:System.Threading.Tasks.Task
A completed task.
Exceptions
| Exception | Description |
|---|---|
Exception | May throw exceptions if a custom action configured via Boolean}) throws. |
Examples
Remarks
This method implements the core functionality of the test double by:- Adding the message to the internal collection for later verification
- Invoking any configured action (if set via
Boolean})) - Returning a completed task to satisfy the async interface
ReferenceEquals Inherited
Inherited from
objectSyntax
Parameters
| Name | Type | Description |
|---|---|---|
objA | object? | - |
objB | object? | - |
Returns
Type:bool
SetAction
Sets an action to be executed when a message is published.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
onPublish | System.Action<CloudNimble.SimpleMessageBus.Core.IMessage, bool> | The action to execute when PublishAsync is called. |
| The action receives the published message and the isSystemGenerated flag. |
Examples
Remarks
This method allows customization of the publisher’s behavior during testing. The configured action is invoked after the message is added to the TestableMessagePublisher.PublishedMessages collection, allowing for simulation of various publishing scenarios such as failures, delays, or side effects. Setting this to null removes any previously configured action. The action is optional and publishing will work normally even without it being set.ToString Inherited Virtual
Inherited from
objectSyntax
Returns
Type:string?
Related APIs
- CloudNimble.SimpleMessageBus.Publish.IMessagePublisher