Show / Hide Table of Contents

    Class MqttTestingHelper

    Exposes some helper methods and shortcuts to simplify testing.

    Inheritance
    object
    TestingHelper
    MqttTestingHelper
    Implements
    IMqttTestingHelper
    ITestingHelper
    Inherited Members
    TestingHelper.GetEndpointRawName(string)
    TestingHelper.GetConsumer(string)
    TestingHelper.GetConsumerForEndpoint(string)
    TestingHelper.GetConsumerEndpointConfiguration(string)
    TestingHelper.GetProducerForEndpoint(string)
    TestingHelper.GetProducerEndpointConfiguration(string)
    TestingHelper.WaitUntilConnectedAsync(TimeSpan?)
    TestingHelper.WaitUntilConnectedAsync(bool, TimeSpan?)
    TestingHelper.WaitUntilConnectedAsync(CancellationToken)
    TestingHelper.WaitUntilConnectedAsync(bool, CancellationToken)
    TestingHelper.WaitUntilAllMessagesAreConsumedAsync(params string[])
    TestingHelper.WaitUntilAllMessagesAreConsumedAsync(TimeSpan?, params string[])
    TestingHelper.WaitUntilAllMessagesAreConsumedAsync(bool, params string[])
    TestingHelper.WaitUntilAllMessagesAreConsumedAsync(bool, TimeSpan?)
    TestingHelper.WaitUntilAllMessagesAreConsumedAsync(bool, TimeSpan?, params string[])
    TestingHelper.WaitUntilAllMessagesAreConsumedAsync(CancellationToken, params string[])
    TestingHelper.WaitUntilAllMessagesAreConsumedAsync(bool, CancellationToken, params string[])
    TestingHelper.WaitUntilOutboxIsEmptyAsync(TimeSpan?)
    TestingHelper.WaitUntilOutboxIsEmptyAsync(CancellationToken)
    TestingHelper.IsOutboxEmptyAsync()
    TestingHelper.Spy
    object.GetType()
    object.MemberwiseClone()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    Namespace: Silverback.Testing
    Assembly: Silverback.Integration.MQTT.Testing.dll
    Syntax
    public class MqttTestingHelper : TestingHelper, IMqttTestingHelper, ITestingHelper

    Constructors

    MqttTestingHelper(IServiceProvider, ILogger<MqttTestingHelper>)

    Initializes a new instance of the MqttTestingHelper class.

    Declaration
    public MqttTestingHelper(IServiceProvider serviceProvider, ILogger<MqttTestingHelper> logger)
    Parameters
    Type Name Description
    IServiceProvider serviceProvider

    The IServiceProvider.

    ILogger<MqttTestingHelper> logger

    The ISilverbackLogger.

    Methods

    GetClientSession(string)

    Gets the IClientSession of the specified client.

    Declaration
    public IClientSession GetClientSession(string clientId)
    Parameters
    Type Name Description
    string clientId

    The client id.

    Returns
    Type Description
    IClientSession

    The IClientSession.

    Remarks

    This method works with the mocked MQTT broker only. See UseMockedMqtt(SilverbackBuilder, Action<IMockedMqttOptionsBuilder>?) or AddMockedMqtt(BrokerOptionsBuilder, Action<IMockedMqttOptionsBuilder>?).

    GetMessages(string)

    Gets the messages that have been published to the specified topic.

    Declaration
    public IReadOnlyList<MqttApplicationMessage> GetMessages(string topic)
    Parameters
    Type Name Description
    string topic

    The topic.

    Returns
    Type Description
    IReadOnlyList<MqttApplicationMessage>

    The messages published to the topic.

    Remarks

    This method works with the mocked MQTT broker only. See UseMockedMqtt(SilverbackBuilder, Action<IMockedMqttOptionsBuilder>?) or AddMockedMqtt(BrokerOptionsBuilder, Action<IMockedMqttOptionsBuilder>?).

    GetProducer(Action<MqttClientConfigurationBuilder>)

    Gets a new producer with the specified configuration.

    Declaration
    public IProducer GetProducer(Action<MqttClientConfigurationBuilder> configurationBuilderAction)
    Parameters
    Type Name Description
    Action<MqttClientConfigurationBuilder> configurationBuilderAction

    An Action<T> that takes the MqttClientConfigurationBuilder and configures it.

    Returns
    Type Description
    IProducer

    The IProducer.

    GetProducerForConsumer(IConsumerCollection, string)

    Gets a producer for the specified endpoint.

    Declaration
    protected override IProducer? GetProducerForConsumer(IConsumerCollection consumers, string endpointName)
    Parameters
    Type Name Description
    IConsumerCollection consumers
    string endpointName

    The endpoint name. It could be either the topic/queue name or the friendly name.

    Returns
    Type Description
    IProducer

    The IProducer.

    Overrides
    TestingHelper.GetProducerForConsumer(IConsumerCollection, string)

    WaitUntilAllMessagesAreConsumedCoreAsync(IReadOnlyCollection<string>, CancellationToken)

    Returns a ValueTask that completes when all messages routed to the consumers have been processed and committed.

    Declaration
    protected override Task WaitUntilAllMessagesAreConsumedCoreAsync(IReadOnlyCollection<string> endpointNames, CancellationToken cancellationToken)
    Parameters
    Type Name Description
    IReadOnlyCollection<string> endpointNames

    The names of the endpoints to wait for. If not specified, all endpoints are considered.

    CancellationToken cancellationToken

    A CancellationToken to observe while waiting for the task to complete.

    Returns
    Type Description
    Task

    A ValueTask that completes when all messages have been processed.

    Overrides
    TestingHelper.WaitUntilAllMessagesAreConsumedCoreAsync(IReadOnlyCollection<string>, CancellationToken)
    Remarks

    This method works with the mocked brokers only.

    Implements

    IMqttTestingHelper
    ITestingHelper
    GitHub E-Mail
    ↑ Back to top © 2026 Sergio Aquilini