Skip to main content

Definition

Assembly: CloudNimble.SimpleMessageBus.Breakdance.dll Namespace: CloudNimble.SimpleMessageBus.Breakdance Inheritance: System.Object

Syntax

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
This class is part of the “Breakdance” testing utilities, named after the dance style that emphasizes breaking conventional patterns - just like how test doubles break the normal execution flow for testing.

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 object

Syntax

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 object

Syntax

Parameters

Returns

Type: bool

Equals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

GetHashCode Inherited Virtual

Inherited from object

Syntax

Returns

Type: int

GetType Inherited

Inherited from object

Syntax

Returns

Type: System.Type

MemberwiseClone Inherited

Inherited from object

Syntax

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

Returns

Type: System.Threading.Tasks.Task A completed task.

Exceptions

Examples

Remarks

This method implements the core functionality of the test double by:
  1. Adding the message to the internal collection for later verification
  2. Invoking any configured action (if set via Boolean}))
  3. Returning a completed task to satisfy the async interface
Unlike real message publishers, this method does not actually send messages to any queue. It completes synchronously and never throws exceptions unless a custom action is configured to do so.

ReferenceEquals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

SetAction

Sets an action to be executed when a message is published.

Syntax

Parameters

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 object

Syntax

Returns

Type: string?
  • CloudNimble.SimpleMessageBus.Publish.IMessagePublisher