public async Task nEventStreamUpdated_WhenSubscriptionWasStopped_Throws(
            StreamConsumingNotificationListenerStub listener,
            EventStreamUpdated notification,
            INotificationListenerSubscription subscription)
        {
            listener.OnSubscriptionStopped();

            await Assert.ThrowsAsync <InvalidOperationException>(() => listener.On(notification));
        }
        public async Task OnEventStreamUpdated_WhenListenerProcessingCompleted_ClosesConsumer(
            [Frozen] Mock <IEventStreamConsumer> consumerMock,
            StreamConsumingNotificationListenerStub listener,
            EventStreamUpdated notification)
        {
            await listener.On(notification);

            consumerMock.Verify(self => self.CloseAsync());
        }
        public async Task OnEventStreamUpdated_WhenListenerProcessingCompleted_DoesNotDefereNotification(
            [Frozen] Mock <INotificationListenerSubscription> subscriptionMock,
            StreamConsumingNotificationListenerStub listener,
            EventStreamUpdated notification)
        {
            await listener.On(notification);

            subscriptionMock.Verify(self => self.RetryNotificationProcessingAsync(notification), Times.Never());
        }
        public async Task OnEventStreamUpdated_WhenListenerProcessingCompleted_CommitsConsumedStreamVersion(
            [Frozen] Mock <IEventStreamConsumer> consumerMock,
            StreamConsumingNotificationListenerStub listener,
            EventStreamUpdated notification)
        {
            await listener.On(notification);

            consumerMock.Verify(self => self.CommitProcessedStreamVersionAsync(false));
        }
        public async Task OnEventStreamUpdated_CreatesUpdatedStreamConsumer(
            [Frozen] Mock <INotificationListenerSubscription> subscriptionMock,
            StreamConsumingNotificationListenerStub listener,
            EventStreamUpdated notification)
        {
            await listener.On(notification);

            subscriptionMock.Verify(
                self => self.CreateSubscriptionConsumerAsync(notification.StreamName),
                Times.Once());
        }
        public async Task OnEventStreamUpdated_WhenConsumerReceiveOperationFailed_ClosesConsumer(
            [Frozen] Mock <IEventStreamConsumer> consumerMock,
            StreamConsumingNotificationListenerStub listener,
            EventStreamUpdated notification)
        {
            consumerMock
            .Setup(self => self.ReceiveEventsAsync())
            .Returns(ReceivingResultCode.PromotionFailed.YieldTask());

            await listener.On(notification);

            consumerMock.Verify(self => self.CloseAsync(), Times.Once());
        }
        public async Task OnEventStreamUpdated_WhenListenerProcessingFailed_DefersNotificationProcessing(
            [Frozen] Mock <INotificationListenerSubscription> subscriptionMock,
            [Frozen] Mock <IEventStreamConsumer> consumerMock,
            StreamConsumingNotificationListenerStub listener,
            EventStreamUpdated notification)
        {
            listener.ProcessingCompleted = false;

            await listener.On(notification);

            subscriptionMock.Verify(
                self => self.RetryNotificationProcessingAsync(notification),
                Times.Once());
        }
        public async Task OnEventStreamUpdated_WhenConsumerReceiveOperationFailed_DefersNotificationProcessing(
            [Frozen] Mock <INotificationListenerSubscription> subscriptionMock,
            [Frozen] Mock <IEventStreamConsumer> consumerMock,
            StreamConsumingNotificationListenerStub listener,
            EventStreamUpdated notification)
        {
            consumerMock
            .Setup(self => self.ReceiveEventsAsync())
            .Returns(ReceivingResultCode.PromotionFailed.YieldTask());

            await listener.On(notification);

            subscriptionMock.Verify(
                self => self.RetryNotificationProcessingAsync(notification),
                Times.Once());
        }