예제 #1
0
        public async Task It_should_start_the_scheduler()
        {
            await sut.StartAsync(new CancellationToken());

            _schedulerMock.Verify(x => x.ScheduleJob(It.IsAny <IJobDetail>(), It.IsAny <ITrigger>(), It.IsAny <CancellationToken>()), Times.AtLeastOnce);
            _schedulerMock.Verify(x => x.Start(It.IsAny <CancellationToken>()), Times.AtLeastOnce());
        }
        public async void IServiceCollectionExtensions_Register_RegisterJob_ITrigger()
        {
            // Registered jobas
            var scheduleJobc = new List <IScheduleJob>();
            var jobDetail1   = A.Fake <IJobDetail>();

            var trigger1 = A.Fake <ITrigger>();
            var trigger2 = A.Fake <ITrigger>();
            var trigger3 = A.Fake <ITrigger>();

            scheduleJobc.Add(new ScheduleJob(jobDetail1, new List <ITrigger>()
            {
                trigger1, trigger2, trigger3
            }));

            IServiceProvider serviceProvider = A.Fake <IServiceProvider>();

            A.CallTo(() => serviceProvider.GetService(typeof(IEnumerable <IScheduleJob>))).Returns(scheduleJobc);


            ISchedulerFactory schedulerFactory = A.Fake <ISchedulerFactory>();
            IScheduler        scheduler        = A.Fake <IScheduler>();

            A.CallTo(() => schedulerFactory.GetScheduler(A <CancellationToken> .Ignored))
            .Returns(Task.FromResult(scheduler));

            IJobFactory jobFactory = A.Fake <IJobFactory>();

            var testClass = new QuartzHostedService(serviceProvider, schedulerFactory, jobFactory);
            await testClass.StartAsync(CancellationToken.None);

            A.CallTo(
                () => scheduler.ScheduleJob(
                    A <IJobDetail> .That.Matches(jd => jd == jobDetail1),
                    A <ITrigger> .That.Matches(t => t == trigger1),
                    A <CancellationToken> .Ignored))
            .MustHaveHappened(1, Times.Exactly);

            A.CallTo(
                () => scheduler.ScheduleJob(
                    A <ITrigger> .That.Matches(t => t == trigger2 || t == trigger3),
                    A <CancellationToken> .Ignored))
            .MustHaveHappened(2, Times.Exactly);
        }
        public async void IServiceCollectionExtensions_Register_RegisterJob()
        {
            // Зарегистрированные джобы
            var scheduleJobc = new List <IScheduleJob>();
            var jobDetail1   = A.Fake <IJobDetail>();
            var jobDetail2   = A.Fake <IJobDetail>();
            var jobDetail3   = A.Fake <IJobDetail>();

            scheduleJobc.Add(new ScheduleJob(jobDetail1, new List <ITrigger>()
            {
                A.Fake <ITrigger>()
            }));
            scheduleJobc.Add(new ScheduleJob(jobDetail2, new List <ITrigger>()
            {
                A.Fake <ITrigger>()
            }));
            scheduleJobc.Add(new ScheduleJob(jobDetail3, new List <ITrigger>()
            {
                A.Fake <ITrigger>()
            }));

            IServiceProvider serviceProvider = A.Fake <IServiceProvider>();

            A.CallTo(() => serviceProvider.GetService(typeof(IEnumerable <IScheduleJob>))).Returns(scheduleJobc);


            ISchedulerFactory schedulerFactory = A.Fake <ISchedulerFactory>();
            IScheduler        scheduler        = A.Fake <IScheduler>();

            A.CallTo(() => schedulerFactory.GetScheduler(A <CancellationToken> .Ignored))
            .Returns(Task.FromResult(scheduler));

            IJobFactory jobFactory = A.Fake <IJobFactory>();

            var testClass = new QuartzHostedService(serviceProvider, schedulerFactory, jobFactory);
            await testClass.StartAsync(CancellationToken.None);

            A.CallTo(
                () => scheduler.ScheduleJob(
                    A <IJobDetail> .That.Matches(jd => jd == jobDetail1 || jd == jobDetail2 || jd == jobDetail3),
                    A <ITrigger> .Ignored,
                    A <CancellationToken> .Ignored))
            .MustHaveHappened(Repeated.Like(count => count == 3));
        }
        public async void IServiceCollectionExtensions_Register_HostedService()
        {
            IServiceProvider serviceProvider = A.Fake <IServiceProvider>();

            A.CallTo(() => serviceProvider.GetService(typeof(IEnumerable <IScheduleJob>))).Returns(null);

            ISchedulerFactory schedulerFactory = A.Fake <ISchedulerFactory>();
            IScheduler        scheduler        = A.Fake <IScheduler>();

            A.CallTo(() => schedulerFactory.GetScheduler(A <CancellationToken> .Ignored))
            .Returns(Task.FromResult(scheduler));

            IJobFactory jobFactory = A.Fake <IJobFactory>();

            var testClass = new QuartzHostedService(serviceProvider, schedulerFactory, jobFactory);
            await testClass.StartAsync(CancellationToken.None);

            A.CallTo(scheduler)
            .Where(a => a.Method.Name.Equals("set_JobFactory"));
        }
예제 #5
0
파일: Program.cs 프로젝트: Dimo99/Auto
        static async Task Main()
        {
            ILogger            logger            = GetLogger();
            IServiceCollection serviceCollection = ConfigureServices(logger);
            ServiceProvider    serviceProvider   = serviceCollection.BuildServiceProvider();

            LoadBrands(serviceProvider);
            LoadModels(serviceProvider);
            LoadCars(serviceProvider);

            SeedDb(serviceProvider);

            CollectData collectData = serviceProvider.GetService <CollectData>();

            collectData.SaveAllBrands(serviceProvider);
            collectData.SaveAllModels(serviceProvider);

            QuartzHostedService quartz = serviceProvider.GetService <QuartzHostedService>();

            await quartz.StartAsync(new CancellationToken());

            Thread.Sleep(1000000000);
        }
예제 #6
0
 /// <summary>
 /// 開啟排程器
 /// </summary>
 public async Task StartScheduler()
 {
     await _quartzHostedService.StartAsync(_quartzHostedService.CancellationToken);
 }