Exemplo n.º 1
0
        public async Task Schedule_NoPropertiesHaveBeenPassed_ShouldScheduleWithDefault()
        {
            // Arrange
            var builder =
                new ParameterizedJobBuilder <TestJob, string>(_jobsAdderMock.Object, "HALLO", _globalObsoleteInterval);
            var scheduledJob = new JobMetadata();

            _jobsAdderMock.Setup(a => a.AddEnqueueJob(It.IsAny <JobMetadata>()))
            .Returns(Task.CompletedTask)
            .Callback((JobMetadata job) => scheduledJob = job);

            // Act
            await builder.Schedule();

            // Assert
            Assert.Equal(scheduledJob.StartAt, DateTime.UtcNow, TimeSpan.FromMilliseconds(500));
            _jobsAdderMock.Verify(a => a.AddEnqueueJob(It.IsAny <JobMetadata>()), Times.Once);
            _jobsAdderMock.VerifyNoOtherCalls();
        }
        public async Task Schedule_SetFailedStrategy_SaveInJobMetadata()
        {
            // Arrange
            var       scheduledJob   = new JobMetadata();
            const int maxRepeatCount = 5;

            var builder =
                new ParameterizedJobBuilder <TestJob, string>(_jobsAdderMock.Object, "HALLO", _globalObsoleteInterval)
                .AddRepeatStrategy <DefaultRepeatStrategy>()
                .MaxRepeatCount(maxRepeatCount);

            _jobsAdderMock.Setup(a => a.AddEnqueueJob(It.IsAny <JobMetadata>()))
            .Returns(Task.CompletedTask)
            .Callback((JobMetadata job) => scheduledJob = job);

            // Act
            await builder.Schedule();

            // Assert
            Assert.Equal(typeof(DefaultRepeatStrategy), scheduledJob.RepeatStrategy);
            Assert.Equal(scheduledJob.MaxRepeatCount, maxRepeatCount);
            _jobsAdderMock.Verify(a => a.AddEnqueueJob(It.IsAny <JobMetadata>()), Times.Once);
            _jobsAdderMock.VerifyNoOtherCalls();
        }