Show / Hide Table of Contents

    Class TestingHelper

    Exposes some helper methods and shortcuts to simplify testing.

    Inheritance
    object
    TestingHelper
    KafkaTestingHelper
    MqttTestingHelper
    Implements
    ITestingHelper
    Inherited Members
    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.Testing.dll
    Syntax
    public abstract class TestingHelper : ITestingHelper

    Constructors

    TestingHelper(IServiceProvider, ILogger<TestingHelper>)

    Initializes a new instance of the TestingHelper class.

    Declaration
    protected TestingHelper(IServiceProvider serviceProvider, ILogger<TestingHelper> logger)
    Parameters
    Type Name Description
    IServiceProvider serviceProvider

    The IServiceProvider.

    ILogger<TestingHelper> logger

    The ILogger<TCategoryName>.

    Properties

    Spy

    Gets the IIntegrationSpy.

    Declaration
    public IIntegrationSpy Spy { get; }
    Property Value
    Type Description
    IIntegrationSpy
    Remarks

    The IIntegrationSpy must be enabled calling AddIntegrationSpy or AddIntegrationSpyAndSubscriber.

    Methods

    GetConsumer(string)

    Gets the consumer with the specified name.

    Declaration
    public IConsumer GetConsumer(string name)
    Parameters
    Type Name Description
    string name

    The consumer name.

    Returns
    Type Description
    IConsumer

    The IConsumer with the specified name.

    GetConsumerEndpointConfiguration(string)

    Returns the ConsumerEndpointConfiguration for the specified endpoint.

    Declaration
    protected ConsumerEndpointConfiguration? GetConsumerEndpointConfiguration(string endpointName)
    Parameters
    Type Name Description
    string endpointName

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

    Returns
    Type Description
    ConsumerEndpointConfiguration

    The ConsumerEndpointConfiguration.

    GetConsumerForEndpoint(string)

    Gets the existing consumer connected to specified endpoint.

    Declaration
    public IConsumer GetConsumerForEndpoint(string endpointName)
    Parameters
    Type Name Description
    string endpointName

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

    Returns
    Type Description
    IConsumer

    The IProducer.

    GetEndpointRawName(string)

    Resolves the raw name (topic/queue name) of the specified endpoint. If the endpoint is not found in the producers or consumers configurations an InvalidOperationException is thrown.

    Declaration
    protected string GetEndpointRawName(string endpointName)
    Parameters
    Type Name Description
    string endpointName

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

    Returns
    Type Description
    string

    The raw name (topic/queue).

    GetProducerEndpointConfiguration(string)

    Returns the ProducerEndpointConfiguration for the specified endpoint.

    Declaration
    protected ProducerEndpointConfiguration? GetProducerEndpointConfiguration(string endpointName)
    Parameters
    Type Name Description
    string endpointName

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

    Returns
    Type Description
    ProducerEndpointConfiguration

    The ProducerEndpointConfiguration.

    GetProducerForConsumer(IConsumerCollection, string)

    Gets an existing producer for the endpoint consumed by the specified consumer or initializes a new one mirroring the consumer configuration.

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

    The existing consumers.

    string endpointName

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

    Returns
    Type Description
    IProducer

    The IProducer.

    GetProducerForEndpoint(string)

    Gets a producer for the specified endpoint.

    Declaration
    public IProducer GetProducerForEndpoint(string endpointName)
    Parameters
    Type Name Description
    string endpointName

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

    Returns
    Type Description
    IProducer

    The IProducer.

    IsOutboxEmptyAsync()

    Checks whether the outbox (table) is empty.

    Declaration
    public ValueTask<bool> IsOutboxEmptyAsync()
    Returns
    Type Description
    ValueTask<bool>

    A ValueTask<TResult> representing the asynchronous operation. The task result contains true if the outbox is empty, otherwise false.

    WaitUntilAllMessagesAreConsumedAsync(bool, TimeSpan?)

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

    Declaration
    public ValueTask WaitUntilAllMessagesAreConsumedAsync(bool throwTimeoutException, TimeSpan? timeout = null)
    Parameters
    Type Name Description
    bool throwTimeoutException
    A value specifying whether a <xref href="System.TimeoutException" data-throw-if-not-resolved="false"></xref> has to be thrown when the messages aren't consumed before the
    

    timeout elapses.

    TimeSpan? timeout

    The time to wait for the messages to be consumed and processed. The default is 30 seconds.

    Returns
    Type Description
    ValueTask

    A ValueTask that completes when all messages have been processed.

    Remarks

    This method works with the mocked brokers only.

    WaitUntilAllMessagesAreConsumedAsync(bool, TimeSpan?, params string[])

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

    Declaration
    public ValueTask WaitUntilAllMessagesAreConsumedAsync(bool throwTimeoutException, TimeSpan? timeout, params string[] endpointNames)
    Parameters
    Type Name Description
    bool throwTimeoutException
    A value specifying whether a <xref href="System.TimeoutException" data-throw-if-not-resolved="false"></xref> has to be thrown when the messages aren't consumed before the
    

    timeout elapses.

    TimeSpan? timeout

    The time to wait for the messages to be consumed and processed. The default is 30 seconds.

    string[] endpointNames

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

    Returns
    Type Description
    ValueTask

    A ValueTask that completes when all messages have been processed.

    Remarks

    This method works with the mocked brokers only.

    WaitUntilAllMessagesAreConsumedAsync(bool, params string[])

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

    Declaration
    public ValueTask WaitUntilAllMessagesAreConsumedAsync(bool throwTimeoutException, params string[] endpointNames)
    Parameters
    Type Name Description
    bool throwTimeoutException
    A value specifying whether a <xref href="System.TimeoutException" data-throw-if-not-resolved="false"></xref> has to be thrown when the messages aren't consumed before the
    

    timeout elapses.

    string[] endpointNames

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

    Returns
    Type Description
    ValueTask

    A ValueTask that completes when all messages have been processed.

    Remarks

    This method works with the mocked brokers only.

    WaitUntilAllMessagesAreConsumedAsync(bool, CancellationToken, params string[])

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

    Declaration
    public ValueTask WaitUntilAllMessagesAreConsumedAsync(bool throwTimeoutException, CancellationToken cancellationToken, params string[] endpointNames)
    Parameters
    Type Name Description
    bool throwTimeoutException

    A value specifying whether a TimeoutException has to be thrown when the messages aren't consumed before the CancellationToken is canceled.

    CancellationToken cancellationToken

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

    string[] endpointNames

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

    Returns
    Type Description
    ValueTask

    A ValueTask that completes when all messages have been processed.

    Remarks

    This method works with the mocked brokers only.

    WaitUntilAllMessagesAreConsumedAsync(TimeSpan?, params string[])

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

    Declaration
    public ValueTask WaitUntilAllMessagesAreConsumedAsync(TimeSpan? timeout, params string[] endpointNames)
    Parameters
    Type Name Description
    TimeSpan? timeout
    string[] endpointNames

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

    Returns
    Type Description
    ValueTask

    A ValueTask that completes when all messages have been processed.

    Remarks

    This method works with the mocked brokers only.

    WaitUntilAllMessagesAreConsumedAsync(params string[])

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

    Declaration
    public ValueTask WaitUntilAllMessagesAreConsumedAsync(params string[] endpointNames)
    Parameters
    Type Name Description
    string[] endpointNames

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

    Returns
    Type Description
    ValueTask

    A ValueTask that completes when all messages have been processed.

    Remarks

    This method works with the mocked brokers only.

    WaitUntilAllMessagesAreConsumedAsync(CancellationToken, params string[])

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

    Declaration
    public ValueTask WaitUntilAllMessagesAreConsumedAsync(CancellationToken cancellationToken, params string[] endpointNames)
    Parameters
    Type Name Description
    CancellationToken cancellationToken

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

    string[] endpointNames

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

    Returns
    Type Description
    ValueTask

    A ValueTask that completes when all messages have been processed.

    Remarks

    This method works with the mocked brokers only.

    WaitUntilAllMessagesAreConsumedCoreAsync(IReadOnlyCollection<string>, CancellationToken)

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

    Declaration
    protected abstract 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.

    Remarks

    This method works with the mocked brokers only.

    WaitUntilConnectedAsync(bool, TimeSpan?)

    Returns a ValueTask that completes when all consumers are connected and ready.

    Declaration
    public ValueTask WaitUntilConnectedAsync(bool throwTimeoutException, TimeSpan? timeout = null)
    Parameters
    Type Name Description
    bool throwTimeoutException

    A value specifying whether a TimeoutException has to be thrown when the connection isn't established before the timeout elapses.

    TimeSpan? timeout

    The time to wait for the consumers to connect. The default is 30 seconds.

    Returns
    Type Description
    ValueTask

    A ValueTask that completes when all consumers are successfully connected and ready.

    WaitUntilConnectedAsync(bool, CancellationToken)

    Returns a ValueTask that completes when all consumers are connected and ready.

    Declaration
    public ValueTask WaitUntilConnectedAsync(bool throwTimeoutException, CancellationToken cancellationToken)
    Parameters
    Type Name Description
    bool throwTimeoutException
    A value specifying whether a <xref href="System.TimeoutException" data-throw-if-not-resolved="false"></xref> has to be thrown when the connection isn't established before the
    

    CancellationToken is canceled.

    CancellationToken cancellationToken

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

    Returns
    Type Description
    ValueTask

    A Task that completes when all consumers are successfully connected and ready.

    WaitUntilConnectedAsync(TimeSpan?)

    Returns a ValueTask that completes when all consumers are connected and ready.

    Declaration
    public ValueTask WaitUntilConnectedAsync(TimeSpan? timeout = null)
    Parameters
    Type Name Description
    TimeSpan? timeout

    The time to wait for the consumers to connect. The default is 30 seconds.

    Returns
    Type Description
    ValueTask

    A ValueTask that completes when all consumers are successfully connected and ready.

    WaitUntilConnectedAsync(CancellationToken)

    Returns a ValueTask that completes when all consumers are connected and ready.

    Declaration
    public ValueTask WaitUntilConnectedAsync(CancellationToken cancellationToken)
    Parameters
    Type Name Description
    CancellationToken cancellationToken

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

    Returns
    Type Description
    ValueTask

    A ValueTask that completes when all consumers are successfully connected and ready.

    WaitUntilOutboxIsEmptyAsync(TimeSpan?)

    Returns a ValueTask that completes when all messages stored in the outbox have been produced.

    Declaration
    public ValueTask WaitUntilOutboxIsEmptyAsync(TimeSpan? timeout = null)
    Parameters
    Type Name Description
    TimeSpan? timeout

    The time to wait for the messages to be consumed and processed. The default is 30 seconds.

    Returns
    Type Description
    ValueTask

    A ValueTask that completes when the outbox is empty.

    WaitUntilOutboxIsEmptyAsync(CancellationToken)

    Returns a ValueTask that completes when all messages stored in the outbox have been produced.

    Declaration
    public ValueTask WaitUntilOutboxIsEmptyAsync(CancellationToken cancellationToken)
    Parameters
    Type Name Description
    CancellationToken cancellationToken

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

    Returns
    Type Description
    ValueTask

    A ValueTask that completes when the outbox is empty.

    Implements

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