Class MqttTestingHelper
Exposes some helper methods and shortcuts to simplify testing.
Inherited Members
Namespace: Silverback.Testing
Assembly: Silverback.Integration.MQTT.Testing.dll
Syntax
public class MqttTestingHelper : TestingHelper<MqttBroker>, IMqttTestingHelper, ITestingHelper<MqttBroker>
Constructors
| Improve this doc View sourceMqttTestingHelper(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
| Improve this doc View sourceGetClientSession(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(ISilverbackBuilder, Action<IMockedMqttOptionsBuilder>?) or AddMockedMqtt(IBrokerOptionsBuilder, 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 name of 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(ISilverbackBuilder, Action<IMockedMqttOptionsBuilder>?) or AddMockedMqtt(IBrokerOptionsBuilder, Action<IMockedMqttOptionsBuilder>?).
WaitUntilAllMessagesAreConsumedAsync(bool, TimeSpan?)
Returns a Task that completes when all messages routed to the consumers have been processed and committed.
Declaration
public override Task WaitUntilAllMessagesAreConsumedAsync(bool throwTimeoutException, TimeSpan? timeout = null)
Parameters
Type | Name | Description |
---|---|---|
bool | throwTimeoutException | A value specifying whether a TimeoutException has to be thrown when the messages aren't consumed before the timeout expires. |
TimeSpan? | timeout | The time to wait for the messages to be consumed and processed. The default is 30 seconds. |
Returns
Type | Description |
---|---|
Task | A Task that completes when all messages have been processed. |
Overrides
Remarks
This method works with the mocked brokers only.