示例#1
0
        private static (IScorpioTimer, IBackgroundJobStore, BackgroundJobWorker, IBackgroundJobExecuter, BackgroundJobWorkerOptions) Getclasses()
        {
            var timer      = Substitute.For <IScorpioTimer>();
            var objOptions = Substitute.For <IOptions <BackgroundJobOptions> >();

            objOptions.Configure().Value.Returns(new BackgroundJobOptions().Action(opt => opt.AddJob <FakeBackgroundJob>()));
            var workOptions = Substitute.For <IOptions <BackgroundJobWorkerOptions> >();
            var workOpt     = new BackgroundJobWorkerOptions();

            workOptions.Configure().Value.Returns(workOpt);
            var factory = Substitute.For <IServiceScopeFactory>();
            var store   = Substitute.For <IBackgroundJobStore>();

            factory.Configure().CreateScope().ServiceProvider.GetService(typeof(IBackgroundJobStore)).Returns(store);
            var executor = Substitute.For <IBackgroundJobExecuter>();

            factory.Configure().CreateScope().ServiceProvider.GetService(typeof(IBackgroundJobExecuter)).Returns(executor);
            var clock = Substitute.For <IClock>();

            clock.Configure().Now.Returns(DateTime.MinValue);
            factory.Configure().CreateScope().ServiceProvider.GetService(typeof(IClock)).Returns(clock);
            var serializer = Substitute.For <IBackgroundJobSerializer>();

            serializer.Configure().Deserialize(Arg.Any <string>(), Arg.Any <Type>()).Returns("");
            factory.Configure().CreateScope().ServiceProvider.GetService(typeof(IBackgroundJobSerializer)).Returns(serializer);
            var worker = new BackgroundJobWorker(timer, objOptions, workOptions, factory);

            return(timer, store, worker, executor, workOpt);
        }
示例#2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="timer"></param>
 /// <param name="jobOptions"></param>
 /// <param name="workerOptions"></param>
 /// <param name="serviceScopeFactory"></param>
 public BackgroundJobWorker(
     IScorpioTimer timer,
     IOptions <BackgroundJobOptions> jobOptions,
     IOptions <BackgroundJobWorkerOptions> workerOptions,
     IServiceScopeFactory serviceScopeFactory)
     : base(
         timer,
         serviceScopeFactory)
 {
     WorkerOptions = workerOptions.Value;
     JobOptions    = jobOptions.Value;
     Timer.Period  = WorkerOptions.JobPollPeriod;
 }