Exemplo n.º 1
0
        public void ShouldScheduleJobWithSimpleTriggerWhenCalledScheduleTrigger()
        {
            // Arrange
            var myTrigger = new SimpleTrigger
            {
                Name           = "TestTrigger",
                Group          = "TestGroup",
                JobName        = "TestJobName",
                JobGroup       = "TestJobGroup",
                RepeatCount    = 2,
                RepeatInterval = new TimeSpan(0, 0, 0, 1)
            };
            IJobDetail noOpJob = new JobDetailImpl("TestJobName", "TestJobGroup", typeof(NoOpJob));

            _mockScheduler.Setup(x => x.GetJobDetail(It.IsAny <JobKey>())).Returns(noOpJob);
            _mockScheduler.Setup(x => x.CheckExists(It.IsAny <JobKey>())).Returns(true);

            ISchedulerCore schedulerCore = new SchedulerCore(_mockScheduler.Object, _mockPersistanceStore.Object);

            // Act
            schedulerCore.ScheduleTrigger(myTrigger);

            // Assert
            _mockScheduler.Verify(x => x.ScheduleJob(
                                      It.Is <ISimpleTrigger>(t => t.RepeatCount == 2)), Times.Once);
        }
Exemplo n.º 2
0
        public void ShouldAddExclusionDatesToExistingHolidayCalendar()
        {
            // Arrange
            Guid         calId          = Guid.NewGuid();
            const string calName        = "TestHolCal";
            var          exclusionDate1 = new DateTime(2016, 01, 01);
            var          exclusionDate2 = new DateTime(2016, 01, 02);

            _mockPersistanceStore.Setup(m => m.GetCalendarName(calId)).Returns(calName);

            var registeredCalendar = new HolidayCalendar();

            registeredCalendar.AddExcludedDate(exclusionDate1);
            _mockScheduler.Setup(i => i.GetCalendar(calName)).Returns(registeredCalendar);

            ISchedulerCore schedulerCore = new SchedulerCore(_mockScheduler.Object, _mockPersistanceStore.Object);

            // Act
            schedulerCore.AddHolidayCalendarExclusionDates(calId, new List <DateTime> {
                exclusionDate1, exclusionDate2
            });

            // Assert
            _mockScheduler.Verify(
                x => x.AddCalendar(calName,
                                   It.Is <HolidayCalendar>(
                                       c => c.ExcludedDates.Contains(exclusionDate1) && c.ExcludedDates.Contains(exclusionDate2) &&
                                       c.ExcludedDates.Count == 2), true, true), Times.Once);
        }
Exemplo n.º 3
0
        public void ShouldSetLocalTimezoneOnCronTriggerWhenCalledScheduleTrigger()
        {
            // Arrange
            var myTrigger = new CronTrigger
            {
                Name           = "TestTrigger",
                Group          = "TestGroup",
                JobName        = "TestJobName",
                JobGroup       = "TestJobGroup",
                CronExpression = "0/30 * * * * ?"
            };
            IJobDetail noOpJob = new JobDetailImpl("TestJobName", "TestJobGroup", typeof(NoOpJob));

            _mockScheduler.Setup(x => x.GetJobDetail(It.IsAny <JobKey>())).Returns(noOpJob);
            _mockScheduler.Setup(x => x.CheckExists(It.IsAny <JobKey>())).Returns(true);

            ISchedulerCore schedulerCore = new SchedulerCore(_mockScheduler.Object, _mockPersistanceStore.Object);

            // Act
            schedulerCore.ScheduleTrigger(myTrigger);

            // Assert
            _mockScheduler.Verify(x => x.ScheduleJob(
                                      It.Is <ICronTrigger>(t => (Equals(t.TimeZone, TimeZoneInfo.Local)))), Times.Once);
        }
Exemplo n.º 4
0
        private void Form1_Load(object sender, EventArgs e)
        {
            notifyIcon.Text    = Text;
            notifyIcon.Icon    = Icon;
            notifyIcon.Visible = false;

            logger = new Logger("scheduler", "schedulerUI", true);
            logger.V("Starting application...");

            SchedulerCoreParameters parameters = new SchedulerCoreParameters()
            {
                DataChangedAction = ListChanged,
                ElapsedAction     = Elapsed,
                FileName          = MainFileName,
                Interval          = 1000,
                LibDir            = SCHEnvironment.LibDir,
                Logger            = logger,
                OnErrorAction     = OnCoreError
            };

            SchedulerCore = new SchedulerCore(parameters);

            logger.I("SchedulerCore item has been created");
            label_lastElapsed.Text = string.Format("Last updated: {0}", DateTime.Now);
            UpdateUI();
        }
