Exemple #1
0
        public void Constructor_LastDayOfMonthMark_NextExecutionInLastDayOfMonth()
        {
            var job        = new StubOneJob();
            var crontabKey = "StubOneJob:Crontab";

            ConfigurationManager.AppSettings[crontabKey] = "0 0 L * *";

            var target = new JobInfo(job);
            var actual = target.NextExecution;

            Assert.AreEqual(DateTime.Now.GetEndOfMonth().Day, actual.Day);
        }
Exemple #2
0
        public void Constructor_NoCrontabKey_Exception()
        {
            var job        = new StubOneJob();
            var crontabKey = "StubOneJob:Crontab";

            ConfigurationManager.AppSettings[crontabKey] = null;

            ExceptionAssert.IsThrowing(
                new ConfigurationErrorsException("The key '{0}' was not found on the app.config. Please add the crontab configuration to the job 'StubOneJob' in the app.config file and try again.".With(crontabKey)), () => {
                new JobInfo(job);
            });
        }
Exemple #3
0
        public void Constructor_InvalidCrontabExpression_Exception()
        {
            var job        = new StubOneJob();
            var crontabKey = "StubOneJob:Crontab";

            ConfigurationManager.AppSettings[crontabKey] = "X * * * *";

            bool thrown = false;

            try
            {
                new JobInfo(job);
            }
            catch (ConfigurationErrorsException ex) {
                thrown = ex.Message.StartsWith("The crontab expression define at key '{0}' on app.config file is invalid. Error:".With(crontabKey));
            }

            Assert.IsTrue(thrown, "Exception was not thrown");
        }
Exemple #4
0
        public void RefreshNextExecution_CronttabExpression_NextDateTimeExecution()
        {
            var job        = new StubOneJob();
            var crontabKey = "StubOneJob:Crontab";

            ConfigurationManager.AppSettings[crontabKey] = "* * * * *";


            var target = new JobInfo(job);
            var actual = target.NextExecution;

            target.RefreshNextExecution(DateTime.Now.AddMinutes(1));
            Assert.IsTrue(actual < target.NextExecution);

            actual = target.NextExecution;
            Assert.IsTrue(actual == target.NextExecution);

            target.RefreshNextExecution(DateTime.Now.AddMinutes(2));
            Assert.IsTrue(actual < target.NextExecution);
        }