public async Task ProcessAsync()
        {
            // Arrange
            var job = new Job(
                InvocationData.Serialize(
                    MethodInvocation.FromExpression(() => Method())).Serialize());

            var mockFetchedJob = Mock.Get(Mock.Of <IFetchedJob>(fj => fj.JobId == 42));

            _mockStorageConnection
            .Setup(m => m.FetchNextJobAsync())
            .ReturnsAsync(mockFetchedJob.Object).Verifiable();

            _mockStorageConnection
            .Setup(m => m.GetJobAsync(42))
            .ReturnsAsync(job).Verifiable();

            var fixture = Create();

            // Act
            await fixture.ProcessAsync(_context);

            // Assert
            _mockStorageConnection.VerifyAll();
            _mockStateChanger.Verify(m => m.ChangeState(job, It.IsAny <SucceededState>(), It.IsAny <IStorageTransaction>()));
            mockFetchedJob.Verify(m => m.Requeue(), Times.Never);
            mockFetchedJob.Verify(m => m.RemoveFromQueue());
        }
        public async Task ProcessAsync_Exception()
        {
            // Arrange
            var job = new Job(
                InvocationData.Serialize(
                    MethodInvocation.FromExpression(() => Throw())).Serialize());

            var mockFetchedJob = Mock.Get(Mock.Of <IFetchedJob>(fj => fj.JobId == 42));

            _mockStorageConnection
            .Setup(m => m.FetchNextJobAsync())
            .ReturnsAsync(mockFetchedJob.Object);

            _mockStorageConnection
            .Setup(m => m.GetJobAsync(42))
            .ReturnsAsync(job);

            _mockStateChanger.Setup(m => m.ChangeState(job, It.IsAny <IState>(), It.IsAny <IStorageTransaction>()))
            .Throws <Exception>();

            var fixture = Create();

            // Act
            await fixture.ProcessAsync(_context);

            // Assert
            job.Retries.Should().Be(0);
            mockFetchedJob.Verify(m => m.Requeue());
        }
        public async Task ProcessAsync_JobThrows_WithNoRetry()
        {
            // Arrange
            var job = new Job(
                InvocationData.Serialize(
                    MethodInvocation.FromExpression <NoRetryJob>(j => j.Throw())).Serialize());

            var mockFetchedJob = Mock.Get(Mock.Of <IFetchedJob>(fj => fj.JobId == 42));

            _mockStorageConnection
            .Setup(m => m.FetchNextJobAsync())
            .ReturnsAsync(mockFetchedJob.Object);

            _mockStorageConnection
            .Setup(m => m.GetJobAsync(42))
            .ReturnsAsync(job);

            var fixture = Create();

            // Act
            await fixture.ProcessAsync(_context);

            // Assert
            _mockStateChanger.Verify(m => m.ChangeState(job, It.IsAny <FailedState>(), It.IsAny <IStorageTransaction>()));
        }