public void Should_Not_Alter_Original_Runtime_If_Chained_Task_Exists()
 {
     var task = new Mock<ITask>();
     var schedule = new Schedule(task.Object);
     schedule.ToRunNow().AndEvery(1).Months();
     Assert.IsNull(schedule.CalculateNextRun);
 }
        public SecondUnit(Schedule schedule, int duration)
        {
            Schedule = schedule;
            Duration = duration;

            Schedule.CalculateNextRun = x => x.AddSeconds(Duration);
        }
        public MinuteUnit(Schedule schedule, int duration)
        {
            Schedule = schedule;
            Duration = duration;

            Schedule.CalculateNextRun = x => x.AddMinutes(Duration);
        }
 public void Should_Add_Chained_Tasks_To_AdditionalSchedules_Property()
 {
     var task = new Mock<ITask>();
     var schedule = new Schedule(task.Object);
     schedule.ToRunNow().AndEvery(1).Months();
     Assert.AreEqual(schedule.AdditionalSchedules.Count, 1);
 }
        public void Should_Be_True_By_Default()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunNow();

            schedule.Reentrant.Should().Be.True();
        }
 public MonthOnLastDayOfMonthUnit(Schedule schedule, int duration)
 {
     Schedule = schedule;
     Duration = duration;
     Schedule.CalculateNextRun = x => {
         var nextRun = x.Date.Last();
         return (x > nextRun) ? x.Date.First().AddMonths(Duration).Last() : x.Date.Last();
     };
 }
 public YearOnLastDayOfYearUnit(Schedule schedule, int duration)
 {
     Schedule = schedule;
     Duration = duration;
     Schedule.CalculateNextRun = x => {
         var nextRun = x.Date.FirstOfYear().AddMonths(11).Last();
         return (x > nextRun) ? x.Date.FirstOfYear().AddYears(Duration).AddMonths(11).Last() : nextRun;
     };
 }
Esempio n. 8
0
 public YearUnit(Schedule schedule, int duration)
 {
     Schedule = schedule;
     Duration = duration;
     Schedule.CalculateNextRun = x => {
         var nextRun = x.Date.AddYears(Duration);
         return (x > nextRun) ? nextRun.AddYears(Duration) : nextRun;
     };
 }
 public YearOnDayOfYearUnit(Schedule schedule, int duration, int dayOfYear)
 {
     Schedule = schedule;
     Duration = duration;
     DayOfYear = dayOfYear;
     Schedule.CalculateNextRun = x => {
         var nextRun = x.Date.FirstOfYear().AddDays(DayOfYear - 1);
         return (x > nextRun) ? x.Date.FirstOfYear().AddYears(Duration).AddDays(DayOfYear - 1) : nextRun;
     };
 }
Esempio n. 10
0
        public void Should_Add_Specified_Days_To_Next_Run_Date()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(1).Days();

            var input = new DateTime(2000, 1, 1, 1, 23, 25);
            var scheduledTime = schedule.CalculateNextRun(input);
            Assert.AreEqual(scheduledTime, input.Date.AddDays(1));
        }
 public MonthOnDayOfMonthUnit(Schedule schedule, int duration, int dayOfMonth)
 {
     Schedule = schedule;
     Duration = duration;
     DayOfMonth = dayOfMonth;
     Schedule.CalculateNextRun = x => {
         var nextRun = x.Date.First().AddDays(DayOfMonth - 1);
         return (x > nextRun) ? x.Date.First().AddMonths(Duration).AddDays(DayOfMonth - 1) : nextRun;
     };
 }
Esempio n. 12
0
        public void Should_Add_Specified_Months_To_Next_Run_Date_And_Select_Specified_Day()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(2).Months().On(5);

            var input = new DateTime(2000, 1, 6);
            var scheduledTime = schedule.CalculateNextRun(input);
            var expectedTime = new DateTime(2000, 3, 5);
            scheduledTime.Should().Equal(expectedTime);
        }
        public void Should_Remove_Named_Task()
        {
            var task = new Mock<ITask>();
            var name = "ShouldRemoveTask";
            var schedule = new Schedule(task.Object).WithName(name);
            schedule.ToRunNow().AndEvery(1).Seconds();
            TaskManager.RemoveTask(name);

            var taskFromManager = TaskManager.GetSchedule(name);
            Assert.IsNull(taskFromManager);
        }
