public void TestControllerJSONGenerationForMonth()
        {
            //Arrange
            MonthlySchedule item = new MonthlySchedule
            {
                RecurrenceType                = MonthlySchedule.RecurrenceTypeEnum.Monthly,
                MonthlyTheNDaySelected        = true,
                MonthlyTheNOccurrence         = MonthlySchedule.MonthlyTheNOccurrenceEnum.Last,
                MonthlyTheNDayOfWeek          = DayOfWeek.Friday,
                MonthlyTheNDayDayMonth        = 1,
                RecurrenceStartDate           = new System.DateTime(2019, 1, 25),
                RecurrenceEndAfterNSelected   = true,
                RecurrenceEndAfterNOccurences = 100
            };
            ScheduleItem scheduleItem = new ScheduleItem
            {
                MonthlySchedule = item
            };
            ScheduleItemController controller = new ScheduleItemController();

            //Act
            item.ProcessFutureDates();
            string       json          = controller.CreateJSON(scheduleItem);
            ScheduleItem processedItem = controller.ProcessJSON(json);

            //Assert
            Assert.IsTrue(json != null);
            Assert.AreEqual(processedItem.ScheduleItemType, "Monthly");
            Assert.IsTrue(processedItem.DailySchedule == null);
            Assert.IsTrue(processedItem.WeeklySchedule == null);
            Assert.IsTrue(processedItem.MonthlySchedule != null);
            Assert.IsTrue(processedItem.YearlySchedule == null);
        }
        public void TestControllerJSONGenerationForMultipleSchedules()
        {
            try
            {
                //Arrange
                MonthlySchedule item = new MonthlySchedule
                {
                    RecurrenceType                = MonthlySchedule.RecurrenceTypeEnum.Monthly,
                    MonthlyTheNDaySelected        = true,
                    MonthlyTheNOccurrence         = MonthlySchedule.MonthlyTheNOccurrenceEnum.Last,
                    MonthlyTheNDayOfWeek          = DayOfWeek.Friday,
                    MonthlyTheNDayDayMonth        = 1,
                    RecurrenceStartDate           = new System.DateTime(2019, 1, 25),
                    RecurrenceEndAfterNSelected   = true,
                    RecurrenceEndAfterNOccurences = 100
                };
                YearlySchedule item2 = new YearlySchedule
                {
                    RecurrenceType                = YearlySchedule.RecurrenceTypeEnum.Yearly,
                    YearlyEveryNYearsSelected     = true,
                    YearlyEveryNYears             = 1,
                    RecurrenceStartDate           = DateTime.Now,
                    RecurrenceEndAfterNSelected   = true,
                    RecurrenceEndAfterNOccurences = 10
                };
                ScheduleItem scheduleItem = new ScheduleItem
                {
                    MonthlySchedule = item,
                    YearlySchedule  = item2
                };
                ScheduleItemController controller = new ScheduleItemController();

                //Act
                item.ProcessFutureDates();
                string json = controller.CreateJSON(scheduleItem);
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.InnerException.Message == "object has multiple types and cannot be processed");
            }
        }
Exemplo n.º 3
0
        public void TestEvery22ndDayFor3Months()
        {
            //Arrange
            MonthlySchedule item = new MonthlySchedule
            {
                RecurrenceType = MonthlySchedule.RecurrenceTypeEnum.Monthly,
                MonthlyEveryNMonthsSelected   = true,
                MonthlyDayOfMonth             = 22,
                MonthlyEveryNMonths           = 3,
                RecurrenceStartDate           = new System.DateTime(2019, 1, 22),
                RecurrenceEndAfterNSelected   = true,
                RecurrenceEndAfterNOccurences = 10
            };
            DateTime lastDate = item.NormalizeDate(item.RecurrenceStartDate.AddMonths(item.MonthlyEveryNMonths * item.RecurrenceEndAfterNOccurences - item.MonthlyEveryNMonths));

            //Act
            item.ProcessFutureDates();

            //Assert
            Assert.AreEqual(item.Name, "Monthly on the " + item.MonthlyDayOfMonth + " day of the month every " + item.MonthlyEveryNMonths + " months for a total of " + item.RecurrenceEndAfterNOccurences + " FutureDates");
            DateTime[] dates = item.FutureDates.ToArray();
            Assert.AreEqual(lastDate, dates[dates.Length - 1]);
        }
Exemplo n.º 4
0
        public void TestEveryLastFridayFor3Months()
        {
            //Arrange
            MonthlySchedule item = new MonthlySchedule
            {
                RecurrenceType                = MonthlySchedule.RecurrenceTypeEnum.Monthly,
                MonthlyTheNDaySelected        = true,
                MonthlyTheNOccurrence         = MonthlySchedule.MonthlyTheNOccurrenceEnum.Last,
                MonthlyTheNDayOfWeek          = DayOfWeek.Friday,
                MonthlyTheNDayDayMonth        = 1,
                RecurrenceStartDate           = new System.DateTime(2019, 1, 25),
                RecurrenceEndAfterNSelected   = true,
                RecurrenceEndAfterNOccurences = 3
            };
            DateTime lastDate = item.NormalizeDate(new DateTime(2019, 3, 29)); //item.NormalizeDate(item.RecurrenceStartDate.AddMonths(item.MonthlyEveryNMonths * item.RecurrenceEndAfterNOccurences - item.MonthlyEveryNMonths));

            //Act
            item.ProcessFutureDates();

            //Assert
            Assert.AreEqual(item.Name, "Monthly the " + item.GetMonthlyTheNOccurrenceText() + " " + item.GetMonthlyTheNDayOfWeekText() + " of every " + item.MonthlyTheNDayDayMonth + " months for a total of " + item.RecurrenceEndAfterNOccurences + " FutureDates");
            DateTime[] dates = item.FutureDates.ToArray();
            Assert.AreEqual(lastDate, dates[dates.Length - 1]);
        }