Table of Contents

Class MqttTestingHelper

Namespace
Silverback.Testing
Assembly
Silverback.Integration.MQTT.Testing.dll

Exposes some helper methods and shortcuts to simplify testing.

public class MqttTestingHelper : TestingHelper, IMqttTestingHelper, ITestingHelper
Inheritance
MqttTestingHelper
Implements
Inherited Members

Constructors

MqttTestingHelper(IServiceProvider, ILogger<MqttTestingHelper>)

Initializes a new instance of the MqttTestingHelper class.

public MqttTestingHelper(IServiceProvider serviceProvider, ILogger<MqttTestingHelper> logger)

Parameters

serviceProvider IServiceProvider

The IServiceProvider.

logger ILogger<MqttTestingHelper>

The ISilverbackLogger.

Methods

GetClientSession(string)

Gets the IClientSession of the specified client.

public IClientSession GetClientSession(string clientId)

Parameters

clientId string

The client id.

Returns

IClientSession

The IClientSession.

Remarks

GetMessages(string)

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

public IReadOnlyList<MqttApplicationMessage> GetMessages(string topic)

Parameters

topic string

The topic.

Returns

IReadOnlyList<MqttApplicationMessage>

The messages published to the topic.

Remarks

GetProducer(Action<MqttClientConfigurationBuilder>)

Gets a new producer with the specified configuration.

public IProducer GetProducer(Action<MqttClientConfigurationBuilder> configurationBuilderAction)

Parameters

configurationBuilderAction Action<MqttClientConfigurationBuilder>

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

Returns

IProducer

The IProducer.

GetProducerForConsumer(IConsumerCollection, string)

Gets a producer for the specified endpoint.

protected override IProducer? GetProducerForConsumer(IConsumerCollection consumers, string endpointName)

Parameters

consumers IConsumerCollection
endpointName string

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

Returns

IProducer

The IProducer.

WaitUntilAllMessagesAreConsumedCoreAsync(IReadOnlyCollection<string>, CancellationToken)

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

protected override Task WaitUntilAllMessagesAreConsumedCoreAsync(IReadOnlyCollection<string> endpointNames, CancellationToken cancellationToken)

Parameters

endpointNames IReadOnlyCollection<string>

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

Task

A ValueTask that completes when all messages have been processed.

Remarks

This method works with the mocked brokers only.