Esempio n. 14
0
        public void Should_Not_Fail_If_Specified_Day_Does_Not_Exist_In_Year()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(1).Years().On(400);

            var input = new DateTime(2000, 1, 1);
            var scheduledTime = schedule.CalculateNextRun(input);
            var expectedTime = new DateTime(2001, 2, 3);
            Assert.AreEqual(scheduledTime, expectedTime);
        }
Esempio n. 15
0
        public void Should_Add_Specified_Years_To_Next_Run_Date()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(2).Years();

            var input = new DateTime(2000, 1, 1);
            var scheduledTime = schedule.CalculateNextRun(input);
            var expectedTime = new DateTime(2002, 1, 1);
            scheduledTime.Should().Equal(expectedTime);
        }
Esempio n. 16
0
        public void Should_Add_Specified_Years_To_Next_Run_Date_And_Select_Specified_Day()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(2).Years().On(5);

            var input = new DateTime(2000, 2, 15);
            var scheduledTime = schedule.CalculateNextRun(input);
            var expectedTime = new DateTime(2002, 1, 5);
            Assert.AreEqual(scheduledTime, expectedTime);
        }
Esempio n. 17
0
        public void Should_Handle_Negative_Numbers()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(2).Years().On(-1);

            var input = new DateTime(2000, 1, 1);
            var scheduledTime = schedule.CalculateNextRun(input);
            var expectedTime = new DateTime(2001, 12, 30);
            Assert.AreEqual(scheduledTime.Date, expectedTime);
        }
        public void Should_Set_Chained_Task_Schedule_As_Expected()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunNow().AndEvery(2).Months();

            var input = new DateTime(2000, 1, 1);
            var scheduledTime = schedule.AdditionalSchedules.ElementAt(0).CalculateNextRun(input);
            var expectedTime = new DateTime(2000, 3, 1);
            scheduledTime.Should().Equal(expectedTime);
        }
        public void Should_Add_Specified_Weeks_To_Next_Run_Date()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(2).Weeks();

            var input = new DateTime(2000, 1, 1);
            var scheduledTime = schedule.CalculateNextRun(input);
            var expectedTime = new DateTime(2000, 1, 15);
            Assert.AreEqual(scheduledTime, expectedTime);
        }
Esempio n. 20
0
        public void Should_Handle_Negative_Numbers()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(2).Months().On(-1);

            var input = new DateTime(2000, 1, 1, 1, 23, 25);
            var scheduledTime = schedule.CalculateNextRun(input);
            var expectedTime = new DateTime(2000, 2, 28);
            expectedTime.Should().Equal(scheduledTime.Date);
        }
        public void Should_Add_Specified_Months_To_Next_Run_Date_And_Select_Last_Day_In_That_Month()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(2).Months().OnTheLastDay();

            var input = new DateTime(2000, 1, 1);
            var scheduledTime = schedule.CalculateNextRun(input);
            var expectedTime = new DateTime(2000, 1, 31);
            Assert.AreEqual(scheduledTime, expectedTime);
        }
Esempio n. 22
0
 public HourUnit(Schedule schedule, int duration)
 {
     Schedule = schedule;
     Duration = duration;
     if (Duration < 1)
         Duration = 1;
     Schedule.CalculateNextRun = x => {
         var nextRun = x.AddHours(Duration);
         return (x > nextRun) ? nextRun.AddHours(Duration) : nextRun;
     };
 }
        public void Should_Add_Specified_Years_To_Next_Run_Date_And_Select_Last_Day_In_That_Year()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(2).Years().OnTheLastDay();

            var input = new DateTime(2000, 1, 1);
            var scheduledTime = schedule.CalculateNextRun(input);
            var expectedTime = new DateTime(2000, 12, 31);
            scheduledTime.Should().Equal(expectedTime);
        }
Esempio n. 24
0
 public WeekUnit(Schedule schedule, int duration)
 {
     Schedule = schedule;
     Duration = duration;
     if (Duration < 0)
         Duration = 0;
     Schedule.CalculateNextRun = x => {
         var nextRun = x.Date.AddDays(Duration * 7);
         return (x > nextRun) ? nextRun.AddDays(Math.Max(Duration, 1) * 7) : nextRun;
     };
 }
