Interface ITestingHelper
- Namespace
- Silverback.Testing
- Assembly
- Silverback.Integration.Testing.dll
Exposes some helper methods and shortcuts to simplify testing.
public interface ITestingHelper
Properties
Outbox
Gets the IOutboxTestingHelper, exposing the helpers to test the applications using the transactional outbox.
IOutboxTestingHelper Outbox { get; }
Property Value
Spy
Gets the IIntegrationSpy.
IIntegrationSpy Spy { get; }
Property Value
Remarks
The IIntegrationSpy must be enabled calling AddIntegrationSpy or AddIntegrationSpyAndSubscriber.
Exceptions
- InvalidOperationException
The IIntegrationSpy isn't registered.
Methods
GetConsumer(string)
Gets the consumer with the specified name.
IConsumer GetConsumer(string name)
Parameters
namestringThe consumer name.
Returns
Exceptions
- KeyNotFoundException
No consumer with the specified
nameexists.
GetConsumerForEndpoint(string)
Gets the existing consumer connected to specified endpoint.
IConsumer GetConsumerForEndpoint(string endpointName)
Parameters
endpointNamestringThe endpoint name. It could be either the topic/queue name or the friendly name. An endpoint with the specified friendly name takes precedence over an endpoint with the specified topic/queue name.
Returns
Exceptions
- InvalidOperationException
No consumer is configured for the specified endpoint.
GetProducerForEndpoint(string)
Gets a producer for the specified endpoint.
IProducer GetProducerForEndpoint(string endpointName)
Parameters
endpointNamestringThe endpoint name. It could be either the topic/queue name or the friendly name.
Returns
Remarks
If no producer endpoint has the specified name, a new producer is created mirroring the consumer endpoint subscribing the topic or having the specified friendly name: it serializes and encrypts the messages the way the consumer expects them and produces them to the consumed topic. The connection security settings aren't mirrored.
Exceptions
- InvalidOperationException
No producer or consumer is configured for the specified endpoint, the endpoint is a topic pattern or wildcard filter, the consumer endpoint subscribes only topic patterns or wildcard filters, or the key provider of the consumer's decryption settings doesn't return a key.
- NotSupportedException
The decryption settings of the consumer endpoint to mirror aren't supported.
IsOutboxEmptyAsync()
Checks whether the outbox (table) is empty.
ValueTask<bool> IsOutboxEmptyAsync()
Returns
- ValueTask<bool>
A ValueTask<TResult> representing the asynchronous operation. The task result contains
trueif the outbox is empty, otherwisefalse.
Remarks
Only the outboxes actively drained by a registered and not paused outbox worker are considered (see IOutboxTestingHelper).
WaitUntilAllMessagesAreConsumedAsync(bool, TimeSpan?)
Returns a ValueTask that completes when all messages routed to the consumers have been processed.
ValueTask WaitUntilAllMessagesAreConsumedAsync(bool throwTimeoutException, TimeSpan? timeout = null)
Parameters
throwTimeoutExceptionboolA value specifying whether a TimeoutException has to be thrown when the messages aren't consumed before the timeout elapses.
timeoutTimeSpan?The time to wait for the messages to be consumed and processed. The default is 30 seconds.
Returns
Remarks
This method works with the mocked brokers only.
Exceptions
- TimeoutException
The
throwTimeoutExceptionistrueand the timeout elapsed before all messages were consumed and processed.
WaitUntilAllMessagesAreConsumedAsync(bool, TimeSpan?, params string[])
Returns a ValueTask that completes when all messages routed to the consumers have been processed.
ValueTask WaitUntilAllMessagesAreConsumedAsync(bool throwTimeoutException, TimeSpan? timeout, params string[] endpointNames)
Parameters
throwTimeoutExceptionboolA value specifying whether a TimeoutException has to be thrown when the messages aren't consumed before the timeout elapses.
timeoutTimeSpan?The time to wait for the messages to be consumed and processed. The default is 30 seconds.
endpointNamesstring[]The names of the endpoints to wait for. If not specified, or if one of them is the name of a producer endpoint of the tested broker whose topic is resolved dynamically per message, all endpoints are considered.
Returns
Remarks
This method works with the mocked brokers only.
Exceptions
- TimeoutException
The
throwTimeoutExceptionistrueand the timeout elapsed before all messages were consumed and processed.- InvalidOperationException
One of the
endpointNamesdoesn't match any endpoint.
WaitUntilAllMessagesAreConsumedAsync(bool, params string[])
Returns a ValueTask that completes when all messages routed to the consumers have been processed.
ValueTask WaitUntilAllMessagesAreConsumedAsync(bool throwTimeoutException, params string[] endpointNames)
Parameters
throwTimeoutExceptionboolA value specifying whether a TimeoutException has to be thrown when the messages aren't consumed before the timeout elapses.
endpointNamesstring[]The names of the endpoints to wait for. If not specified, or if one of them is the name of a producer endpoint of the tested broker whose topic is resolved dynamically per message, all endpoints are considered.
Returns
Remarks
This method works with the mocked brokers only.
Exceptions
- TimeoutException
The
throwTimeoutExceptionistrueand the default timeout elapsed before all messages were consumed and processed.- InvalidOperationException
One of the
endpointNamesdoesn't match any endpoint.
WaitUntilAllMessagesAreConsumedAsync(bool, CancellationToken, params string[])
Returns a ValueTask that completes when all messages routed to the consumers have been processed.
ValueTask WaitUntilAllMessagesAreConsumedAsync(bool throwTimeoutException, CancellationToken cancellationToken, params string[] endpointNames)
Parameters
throwTimeoutExceptionboolA value specifying whether a TimeoutException has to be thrown when the messages aren't consumed before the CancellationToken is canceled.
cancellationTokenCancellationTokenA CancellationToken to observe while waiting for the task to complete.
endpointNamesstring[]The names of the endpoints to wait for. If not specified, or if one of them is the name of a producer endpoint of the tested broker whose topic is resolved dynamically per message, all endpoints are considered.
Returns
Remarks
This method works with the mocked brokers only.
Exceptions
- TimeoutException
The
throwTimeoutExceptionistrueand thecancellationTokenwas canceled before all messages were consumed and processed.- InvalidOperationException
One of the
endpointNamesdoesn't match any endpoint.
WaitUntilAllMessagesAreConsumedAsync(TimeSpan?, params string[])
Returns a ValueTask that completes when all messages routed to the consumers have been processed.
ValueTask WaitUntilAllMessagesAreConsumedAsync(TimeSpan? timeout, params string[] endpointNames)
Parameters
timeoutTimeSpan?The time to wait for the messages to be consumed and processed. The default is 30 seconds.
endpointNamesstring[]The names of the endpoints to wait for. If not specified, or if one of them is the name of a producer endpoint of the tested broker whose topic is resolved dynamically per message, all endpoints are considered.
Returns
Remarks
This method works with the mocked brokers only.
Exceptions
- TimeoutException
The timeout elapsed before all messages were consumed and processed.
- InvalidOperationException
One of the
endpointNamesdoesn't match any endpoint.
WaitUntilAllMessagesAreConsumedAsync(params string[])
Returns a ValueTask that completes when all messages routed to the consumers have been processed.
ValueTask WaitUntilAllMessagesAreConsumedAsync(params string[] endpointNames)
Parameters
endpointNamesstring[]The names of the endpoints to wait for. If not specified, or if one of them is the name of a producer endpoint of the tested broker whose topic is resolved dynamically per message, all endpoints are considered.
Returns
Remarks
This method works with the mocked brokers only.
Exceptions
- TimeoutException
The default timeout elapsed before all messages were consumed and processed.
- InvalidOperationException
One of the
endpointNamesdoesn't match any endpoint.
WaitUntilAllMessagesAreConsumedAsync(CancellationToken, params string[])
Returns a ValueTask that completes when all messages routed to the consumers have been processed.
ValueTask WaitUntilAllMessagesAreConsumedAsync(CancellationToken cancellationToken, params string[] endpointNames)
Parameters
cancellationTokenCancellationTokenA CancellationToken to observe while waiting for the task to complete.
endpointNamesstring[]The names of the endpoints to wait for. If not specified, or if one of them is the name of a producer endpoint of the tested broker whose topic is resolved dynamically per message, all endpoints are considered.
Returns
Remarks
This method works with the mocked brokers only.
Exceptions
- TimeoutException
The
cancellationTokenwas canceled before all messages were consumed and processed.- InvalidOperationException
One of the
endpointNamesdoesn't match any endpoint.
WaitUntilConnectedAsync(bool, TimeSpan?)
Returns a ValueTask that completes when all consumers are connected and ready.
ValueTask WaitUntilConnectedAsync(bool throwTimeoutException, TimeSpan? timeout = null)
Parameters
throwTimeoutExceptionboolA value specifying whether a TimeoutException has to be thrown when the connection isn't established before the timeout elapses.
timeoutTimeSpan?The time to wait for the consumers to connect. The default is 30 seconds.
Returns
Exceptions
- TimeoutException
The
throwTimeoutExceptionistrueand the timeout elapsed before all consumers were connected.
WaitUntilConnectedAsync(bool, CancellationToken)
Returns a ValueTask that completes when all consumers are connected and ready.
ValueTask WaitUntilConnectedAsync(bool throwTimeoutException, CancellationToken cancellationToken)
Parameters
throwTimeoutExceptionboolA value specifying whether a TimeoutException has to be thrown when the connection isn't established before the CancellationToken is canceled.
cancellationTokenCancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
Exceptions
- TimeoutException
The
throwTimeoutExceptionistrueand thecancellationTokenwas canceled before all consumers were connected.
WaitUntilConnectedAsync(TimeSpan?)
Returns a ValueTask that completes when all consumers are connected and ready.
ValueTask WaitUntilConnectedAsync(TimeSpan? timeout = null)
Parameters
timeoutTimeSpan?The time to wait for the consumers to connect. The default is 30 seconds.
Returns
Exceptions
- TimeoutException
The timeout elapsed before all consumers were connected.
WaitUntilConnectedAsync(CancellationToken)
Returns a ValueTask that completes when all consumers are connected and ready.
ValueTask WaitUntilConnectedAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
Exceptions
- TimeoutException
The
cancellationTokenwas canceled before all consumers were connected.
WaitUntilOutboxIsEmptyAsync(TimeSpan?)
Returns a ValueTask that completes when all messages stored in the outbox have been produced.
ValueTask WaitUntilOutboxIsEmptyAsync(TimeSpan? timeout = null)
Parameters
timeoutTimeSpan?The time to wait for the messages to be consumed and processed. The default is 30 seconds.
Returns
Remarks
Only the outboxes actively drained by a registered and not paused outbox worker are considered (see IOutboxTestingHelper).
Exceptions
- TimeoutException
The timeout elapsed before the outbox was emptied.
WaitUntilOutboxIsEmptyAsync(CancellationToken)
Returns a ValueTask that completes when all messages stored in the outbox have been produced.
ValueTask WaitUntilOutboxIsEmptyAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
Remarks
Only the outboxes actively drained by a registered and not paused outbox worker are considered (see IOutboxTestingHelper).
Exceptions
- OperationCanceledException
The
cancellationTokenwas canceled before the outbox was emptied.