Exemplo n.º 5
0
        public void ShouldDeleteTriggerInTriggerGroupWhenTriggerGroupIsSpecifiedInRemoveTrigger()
        {
            // Arrange
            _mockScheduler.Setup(x => x.CheckExists(It.IsAny <TriggerKey>())).Returns(true);


            ISchedulerCore schedulerCore = new SchedulerCore(_mockScheduler.Object);

            // Act
            schedulerCore.RemoveTrigger("TestTrigger", "Group1");

            // Assert
            _mockScheduler.Verify(x => x.UnscheduleJob(It.Is <TriggerKey>(i => i.Name == "TestTrigger")), Times.Once);
            _mockScheduler.Verify(x => x.GetTriggerGroupNames(), Times.Never);
        }
Exemplo n.º 6
0
        public void TestJobsControllerDeleteByIdWithWildcard()
        {
            // Arrange
            IPersistenceStore persistenceStore = new InMemoryStore();

            Scheduler.Shutdown();

            Scheduler.Initialize((config =>
            {
                config.EnableWebApiSelfHost = false;
                config.EnableAuditHistory = false;
                config.PersistenceStoreType = PersistenceStoreType.InMemory;
                config.AutoStart = false;
            }));

            var schedulerCore = new SchedulerCore(Scheduler.Instance(), persistenceStore);

            const string jobName  = "Job1";
            const string jobGroup = "Group1";
            var          jobId    = new Guid("30575FAE-86D3-4EC1-8E10-1E7F5EA6BBB4");

            schedulerCore.CreateJob(jobName, jobGroup, typeof(NoOpJob), new Dictionary <string, object>(), string.Empty, jobId);


            _mockPermissionsHelper.Setup(i => i.GetAuthorizedJobGroups()).Returns(new List <string> {
                "*"
            });
            var controller = new JobsController(_mockPermissionsHelper.Object, schedulerCore);

            // Act
            var jobBeforeDelete = controller.Get(jobId);

            controller.Delete(jobId);
            try
            {
                controller.Get(jobId);
            }
            catch (HttpResponseException ex)
            {
                Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode);
            }

            // Assert
            Assert.Equal(jobGroup, jobBeforeDelete.JobGroup);
            Assert.Equal(jobName, jobBeforeDelete.JobName);
        }
Exemplo n.º 7
0
        public void ShouldDeleteTriggerInDefaultTriggerGroupsWhenTriggerGroupIsNotSpecifiedInRemoveTrigger()
        {
            // Arrange
            _mockScheduler.Setup(x => x.GetTriggerGroupNames()).Returns(new List <string> {
                "DEFAULT", "Group2"
            });
            _mockScheduler.Setup(x => x.CheckExists(It.IsAny <TriggerKey>())).Returns(true);


            ISchedulerCore schedulerCore = new SchedulerCore(_mockScheduler.Object);

            // Act
            schedulerCore.RemoveTrigger("TestTrigger", "DEFAULT");

            // Assert
            _mockScheduler.Verify(x => x.UnscheduleJob(It.Is <TriggerKey>(i => i.Name == "TestTrigger" && i.Group == "DEFAULT")), Times.Exactly(1));
        }
Exemplo n.º 8
0
        public void ShouldDeleteJobInDefaultJobGroupsWhenJobGroupIsNotSpecifiedInRemoveJob()
        {
            // Arrange
            _mockScheduler.Setup(x => x.GetJobGroupNames()).Returns(new List <string> {
                "Group1", "DEFAULT"
            });
            _mockScheduler.Setup(x => x.CheckExists(It.IsAny <JobKey>())).Returns(true);


            ISchedulerCore schedulerCore = new SchedulerCore(_mockScheduler.Object);

            // Act
            schedulerCore.RemoveJob("TestJob", "DEFAULT");

            // Assert
            _mockScheduler.Verify(x => x.DeleteJob(It.Is <JobKey>(i => i.Name == "TestJob" && i.Group == "DEFAULT")), Times.Exactly(1));
        }
Exemplo n.º 9
0
        public void ShouldDeleteJobInJobGroupWhenJobGroupIsSpecifiedInRemoveJob()
        {
            // Arrange
            Guid jobId = Guid.NewGuid();

            _mockScheduler.Setup(x => x.CheckExists(It.IsAny <JobKey>())).Returns(true);
            _mockPersistanceStore.Setup(x => x.GetJobKey(jobId)).Returns(new JobKey("TestJob", "Group1"));


            ISchedulerCore schedulerCore = new SchedulerCore(_mockScheduler.Object, _mockPersistanceStore.Object);

            // Act
            schedulerCore.RemoveJob(jobId);

            // Assert
            _mockScheduler.Verify(x => x.DeleteJob(It.Is <JobKey>(i => i.Name == "TestJob")), Times.Once);
            _mockScheduler.Verify(x => x.GetJobGroupNames(), Times.Never);
        }
