AsyncMediator.Test.MediatorTests.ExecuteDeferredEvents_WhenCalled_ShouldCallAllEventHandlers C# (CSharp) Method

ExecuteDeferredEvents_WhenCalled_ShouldCallAllEventHandlers() private method

private ExecuteDeferredEvents_WhenCalled_ShouldCallAllEventHandlers ( ) : System.Threading.Tasks.Task
return System.Threading.Tasks.Task
        public async Task ExecuteDeferredEvents_WhenCalled_ShouldCallAllEventHandlers()
        {
            // Arrange
            var @event = new FakeEvent { Id = 1 };
            var handlerFactory = new MessageHandlerRegistry();
            var mediator = new Mediator(handlerFactory.MultiInstanceFactory, handlerFactory.SingleInstanceFactory);

            handlerFactory.AddHandlersForEvent(new List<IEventHandler<FakeEvent>>
            {
                _autoSubstitute.SubstituteFor<HandlerDeferringMultipleEvents>(mediator),
                _autoSubstitute.SubstituteFor<HandlerDeferringSingleEvent>(mediator),
                _autoSubstitute.SubstituteFor<HandlerWithoutAdditionalEvents>()
            });

            mediator.DeferEvent(@event);

            // Act
            await mediator.ExecuteDeferredEvents();

            // Assert
            foreach (var handler in handlerFactory.GetHandlersFor<FakeEvent>())
            {
                handler.Received().Handle(Arg.Any<FakeEvent>()).FireAndForget();
            }
        }