public async Task Start_NextJobStarted_AddsJobTaskToUncompletedTasks()
        {
            // Arrange
            var jobRepositoryMock   = new Mock <IJobRepository>();
            var uncompletedTaskList = new Mock <IUncompletedTaskList>();

            uncompletedTaskList.Setup(x => x.Add(It.IsAny <Task>()));

            jobRepositoryMock.Setup(x => x.GetReadyJob(It.IsAny <string>(), It.IsAny <TimeSpan>()))
            .ReturnsAsync(new JobDb
            {
                JobType = typeof(object).ToString(),
            });

            var runnerJobs = new RunnerJobs(jobRepositoryMock.Object,
                                            new HorariumSettings
            {
                IntervalStartJob = TimeSpan.FromHours(1),     // prevent second job from starting
            },
                                            new JsonSerializerSettings(),
                                            Mock.Of <IHorariumLogger>(),
                                            Mock.Of <IExecutorJob>(),
                                            uncompletedTaskList.Object);

            // Act
            runnerJobs.Start();
            await Task.Delay(TimeSpan.FromSeconds(5));

            await runnerJobs.Stop(CancellationToken.None);

            // Assert
            uncompletedTaskList.Verify(x => x.Add(It.IsAny <Task>()), Times.Once);
        }
        public async Task StopAsync_AwaitsWhenAllCompleted()
        {
            // Arrange
            var jobRepositoryMock   = new Mock <IJobRepository>();
            var uncompletedTaskList = new Mock <IUncompletedTaskList>();
            var cancellationToken   = new CancellationTokenSource().Token;

            var settings = new HorariumSettings
            {
                IntervalStartJob = TimeSpan.FromSeconds(2),
            };

            var runnerJobs = new RunnerJobs(jobRepositoryMock.Object,
                                            settings,
                                            new JsonSerializerSettings(),
                                            Mock.Of <IHorariumLogger>(),
                                            Mock.Of <IExecutorJob>(),
                                            uncompletedTaskList.Object);

            jobRepositoryMock.Setup(x => x.GetReadyJob(It.IsAny <string>(), It.IsAny <TimeSpan>()));

            // Act
            runnerJobs.Start();
            await Task.Delay(TimeSpan.FromSeconds(1));

            await runnerJobs.Stop(cancellationToken);

            // Assert
            uncompletedTaskList.Verify(x => x.WhenAllCompleted(cancellationToken), Times.Once);
        }
        public async Task Start_Stop()
        {
            // Arrange
            var jobRepositoryMock = new Mock <IJobRepository>();

            jobRepositoryMock.Setup(x => x.GetReadyJob(It.IsAny <string>(), It.IsAny <TimeSpan>()));

            var runnerJobs = new RunnerJobs(jobRepositoryMock.Object,
                                            new HorariumSettings(),
                                            new JsonSerializerSettings(),
                                            Mock.Of <IHorariumLogger>(),
                                            Mock.Of <IExecutorJob>(),
                                            Mock.Of <IUncompletedTaskList>());

            // Act
            runnerJobs.Start();

            await Task.Delay(TimeSpan.FromSeconds(1));

            await runnerJobs.Stop(CancellationToken.None);

            jobRepositoryMock.Invocations.Clear();

            await Task.Delay(TimeSpan.FromSeconds(1));

            // Assert
            jobRepositoryMock.Verify(x => x.GetReadyJob(It.IsAny <string>(), It.IsAny <TimeSpan>()), Times.Never);
        }