Exemplo n.º 1
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 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);
        }
        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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
        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);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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);
        }
        public void Should_Select_The_Date_If_The_Next_Runtime_Falls_On_The_Specified_Day()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(2).Months().OnTheLast(DayOfWeek.Friday);

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

            var expectedTime = new DateTime(2000, 3, 31);
            Assert.AreEqual(scheduledTime, expectedTime);
        }
        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().OnTheSecond(DayOfWeek.Tuesday);

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

            var expectedTime = new DateTime(2000, 3, 14);
            Assert.AreEqual(scheduledTime, expectedTime);
        }
        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);
        }
Exemplo n.º 17
0
        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);
        }
        public void Should_Pick_The_Day_Of_Week_Specified()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(2).Months().OnTheThird(DayOfWeek.Friday);

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

            var expectedTime = new DateTime(2000, 3, 17);
            Assert.AreEqual(scheduledTime, expectedTime);
        }
        public void Should_Default_To_00_00_If_On_Is_Specified_And_At_Is_Not_Defined()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(2).Weeks().On(DayOfWeek.Saturday);

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

            Assert.AreEqual(scheduledTime.Hour, 0);
            Assert.AreEqual(scheduledTime.Minute, 0);
            Assert.AreEqual(scheduledTime.Second, 0);
        }
Exemplo n.º 20
0
        public void Should_Default_To_00_00_If_At_Is_Not_Defined()
        {
            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);

            scheduledTime.Hour.Should().Equal(0);
            scheduledTime.Minute.Should().Equal(0);
            scheduledTime.Second.Should().Equal(0);
        }
Exemplo n.º 21
0
        public void Should_Add_Specified_Seconds_To_Same_Date_Within_Bounds()
        {
            var task = new Mock<ITask>();
              var schedule = new Schedule(task.Object);
              schedule.ToRunEvery(30).Seconds().Between(10, 0, 11, 0);

              var input = new DateTime(2000, 1, 1, 10, 15, 0);
              var scheduledTime = schedule.CalculateNextRun(input);
              Assert.AreEqual(scheduledTime.Date, input.Date);
              Assert.AreEqual(scheduledTime.Hour, input.Hour);
              Assert.AreEqual(scheduledTime.Minute, input.Minute);
              Assert.AreEqual(scheduledTime.Second, 30);
        }
Exemplo n.º 22
0
        public void Should_Default_To_00_00_If_At_Is_Not_Defined()
        {
            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.Hour, 0);
            Assert.AreEqual(scheduledTime.Minute, 0);
            Assert.AreEqual(scheduledTime.Second, 0);
        }
Exemplo n.º 23
0
        public void Should_Override_Existing_Minutes_And_Seconds_If_At_Method_Is_Called()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(1).Days().At(3, 15);

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

            Assert.AreEqual(scheduledTime.Hour, 3);
            Assert.AreEqual(scheduledTime.Minute, 15);
            Assert.AreEqual(scheduledTime.Second, 0);
        }
Exemplo n.º 24
0
        public void Should_Pick_Next_Date_If_Now_Is_After_At_Time()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(3).Days().At(3, 15);

            var input = new DateTime(2000, 1, 1, 3, 15, 0).AddMilliseconds(1);
            var scheduledTime = schedule.CalculateNextRun(input);
            Assert.AreEqual(scheduledTime.Date, new DateTime(2000, 1, 4));

            Assert.AreEqual(scheduledTime.Hour, 3);
            Assert.AreEqual(scheduledTime.Minute, 15);
            Assert.AreEqual(scheduledTime.Second, 0);
        }
Exemplo n.º 25
0
        public void Should_Add_Specified_Seconds_To_Next_Run_Date()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(30).Seconds();

            var input = new DateTime(2000, 1, 1);
            var scheduledTime = schedule.CalculateNextRun(input);
            scheduledTime.Date.Should().Equal(input.Date);

            scheduledTime.Hour.Should().Equal(input.Hour);
            scheduledTime.Minute.Should().Equal(input.Minute);
            scheduledTime.Second.Should().Equal(30);
        }
Exemplo n.º 26
0
        public void Should_Add_Specified_Minutes_To_Next_Run_Date_When_Is_Between_Specified_Bounds()
        {
            var task = new Mock<ITask>();
              var schedule = new Schedule(task.Object);
              schedule.ToRunEvery(30).Minutes().Between(10, 00, 16, 00);

              var input = new DateTime(2000, 1, 6, 12, 23, 25);
              var scheduledTime = schedule.CalculateNextRun(input);
              Assert.AreEqual(scheduledTime.Date, input.Date);

              scheduledTime.Hour.Should().Be(input.Hour);
              scheduledTime.Minute.Should().Be(input.Minute + 30);
              scheduledTime.Second.Should().Be(input.Second);
        }
Exemplo n.º 27
0
        public void Should_Delay_Next_Run_Date_Until_Specified_Start()
        {
            var task = new Mock<ITask>();
              var schedule = new Schedule(task.Object);
              schedule.ToRunEvery(2).Minutes().Between(10, 00, 11, 00);

              var input = new DateTime(2000, 1, 6, 1, 23, 25);
              var scheduledTime = schedule.CalculateNextRun(input);
              scheduledTime.Date.Should().Be(input.Date);

              scheduledTime.Hour.Should().Be(10);
              scheduledTime.Minute.Should().Be(0);
              scheduledTime.Second.Should().Be(0);
        }
        public void Should_Not_Schedule_Today_If_Input_Time_Is_After_Run_Time()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(2).Weeks().At(3, 15);

            var input = new DateTime(2000, 1, 1, 5, 23, 25);
            var scheduledTime = schedule.CalculateNextRun(input);
            Assert.AreEqual(scheduledTime.Date, input.Date.AddDays(14));

            Assert.AreEqual(scheduledTime.Hour, 3);
            Assert.AreEqual(scheduledTime.Minute, 15);
            Assert.AreEqual(scheduledTime.Second, 0);
        }
Exemplo n.º 29
0
        public void Should_Pick_Today_If_Now_Is_Before_At_Time()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(3).Days().At(3, 15);

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

            Assert.AreEqual(scheduledTime.Hour, 3);
            Assert.AreEqual(scheduledTime.Minute, 15);
            Assert.AreEqual(scheduledTime.Second, 0);
        }
Exemplo n.º 30
0
        public void Should_Add_Specified_Minutes_To_Next_Run_Date()
        {
            var task = new Mock<ITask>();
              var schedule = new Schedule(task.Object);
              schedule.ToRunEvery(30).Minutes();

              var input = new DateTime(2000, 1, 1);
              var scheduledTime = schedule.CalculateNextRun(input);
              Assert.AreEqual(scheduledTime.Date, input.Date);

              Assert.AreEqual(scheduledTime.Hour, input.Hour);
              Assert.AreEqual(scheduledTime.Minute, 30);
              Assert.AreEqual(scheduledTime.Second, input.Second);
        }