public async Task OnPoll_WhenPendingNotificationListIsNotEmpty_ReturnsTrue(
            [Frozen] PollingJobStub jobStub,
            PendingNotificationsChaser chaser)
        {
            var pollResult = await jobStub.Poll();

            Assert.True(pollResult);
        }
        public async Task PollingFunc_WhenChannelIsEmpty_ReturnsFalse(
            [Frozen] PollingJobStub jobStub,
            NotificationHub hub)
        {
            var pollResult = await jobStub.Poll();

            Assert.False(pollResult);
        }
        public async Task OnPoll_WhenLockWasNotAcquired_ReturnsFalse(
            [Frozen] PollingJobStub jobStub,
            PendingNotificationsChaser chaser)
        {
            var pollResult = await jobStub.Poll();

            Assert.False(pollResult);
        }
        public void StoptNotificationProcessing_StopsPollingJob(
            [Frozen] PollingJobStub jobStub,
            NotificationHub hub)
        {
            hub.StopNotificationProcessing();

            Assert.False(jobStub.JobStarted);
            Assert.True(jobStub.JobStoped);
        }
        public async Task OnPoll_WhenLockWasAcquired_LoadsPendingNotifications(
            [Frozen] PollingJobStub jobStub,
            [Frozen] Mock <IPendingNotifications> pendingNotificationsMock,
            PendingNotificationsChaser chaser)
        {
            await jobStub.Poll();

            pendingNotificationsMock.Verify(self => self.LoadAsync());
        }
        public async Task OnPoll_WhenPendingNotificationListIsNotEmpty_ReleasesAcquiredLock(
            [Frozen] PollingJobStub jobStub,
            [Frozen] Mock <ICloudBlockBlob> blobLock,
            PendingNotificationsChaser chaser)
        {
            await jobStub.Poll();

            blobLock.Verify(self => self.ReleaseLeaseAsync(It.IsAny <string>()));
        }
        public void StartNotificationProcessing_StartsPollingJob(
            [Frozen] PollingJobStub jobStub,
            IEventStoreConnection connection,
            NotificationHub hub)
        {
            hub.StartNotificationProcessing(connection);

            Assert.True(jobStub.JobStarted);
            Assert.False(jobStub.JobStoped);
        }
        public void StartNotificationProcessing_WhenListenerListIsEmpty_DoesNotStartsPoller(
            [Frozen] PollingJobStub jobStub,
            IEventStoreConnection connection,
            NotificationHub hub)
        {
            hub.StartNotificationProcessing(connection);

            Assert.False(jobStub.JobStarted);
            Assert.False(jobStub.JobStoped);
        }
        public async Task PollingFunc_WhenChannelIsNotEmpty_SendsNotificationsToProcessor(
            [Frozen] Mock <INotificationListener> listenerMock,
            [Frozen] Mock <IReceivedNotificationProcessor> processorMock,
            [Frozen] PollingJobStub jobStub,
            NotificationHub hub)
        {
            await jobStub.Poll();

            processorMock.Verify(self => self.Process(
                                     It.IsAny <IReceivedNotification>()),
                                 Times.AtLeastOnce());
        }
        public async Task OnPoll_WhenPendingNotificationListIsNotEmpty_SendNotificationToTheHub(
            [Frozen] PollingJobStub jobStub,
            [Frozen] Mock <INotificationHub> hubMock,
            [Frozen] EventStreamUpdated[] pendingNotifications,
            PendingNotificationsChaser chaser)
        {
            await jobStub.Poll();

            foreach (var pendingNotification in pendingNotifications)
            {
                hubMock.Verify(self => self.NotifyAsync(pendingNotification));
            }
        }
        public async Task OnPoll_WhenExceptionHappensOnProcessing_ReturnsFalse(
            [Frozen] PollingJobStub jobStub,
            [Frozen] Mock <IPendingNotifications> pendingNotificationsMock,
            PendingNotificationsChaser chaser)
        {
            pendingNotificationsMock
            .Setup(self => self.DeleteAsync(It.IsAny <string>(), It.IsAny <StreamVersion[]>()))
            .Throws <Exception>();

            var pollResult = await jobStub.Poll();

            Assert.False(pollResult);
        }
        public async Task OnPoll_WhenExceptionHappensOnProcessing_ReleasesAcquiredLock(
            [Frozen] PollingJobStub jobStub,
            [Frozen] Mock <IPendingNotifications> pendingNotificationsMock,
            [Frozen] Mock <ICloudBlockBlob> blobLock,
            PendingNotificationsChaser chaser)
        {
            pendingNotificationsMock
            .Setup(self => self.DeleteAsync(It.IsAny <string>(), It.IsAny <StreamVersion>()))
            .Throws <Exception>();

            await jobStub.Poll();

            blobLock.Verify(self => self.ReleaseLeaseAsync(It.IsAny <string>()));
        }
        public async Task OnPoll_WhenPendingNotificationListIsNotEmpty_DeletesNotification(
            [Frozen] PollingJobStub jobStub,
            [Frozen] Mock <IPendingNotifications> pendingNotificationsMock,
            [Frozen] EventStreamUpdated[] pendingNotifications,
            PendingNotificationsChaser chaser)
        {
            await jobStub.Poll();


            foreach (var pendingNotification in pendingNotifications)
            {
                pendingNotificationsMock.Verify(self => self.DeleteAsync(
                                                    pendingNotification.StreamName,
                                                    It.Is <StreamVersion[]>(versions => versions.Contains(pendingNotification.FromVersion))));
            }
        }