Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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)}'.");
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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.");
        }
Exemplo n.º 6
0
        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.");
        }
Exemplo n.º 7
0
        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)}'.");
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        public CronQuerySetup Enqueue <TJob>() where TJob : IJob
        {
            runner.Enqueue <TJob>();

            return(this);
        }