public async Task ShouldRunJobManually() { var optionsMonitor = new OptionsMonitorFake(JobSuccessful.Options); var serviceProvider = new ServiceProviderFake(); var loggerFactory = new LoggerFactoryFake(); var jobRunner = new JobRunner(optionsMonitor, serviceProvider, loggerFactory); jobRunner.Enqueue <JobSuccessful>(); await jobRunner.RunAsync(typeof(JobSuccessful)); Assert.True(serviceProvider.GetService <JobSuccessful>().Executed); }
public void ShouldLogJobNotConfigured() { var optionsMonitor = new OptionsMonitorFake(JobNotConfigured.Options); var serviceProvider = new ServiceProviderFake(); var loggerFactory = new LoggerFactoryFake(); var jobRunner = new JobRunner(optionsMonitor, serviceProvider, loggerFactory); jobRunner.Enqueue <JobNotConfigured>(); jobRunner.Start(); Assert.Contains(loggerFactory.Logger.Messages, message => message == $"No job configuration matches '{nameof(JobNotConfigured)}'."); }
public void ShouldNotRunStoppedJob() { var optionsMonitor = new OptionsMonitorFake(JobStopped.Options); var serviceProvider = new ServiceProviderFake(); var loggerFactory = new LoggerFactoryFake(); var jobRunner = new JobRunner(optionsMonitor, serviceProvider, loggerFactory); jobRunner.Enqueue <JobStopped>(); jobRunner.Start(); Task.Delay(1500).GetAwaiter().GetResult(); // Waiting for the job Assert.False(serviceProvider.GetService <JobStopped>().Executed); }
public void ShouldRunJobSuccessfully() { var optionsMonitor = new OptionsMonitorFake(JobSuccessful.Options); var serviceProvider = new ServiceProviderFake(); var loggerFactory = new LoggerFactoryFake(); var jobRunner = new JobRunner(optionsMonitor, serviceProvider, loggerFactory); jobRunner.Enqueue <JobSuccessful>(); jobRunner.Start(); Task.Delay(1500).GetAwaiter().GetResult(); // Waiting for the job Assert.True(serviceProvider.GetService <JobSuccessful>().Executed); }
public async Task ShouldLogJobFailAfterRunManually() { var optionsMonitor = new OptionsMonitorFake(JobWithError.Options); var serviceProvider = new ServiceProviderFake(); var loggerFactory = new LoggerFactoryFake(); var jobRunner = new JobRunner(optionsMonitor, serviceProvider, loggerFactory); jobRunner.Enqueue <JobWithError>(); await jobRunner.RunAsync(typeof(JobWithError)); Assert.Contains(loggerFactory.Logger.Messages, message => message == $"Job '{nameof(JobWithError)}' failed during running."); }
public void ShouldLogJobFail() { var optionsMonitor = new OptionsMonitorFake(JobWithError.Options); var serviceProvider = new ServiceProviderFake(); var loggerFactory = new LoggerFactoryFake(); var jobRunner = new JobRunner(optionsMonitor, serviceProvider, loggerFactory); jobRunner.Enqueue <JobWithError>(); jobRunner.Start(); Task.Delay(1500).GetAwaiter().GetResult(); // Waiting for the job Assert.Contains(loggerFactory.Logger.Messages, message => message == $"Job '{nameof(JobWithError)}' failed during running."); }
public void ShouldLogWhenCronIsInvalid() { var optionsMonitor = new OptionsMonitorFake(JobBadlyConfigured.Options); var serviceProvider = new ServiceProviderFake(); var loggerFactory = new LoggerFactoryFake(); var jobRunner = new JobRunner(optionsMonitor, serviceProvider, loggerFactory); jobRunner.Enqueue <JobBadlyConfigured>(); jobRunner.Start(); Task.Delay(1500).GetAwaiter().GetResult(); // Waiting for the job Assert.Contains(loggerFactory.Logger.Messages, message => message == $"Invalid cron expression for '{nameof(JobBadlyConfigured)}'."); }
public void ShouldAssumeNewConfigurationImmediately() { var optionsMonitor = new OptionsMonitorFake(JobSuccessful.Options); var serviceProvider = new ServiceProviderFake(); var loggerFactory = new LoggerFactoryFake(); var jobRunner = new JobRunner(optionsMonitor, serviceProvider, loggerFactory); jobRunner.Enqueue <JobSuccessful>(); jobRunner.Start(); optionsMonitor.Change(options => options.Running = false); Task.Delay(1500).GetAwaiter().GetResult(); // Waiting for the job Assert.False(serviceProvider.GetService <JobSuccessful>().Executed); }
public CronQuerySetup Enqueue <TJob>() where TJob : IJob { runner.Enqueue <TJob>(); return(this); }