Exemplo n.º 10
0
        public void ShouldAmendExistingrCronCalendar()
        {
            // Arrange
            Guid         calId      = Guid.NewGuid();
            const string calName    = "TestCronCal";
            const string cronString = "0 0 12 1/1 * ? *";

            _mockPersistanceStore.Setup(m => m.GetCalendarName(calId)).Returns(calName);

            _mockScheduler.Setup(x => x.AddCalendar(calName, It.Is <CronCalendar>(c => c.CronExpression.ToString() == cronString), true, true));
            ISchedulerCore schedulerCore = new SchedulerCore(_mockScheduler.Object, _mockPersistanceStore.Object);

            // Act
            schedulerCore.AmendCronCalendar(calId, "test cal", cronString);

            // Assert
            _mockScheduler.VerifyAll();
        }
Exemplo n.º 11
0
        public void ShouldRegisterCronCalendarWithScheduler()
        {
            // Arrange
            Guid         calId      = Guid.NewGuid();
            const string calName    = "TestCronCal";
            const string cronString = "0 0 12 1/1 * ? *";

            _mockPersistanceStore.Setup(m => m.UpsertCalendarIdMap(calName)).Returns(calId);

            _mockScheduler.Setup(x => x.AddCalendar(calName, It.Is <CronCalendar>(c => c.CronExpression.ToString() == cronString), true, true));
            ISchedulerCore schedulerCore = new SchedulerCore(_mockScheduler.Object, _mockPersistanceStore.Object);

            // Act
            var result = schedulerCore.AddCronCalendar(calName, "test cal", cronString);

            // Assert
            Assert.Equal(calId, result);
            _mockScheduler.VerifyAll();
        }
Exemplo n.º 12
0
        public void ShouldRegisterHolidayCalendarWithScheduler()
        {
            // Arrange
            Guid         calId         = Guid.NewGuid();
            const string calName       = "TestHolCal";
            var          exclusionDate = new DateTime(2016, 01, 01);

            _mockPersistanceStore.Setup(m => m.UpsertCalendarIdMap(calName)).Returns(calId);

            _mockScheduler.Setup(x => x.AddCalendar(calName, It.Is <HolidayCalendar>(c => c.ExcludedDates.Contains(exclusionDate)), true, true));
            ISchedulerCore schedulerCore = new SchedulerCore(_mockScheduler.Object, _mockPersistanceStore.Object);

            // Act
            var result = schedulerCore.AddHolidayCalendar(calName, "test cal", new List <DateTime> {
                exclusionDate
            });

            // Assert
            Assert.Equal(calId, result);
            _mockScheduler.VerifyAll();
        }
Exemplo n.º 13
0
        public void TestSendEmailJobsControllerGetByIdWithJobGroupName()
        {
            // Arrange
            IPersistenceStore persistenceStore = new InMemoryStore();

            Scheduler.Shutdown();

            Scheduler.Initialize((config =>
            {
                config.EnableWebApiSelfHost = false;
                config.EnableAuditHistory = false;
                config.PersistenceStoreType = PersistenceStoreType.InMemory;
                config.AutoStart = false;
            }));

            var schedulerCore = new SchedulerCore(Scheduler.Instance(), persistenceStore);

            const string jobName  = "Job1";
            const string jobGroup = "Group1";
            var          jobId    = new Guid("30575FAE-86D3-4EC1-8E10-1E7F5EA6BBB4");

            schedulerCore.CreateJob(jobName, jobGroup, typeof(NativeJob),
                                    new Dictionary <string, object> {
                { "waitForProcess", "false" }, { "consumeStreams", "false" }
            }, string.Empty,
                                    jobId);


            _mockPermissionsHelper.Setup(i => i.GetAuthorizedJobGroups()).Returns(new List <string> {
                "Group1"
            });
            var sendEmailJobsController = new SendEmailJobsController(_mockPermissionsHelper.Object, schedulerCore);

            // Act
            var job = sendEmailJobsController.Get(jobId);

            // Assert
            Assert.Equal(jobGroup, job.JobGroup);
            Assert.Equal(jobName, job.JobName);
        }
Exemplo n.º 14
0
        public void ShouldGetJobDetailWhenCalledGetJobDetailOfTrigger()
        {
            // Arrange
            Guid     triggerId  = Guid.NewGuid();
            var      triggerKey = new TriggerKey("TestTrigger", "TestTriggerGroup");
            ITrigger trigger    = new SimpleTriggerImpl {
                JobKey = new JobKey("TestJob", "TestJobGroup")
            };

            _mockPersistanceStore.Setup(x => x.GetTriggerKey(triggerId)).Returns(triggerKey);
            _mockScheduler.Setup(x => x.GetTrigger(triggerKey)).Returns(trigger);
            _mockScheduler.Setup(i => i.GetJobDetail(trigger.JobKey)).Returns(new JobDetailImpl()
            {
                Key = trigger.JobKey, Group = "TestJobGroup"
            });

            ISchedulerCore schedulerCore = new SchedulerCore(_mockScheduler.Object, _mockPersistanceStore.Object);

            // Act
            var group = schedulerCore.GetJobDetailOfTrigger(triggerId).Key.Group;

            // Assert
            Assert.Equal("TestJobGroup", group);
        }