public void CanBootstrapJobs() { ServiceProvider.SetServiceProvider(typeof(JobTests)); Assert.NotNull(ServiceProvider.Current); Assert.Equal(ServiceProvider.Current.GetType(), typeof(MyBootstrappedServiceProvider)); ServiceProvider.SetServiceProvider(typeof(MyBootstrappedServiceProvider)); Assert.NotNull(ServiceProvider.Current); Assert.Equal(ServiceProvider.Current.GetType(), typeof(MyBootstrappedServiceProvider)); var job = ServiceProvider.Current.GetService <WithDependencyJob>(); Assert.NotNull(job); Assert.NotNull(job.Dependency); Assert.Equal(5, job.Dependency.MyProperty); var jobInstance = JobRunner.CreateJobInstance("Foundatio.Tests.Jobs.HelloWorldJob,Foundatio.Tests"); Assert.NotNull(job); Assert.NotNull(job.Dependency); Assert.Equal(5, job.Dependency.MyProperty); jobInstance = JobRunner.CreateJobInstance("Foundatio.Tests.Jobs.HelloWorldJob,Foundatio.Tests", "Foundatio.Tests.Jobs.MyBootstrappedServiceProvider,Foundatio.Tests"); Assert.NotNull(job); Assert.NotNull(job.Dependency); Assert.Equal(5, job.Dependency.MyProperty); var result = jobInstance.Run(); Assert.Equal(true, result.IsSuccess); Assert.True(jobInstance is HelloWorldJob); }
public async Task CanRunJobs() { var job = new HelloWorldJob(); Assert.Equal(0, job.RunCount); await job.RunAsync(); Assert.Equal(1, job.RunCount); await job.RunContinuousAsync(iterationLimit : 2); Assert.Equal(3, job.RunCount); var sw = Stopwatch.StartNew(); await job.RunContinuousAsync(cancellationToken : TimeSpan.FromMilliseconds(100).ToCancellationToken()); sw.Stop(); Assert.InRange(sw.Elapsed, TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(150)); var jobInstance = JobRunner.CreateJobInstance(typeof(HelloWorldJob).AssemblyQualifiedName); Assert.NotNull(jobInstance); Assert.Equal(0, ((HelloWorldJob)jobInstance).RunCount); Assert.Equal(JobResult.Success, await jobInstance.RunAsync()); Assert.Equal(1, ((HelloWorldJob)jobInstance).RunCount); }
public async Task CanRunJobWithNoBootstrapperAsync() { var job = JobRunner.CreateJobInstance(typeof(TestJob).AssemblyQualifiedName); Assert.NotNull(job); Assert.Equal(0, TestJob.RunCount); Assert.Equal(JobResult.Success, await job.RunAsync()); Assert.Equal(1, TestJob.RunCount); }
public void CanRunJobWithBootstrapper() { var job = JobRunner.CreateJobInstance(typeof(EventPostsJob).AssemblyQualifiedName, Guid.NewGuid().ToString()); Assert.Null(job); job = JobRunner.CreateJobInstance(typeof(EventPostsJob).AssemblyQualifiedName, typeof(TestJob).AssemblyQualifiedName); Assert.Null(job); job = JobRunner.CreateJobInstance(typeof(EventPostsJob).AssemblyQualifiedName); Assert.NotNull(job); job = JobRunner.CreateJobInstance(typeof(EventPostsJob).AssemblyQualifiedName, typeof(EventPostsJob).AssemblyQualifiedName); Assert.NotNull(job); }
public void CanRunJobs() { var job = new HelloWorldJob(); Assert.Equal(0, job.RunCount); job.Run(); Assert.Equal(1, job.RunCount); job.RunContinuous(iterationLimit: 2); Assert.Equal(3, job.RunCount); job.RunContinuous(token: new CancellationTokenSource(TimeSpan.FromMilliseconds(10)).Token); Assert.True(job.RunCount > 10); var jobInstance = JobRunner.CreateJobInstance(typeof(HelloWorldJob).AssemblyQualifiedName); Assert.NotNull(jobInstance); Assert.Equal(0, ((HelloWorldJob)jobInstance).RunCount); Assert.Equal(JobResult.Success, jobInstance.Run()); Assert.Equal(1, ((HelloWorldJob)jobInstance).RunCount); }
public void CanRunJobWithBootstrapper() { var job = JobRunner.CreateJobInstance(typeof(EventPostsJob).AssemblyQualifiedName); Assert.NotNull(job); }