source/TestCommon/source/FunctionApp.TestCommon/ServiceBus/ListenerMock/ServiceBusListenerMock.cs
/// <summary>
/// Add a message handler <paramref name="messageHandler"/> that will be used if message matches <paramref name="messageMatcher"/>.
/// If multiple message handlers can be matched with a message, then only one will be used (no guarantee for which one).
/// NOTE: The handler supplied will be invoked for all messages already received and currently present in the ReceivedMessages collection.
/// </summary>
Add a message handler  that will be used if message matches .
If multiple message handlers can be matched with a message, then only one will be used (no guarantee for which one).
NOTE: The handler supplied will be invoked for all messages already received and currently present in the ReceivedMessages collection.
Add a message handler that will be used if message matches . If multiple message handlers can be matched with a message then only one will be used ( no guarantee for which one ) . NOTE : The handler supplied will be invoked for all messages already received and currently present in the ReceivedMessages collection .
public async Task AddMessageHandlerAsync(Func<ServiceBusReceivedMessage, bool> messageMatcher, Func<ServiceBusReceivedMessage, Task> messageHandler)
        {
            var alreadyReceivedMessages = new List<ServiceBusReceivedMessage>();
            await MutableReceivedMessagesLock.WaitAsync().ConfigureAwait(false);
            try
            {
                MessageHandlers.Add(messageMatcher, messageHandler);
                alreadyReceivedMessages.AddRange(ReceivedMessages);
            }
            finally
            {
                MutableReceivedMessagesLock.Release();
            }
            foreach (var alreadyReceivedMessage in alreadyReceivedMessages)
            {
                if (messageMatcher(alreadyReceivedMessage))
                {
                    await messageHandler(alreadyReceivedMessage).ConfigureAwait(false);
                }
            }
        }
public async Task AddMessageHandlerAsync ( Func < ServiceBusReceivedMessage , bool > messageMatcher , Func < ServiceBusReceivedMessage , Task > messageHandler ) { var alreadyReceivedMessages = new List < ServiceBusReceivedMessage > ( ) ; await MutableReceivedMessagesLock . WaitAsync ( ) . ConfigureAwait ( false ) ; try { MessageHandlers . Add ( messageMatcher , messageHandler ) ; alreadyReceivedMessages . AddRange ( ReceivedMessages ) ; } finally { MutableReceivedMessagesLock . Release ( ) ; } foreach ( var alreadyReceivedMessage in alreadyReceivedMessages ) { if ( messageMatcher ( alreadyReceivedMessage ) ) { await messageHandler ( alreadyReceivedMessage ) . ConfigureAwait ( false ) ; } } }
Add a message handler  that will be used if message matches .
Add a message handler that will be used if message matches .
// Replay already received messages on messageHandler
messageMatcher
Func<ServiceBusReceivedMessage, bool>
messageHandler
Func<ServiceBusReceivedMessage, Task>