source/TestCommon/source/FunctionApp.TestCommon/EventHub/ListenerMock/EventHubListenerMock.cs
/// <summary>
/// Add an event handler <paramref name="eventHandler"/> that will be used if event data matches <paramref name="eventMatcher"/>.
/// If multiple event handlers can be matched with an event, then only one will be used (no guarantee for which one).
/// NOTE: The handler supplied will be invoked for all events already received and currently present in the ReceivedEvents collection.
/// </summary>
Add an event handler  that will be used if event data matches .
If multiple event handlers can be matched with an event, then only one will be used (no guarantee for which one).
NOTE: The handler supplied will be invoked for all events already received and currently present in the ReceivedEvents collection.
Add an event handler that will be used if event data matches . If multiple event handlers can be matched with an event then only one will be used ( no guarantee for which one ) . NOTE : The handler supplied will be invoked for all events already received and currently present in the ReceivedEvents collection .
public async Task AddEventHandlerAsync(Func<EventData, bool> eventMatcher, Func<EventData, Task> eventHandler)
        {
            var alreadyReceivedEvents = new List<EventData>();
            await MutableReceivedEventsLock.WaitAsync()
                .ConfigureAwait(false);
            try
            {
                EventHandlers.Add(eventMatcher, eventHandler);
                alreadyReceivedEvents.AddRange(ReceivedEvents);
            }
            finally
            {
                MutableReceivedEventsLock.Release();
            }
            foreach (var alreadyReceivedEvent in alreadyReceivedEvents)
            {
                if (eventMatcher(alreadyReceivedEvent))
                {
                    await eventHandler(alreadyReceivedEvent)
                        .ConfigureAwait(false);
                }
            }
        }
public async Task AddEventHandlerAsync ( Func < EventData , bool > eventMatcher , Func < EventData , Task > eventHandler ) { var alreadyReceivedEvents = new List < EventData > ( ) ; await MutableReceivedEventsLock . WaitAsync ( ) . ConfigureAwait ( false ) ; try { EventHandlers . Add ( eventMatcher , eventHandler ) ; alreadyReceivedEvents . AddRange ( ReceivedEvents ) ; } finally { MutableReceivedEventsLock . Release ( ) ; } foreach ( var alreadyReceivedEvent in alreadyReceivedEvents ) { if ( eventMatcher ( alreadyReceivedEvent ) ) { await eventHandler ( alreadyReceivedEvent ) . ConfigureAwait ( false ) ; } } }
Add an event handler  that will be used if event data matches .
Add an event handler that will be used if event data matches .
// Replay already received events on eventHandler
eventMatcher
Func<EventData, bool>
eventHandler
Func<EventData, Task>