Esempio n. 25
0
        public void Should_Not_Fail_If_Specified_Day_Does_Not_Exist_In_Month()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(1).Months().On(31);

            var input = new DateTime(2000, 2, 1, 1, 23, 25);
            var scheduledTime = schedule.CalculateNextRun(input);
            var expectedTime = new DateTime(2000, 3, 2);
            scheduledTime.Should().Equal(expectedTime);
        }
Esempio n. 26
0
        public void Should_Be_True_By_Default()
        {
            // Arrange
            var task = new Mock<ITask>();

            // Act
            var schedule = new Schedule(task.Object);
            schedule.ToRunNow();

            // Assert
            Assert.IsTrue(schedule.Reentrant);
        }
        public void Should_Pick_The_Next_Week_If_The_Day_Of_Week_Has_Passed()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(2).Months().OnTheFourth(DayOfWeek.Tuesday);

            var input = new DateTime(2000, 1, 31);
            var scheduledTime = schedule.CalculateNextRun(input);

            var expectedTime = new DateTime(2000, 3, 28);
            scheduledTime.Should().Equal(expectedTime);
        }
        public void Should_Ignore_The_Specified_Day()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(2).Months().OnTheFourth(DayOfWeek.Wednesday);

            var input = new DateTime(2000, 3, 23);
            var scheduledTime = schedule.CalculateNextRun(input);

            var expectedTime = new DateTime(2000, 5, 24);
            scheduledTime.Should().Equal(expectedTime);
        }
        public void Should_Pick_The_Day_Of_Week_Specified()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(2).Months().OnTheFirst(DayOfWeek.Friday);

            var input = new DateTime(2000, 1, 14);
            var scheduledTime = schedule.CalculateNextRun(input);

            var expectedTime = new DateTime(2000, 3, 3);
            scheduledTime.Should().Equal(expectedTime);
        }
        public void Should_Ignore_The_Specified_Day()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(2).Months().OnTheFirst(DayOfWeek.Thursday);

            var input = new DateTime(2000, 1, 25);
            var scheduledTime = schedule.CalculateNextRun(input);

            var expectedTime = new DateTime(2000, 3, 2);
            Assert.AreEqual(scheduledTime, expectedTime);
        }
Esempio n. 31
0
        static void MiscTests()
        {
            TaskManager.TaskFactory = new MyTaskFactory();
            TaskManager.TaskStart  += (schedule, e) => Console.WriteLine(schedule.Name + " Started: " + schedule.StartTime);
            TaskManager.TaskEnd    += (schedule, e) => Console.WriteLine(schedule.Name + " Ended.\n\tStarted: " + schedule.StartTime + "\n\tDuration: " + schedule.Duration + "\n\tNext run: " + schedule.NextRunTime);

            TaskManager.Initialize(new MyRegistry());
            Console.WriteLine("Done initializing...");

            // try to get the named schedule registered inside MyRegistry
            FluentScheduler.Model.Schedule named = TaskManager.GetSchedule("named task");
            if (named != null)
            {
                // success, execute it manually
                named.Execute();
            }

            FluentScheduler.Model.Schedule removable = TaskManager.GetSchedule("removable task");
            if (removable != null)
            {
                Console.WriteLine("before remove");
                TaskManager.RemoveTask(removable.Name);
                Console.WriteLine("after remove");
            }

            FluentScheduler.Model.Schedule longRemovable = TaskManager.GetSchedule("long removable task");
            if (longRemovable != null)
            {
                Console.WriteLine("before remove long running");
                TaskManager.RemoveTask(longRemovable.Name);
                Console.WriteLine("after remove long running");
            }

            //Thread.Sleep(10000);
            //TaskManager.Stop();

            /*			TaskManager.AddTask(() => Console.WriteLine("Inline task: " + DateTime.Now), x => x.ToRunEvery(15).Seconds());
             *                      TaskManager.AddTask(() => Console.WriteLine("Inline task (once): " + DateTime.Now), x => x.ToRunOnceAt(DateTime.Now.AddSeconds(5)));
             *
             *                      TaskManager.AddTask<MyInlineTask>(x => x.ToRunNow());
             */
            TaskManager.UnobservedTaskException += TaskManager_UnobservedTaskException;

            /*			TaskManager.AddTask(() => {
             *                                                                              Console.WriteLine("Inline task: " + DateTime.Now);
             *                              throw new Exception("Hi"); }, x => x.ToRunNow());
             */
        }