public void AddJob_ThrowArgumentException_CronExpressionIsInvalid(String cronExpression) { var serviceCollection = new ServiceCollection(); var jobsBuilder = new JobsBuilder(serviceCollection); Assert.ThrowsAny <Exception>(() => jobsBuilder.AddJob <EmptyJob1>(cronExpression)); Assert.ThrowsAny <Exception>(() => jobsBuilder.AddJob(cronExpression, () => new EmptyJob1())); Assert.ThrowsAny <Exception>(() => jobsBuilder.AddJob(cronExpression, sp => new EmptyJob1())); }
public void AddJob_CronExpressionIsValid(String cronExpression) { var serviceCollection = new ServiceCollection(); var jobsBuilder = new JobsBuilder(serviceCollection); jobsBuilder.AddJob <EmptyJob1>(cronExpression); jobsBuilder.AddJob(cronExpression, () => new EmptyJob1()); jobsBuilder.AddJob(cronExpression, sp => new EmptyJob1()); var serviceProvider = serviceCollection.BuildServiceProvider(); var options = serviceProvider.GetRequiredService <IOptions <JobsContext> >(); Assert.Equal(3, options.Value.JobItems.Count); }
public void AddJob_SameJobMultipleTimes() { var serviceCollection = new ServiceCollection(); var jobsBuilder = new JobsBuilder(serviceCollection); jobsBuilder .AddJob <EmptyJob1>("30 0 * * *") .AddJob <EmptyJob1>("30 1 * * *") .AddJob <EmptyJob1>("30 2 * * *"); var serviceProvider = serviceCollection.BuildServiceProvider(); var options = serviceProvider.GetRequiredService <IOptions <JobsContext> >(); var localDateTimeOffset = new DateTimeOffset(DateTime.Today); var jobStorageItems = options.Value.GetJobsToRun(localDateTimeOffset, localDateTimeOffset.AddHours(2)); Assert.NotEmpty(options.Value.JobItems); Assert.Equal(2, jobStorageItems.Length); }