public void TestControllerJSONGenerationForYear()
        {
            //Arrange
            int            numberOfRecurrences = 10;
            YearlySchedule item = new YearlySchedule
            {
                RecurrenceType                = YearlySchedule.RecurrenceTypeEnum.Yearly,
                YearlyEveryNYearsSelected     = true,
                YearlyEveryNYears             = 1,
                RecurrenceStartDate           = DateTime.Now,
                RecurrenceEndAfterNSelected   = true,
                RecurrenceEndAfterNOccurences = numberOfRecurrences
            };
            ScheduleItem scheduleItem = new ScheduleItem
            {
                YearlySchedule = 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, "Yearly");
            Assert.IsTrue(processedItem.DailySchedule == null);
            Assert.IsTrue(processedItem.WeeklySchedule == null);
            Assert.IsTrue(processedItem.MonthlySchedule == null);
            Assert.IsTrue(processedItem.YearlySchedule != null);
        }
        public void Occurrences_before_start()
        {
            // 3/11/1983, 3/11/1990, 3/11/1997, 3/11/2004, 3/11/2011, 3/11/2018, 3/11/2026
            YearlySchedule year = new YearlySchedule { Frequency = 7 };
            IList<DateTime> occurrences = Convert(year.GetOccurrences(_start, new DateTime(1900, 1, 1), new DateTime(1950, 1, 1)));

            Assert.AreEqual(0, occurrences.Count);
        }
        public void Occurrences_crossing_start()
        {
            // 3/11/1983, 3/11/1990, 3/11/1997, 3/11/2004, 3/11/2011, 3/11/2018, 3/11/2026
            YearlySchedule year = new YearlySchedule { Frequency = 7 };
            IList<DateTime> occurrences = Convert(year.GetOccurrences(_start, new DateTime(1970, 1, 1), new DateTime(1990, 11, 3)));

            Assert.AreEqual(2, occurrences.Count);
            Assert.AreEqual(new DateTime(1983, 11, 3), occurrences[0]);
            Assert.AreEqual(new DateTime(1990, 11, 3), occurrences[1]);
        }
        public void Occurrences_before_start()
        {
            // 3/11/1983, 3/11/1990, 3/11/1997, 3/11/2004, 3/11/2011, 3/11/2018, 3/11/2026
            YearlySchedule year = new YearlySchedule {
                Frequency = 7
            };
            IList <DateTime> occurrences = Convert(year.GetOccurrences(_start, new DateTime(1900, 1, 1), new DateTime(1950, 1, 1)));

            Assert.AreEqual(0, occurrences.Count);
        }
        public void Occurrences_stress_test()
        {
            var d = new DateTime(900, 1, 1);
            YearlySchedule year = new YearlySchedule { Frequency = 1 };

            // 1/1/1900 (Monday) -> 31/12/1999 (Friday) = 36524 total days; 7 days in every 21 for 100 years; 36524 - 14 days = 36510 / 3 = 12170
            IList<DateTime> occurrences = Convert(year.GetOccurrences(d, d, new DateTime(2899, 12, 31)));

            Assert.AreEqual(2000, occurrences.Count);
        }
        public void Next_occurrence_during_period()
        {
            // 3/11/1983, 3/11/1990, 3/11/1997, 3/11/2004, 3/11/2011, 3/11/2018, 3/11/2026
            YearlySchedule year = new YearlySchedule {
                Frequency = 7
            };
            DateTime?next = year.NextOccurrence(_start, new DateTime(1995, 1, 1));

            Assert.IsTrue(next.HasValue);
            Assert.AreEqual(new DateTime(1997, 11, 3), next.Value);
        }
        public void Occurrences_within_period()
        {
            // 3/11/1983, 3/11/1990, 3/11/1997, 3/11/2004, 3/11/2011, 3/11/2018, 3/11/2026
            YearlySchedule year = new YearlySchedule { Frequency = 7 };
            IList<DateTime> occurrences = Convert(year.GetOccurrences(_start, new DateTime(1985, 3, 1), new DateTime(2005, 1, 1)));

            Assert.AreEqual(3, occurrences.Count);
            Assert.AreEqual(new DateTime(1990, 11, 3), occurrences[0]);
            Assert.AreEqual(new DateTime(1997, 11, 3), occurrences[1]);
            Assert.AreEqual(new DateTime(2004, 11, 3), occurrences[2]);
        }
        public void Occurrences_stress_test()
        {
            var            d    = new DateTime(900, 1, 1);
            YearlySchedule year = new YearlySchedule {
                Frequency = 1
            };

            // 1/1/1900 (Monday) -> 31/12/1999 (Friday) = 36524 total days; 7 days in every 21 for 100 years; 36524 - 14 days = 36510 / 3 = 12170
            IList <DateTime> occurrences = Convert(year.GetOccurrences(d, d, new DateTime(2899, 12, 31)));

            Assert.AreEqual(2000, occurrences.Count);
        }
        public void Occurrences_crossing_start()
        {
            // 3/11/1983, 3/11/1990, 3/11/1997, 3/11/2004, 3/11/2011, 3/11/2018, 3/11/2026
            YearlySchedule year = new YearlySchedule {
                Frequency = 7
            };
            IList <DateTime> occurrences = Convert(year.GetOccurrences(_start, new DateTime(1970, 1, 1), new DateTime(1990, 11, 3)));

            Assert.AreEqual(2, occurrences.Count);
            Assert.AreEqual(new DateTime(1983, 11, 3), occurrences[0]);
            Assert.AreEqual(new DateTime(1990, 11, 3), occurrences[1]);
        }
Exemplo n.º 10
0
 public override string ToString()
 {
     return(string.Format("IsDailyScheduleEnabled:{0}, IsWeeklyScheduleEnabled:{1}, " +
                          "IsMonthlyScheduleEnabled:{2}, IsYearlyScheduleEnabled:{3}" +
                          "DailySchedule: {4}, WeeklySchedule: {5}, MonthlySchedule:{6}, YearlySchedule:{7}",
                          IsDailyScheduleEnabled, IsWeeklyScheduleEnabled,
                          IsMonthlyScheduleEnabled, IsYearlyScheduleEnabled,
                          DailySchedule == null ? "NULL" : DailySchedule.ToString(),
                          WeeklySchedule == null ? "NULL" : WeeklySchedule.ToString(),
                          MonthlySchedule == null ? "NULL" : MonthlySchedule.ToString(),
                          YearlySchedule == null ? "NULL" : YearlySchedule.ToString()));
 }
        public void Occurrences_with_time()
        {
            // 3/11/1983, 3/11/1990, 3/11/1997, 3/11/2004, 3/11/2011, 3/11/2018, 3/11/2026
            YearlySchedule year = new YearlySchedule { Frequency = 7 };
            IList<DateTime> occurrences = Convert(year.GetOccurrences(
                new DateTime(1983, 11, 3, 18, 0, 0),
                new DateTime(2004, 11, 3, 14, 0, 0),
                new DateTime(2015, 12, 31)));

            Assert.AreEqual(2, occurrences.Count);
            Assert.AreEqual(new DateTime(2004, 11, 3, 18, 0, 0), occurrences[0]);
            Assert.AreEqual(new DateTime(2011, 11, 3, 18, 0, 0), occurrences[1]);
        }
        public void Occurrences_within_period()
        {
            // 3/11/1983, 3/11/1990, 3/11/1997, 3/11/2004, 3/11/2011, 3/11/2018, 3/11/2026
            YearlySchedule year = new YearlySchedule {
                Frequency = 7
            };
            IList <DateTime> occurrences = Convert(year.GetOccurrences(_start, new DateTime(1985, 3, 1), new DateTime(2005, 1, 1)));

            Assert.AreEqual(3, occurrences.Count);
            Assert.AreEqual(new DateTime(1990, 11, 3), occurrences[0]);
            Assert.AreEqual(new DateTime(1997, 11, 3), occurrences[1]);
            Assert.AreEqual(new DateTime(2004, 11, 3), occurrences[2]);
        }
        public void Occurrences_with_time()
        {
            // 3/11/1983, 3/11/1990, 3/11/1997, 3/11/2004, 3/11/2011, 3/11/2018, 3/11/2026
            YearlySchedule year = new YearlySchedule {
                Frequency = 7
            };
            IList <DateTime> occurrences = Convert(year.GetOccurrences(
                                                       new DateTime(1983, 11, 3, 18, 0, 0),
                                                       new DateTime(2004, 11, 3, 14, 0, 0),
                                                       new DateTime(2015, 12, 31)));

            Assert.AreEqual(2, occurrences.Count);
            Assert.AreEqual(new DateTime(2004, 11, 3, 18, 0, 0), occurrences[0]);
            Assert.AreEqual(new DateTime(2011, 11, 3, 18, 0, 0), occurrences[1]);
        }
        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.º 15
0
        private ISchedule Generate(SqlDataReader reader)
        {
            ISchedule result;

            if (!IsDBNull(reader, "sd.Id"))
            {
                result = new DailySchedule();
            }
            else if (!IsDBNull(reader, "sw.Id"))
            {
                var week = new WeeklySchedule();
                week.Monday    = GetBoolean(reader, "Monday");
                week.Tuesday   = GetBoolean(reader, "Tuesday");
                week.Wednesday = GetBoolean(reader, "Wednesday");
                week.Thursday  = GetBoolean(reader, "Thursday");
                week.Friday    = GetBoolean(reader, "Friday");
                week.Saturday  = GetBoolean(reader, "Saturday");
                week.Sunday    = GetBoolean(reader, "Sunday");
                result         = week;
            }
            else if (!IsDBNull(reader, "sm.Id"))
            {
                result = new MonthlySchedule();
            }
            else if (!IsDBNull(reader, "smd.Id"))
            {
                result = new MonthlyDaySchedule();
            }
            else if (!IsDBNull(reader, "sy.Id"))
            {
                result = new YearlySchedule();
            }
            else
            {
                return(null);
            }

            result.Frequency = GetInt32(reader, "Frequency");
            return(result);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Gets the generated description for the schedule.  Will not update Description or fire events.
        /// </summary>
        public virtual string Format(YearlySchedule s)
        {
            // Annually on April 12
            // Every 2 years on April 12
            var sb = new StringBuilder();

            if (s.Frequency == 1)
            {
                sb.Append("Annually");
            }
            else
            {
                sb.AppendFormat("Every {0} years", s.Frequency);
            }

            if (Start.HasValue)
            {
                sb.AppendFormat(" on {0}", Start.Value.ToString("MMMM d"));
            }

            return(sb.ToString());
            //(EndDate.HasValue ? String.Format(", ending {0}", EndDate.Value.ToString("d MMMM yyyy")) : ""));
        }
        public void TestEveryOneDayInThreeYearForFiveOccurences()
        {
            //Arrange
            int            numberOfRecurrences = 5;
            YearlySchedule item = new YearlySchedule
            {
                RecurrenceType                = YearlySchedule.RecurrenceTypeEnum.Yearly,
                YearlyEveryNYearsSelected     = true,
                YearlyEveryNYears             = 5,
                RecurrenceStartDate           = DateTime.Now,
                RecurrenceEndAfterNSelected   = true,
                RecurrenceEndAfterNOccurences = numberOfRecurrences
            };
            DateTime lastDate = item.NormalizeDate(item.RecurrenceStartDate.AddYears((numberOfRecurrences * item.YearlyEveryNYears) - item.YearlyEveryNYears));

            //Act
            item.ProcessFutureDates();

            //Assert
            Assert.AreEqual(item.Name, "Yearly every " + item.YearlyEveryNYears + " years for a total of " + numberOfRecurrences + " FutureDates");
            DateTime[] dates = item.FutureDates.ToArray();
            Assert.AreEqual(lastDate, dates[dates.Length - 1]);
        }
Exemplo n.º 18
0
 /// <summary>
 /// Visitor pattern for generating description for this schedule.  Will update Description and fire events.
 /// </summary>
 public virtual void Visit(YearlySchedule s) { OnDescriptionChanged(s, Format(s)); }
Exemplo n.º 19
0
        /// <summary>
        /// Gets the generated description for the schedule.  Will not update Description or fire events.
        /// </summary>
        public virtual string Format(YearlySchedule s)
        {
            // Annually on April 12
            // Every 2 years on April 12
            var sb = new StringBuilder();
            if (s.Frequency == 1)
                sb.Append("Annually");
            else
                sb.AppendFormat("Every {0} years", s.Frequency);

            if (Start.HasValue)
                sb.AppendFormat(" on {0}", Start.Value.ToString("MMMM d"));

            return sb.ToString();
            //(EndDate.HasValue ? String.Format(", ending {0}", EndDate.Value.ToString("d MMMM yyyy")) : ""));
        }
        public void Next_occurrence_before_start()
        {
            // 3/11/1983, 3/11/1990, 3/11/1997, 3/11/2004, 3/11/2011, 3/11/2018, 3/11/2026
            YearlySchedule year = new YearlySchedule { Frequency = 7 };
            DateTime? next = year.NextOccurrence(_start, new DateTime(1957, 12, 7));

            Assert.IsTrue(next.HasValue);
            Assert.AreEqual(new DateTime(1983, 11, 3), next.Value);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Validates null values and other possible combinations
        /// </summary>
        public override void Validate()
        {
            base.Validate();

            if (IsDailyScheduleEnabled == false && IsWeeklyScheduleEnabled == false &&
                IsMonthlyScheduleEnabled == false && IsYearlyScheduleEnabled == false)
            {
                throw new ArgumentException(Resources.AllRetentionSchedulesEmptyException);
            }

            if (IsDailyScheduleEnabled)
            {
                if (DailySchedule == null)
                {
                    throw new ArgumentException(Resources.DailyScheduleEnabledButScheduleIsNullException);
                }
                else
                {
                    DailySchedule.BackupManagementType = BackupManagementType;
                    DailySchedule.Validate();
                }
            }

            if (IsWeeklyScheduleEnabled)
            {
                if (WeeklySchedule == null)
                {
                    throw new ArgumentException(Resources.WeeklyScheduleEnabledButScheduleIsNullException);
                }
                else
                {
                    WeeklySchedule.BackupManagementType = BackupManagementType;
                    WeeklySchedule.Validate();
                }
            }

            if (IsMonthlyScheduleEnabled)
            {
                if (MonthlySchedule == null)
                {
                    throw new ArgumentException(Resources.MonthlyScheduleEnabledButScheduleIsNullException);
                }
                else
                {
                    MonthlySchedule.BackupManagementType = BackupManagementType;
                    MonthlySchedule.Validate();
                }
            }

            if (IsYearlyScheduleEnabled)
            {
                if (YearlySchedule == null)
                {
                    throw new ArgumentException(Resources.YearlyScheduleEnabledButScheduleIsNullException);
                }
                else
                {
                    YearlySchedule.BackupManagementType = BackupManagementType;
                    YearlySchedule.Validate();
                }
            }
        }
Exemplo n.º 22
0
 /// <summary>
 /// Visitor pattern for generating description for this schedule.  Will update Description and fire events.
 /// </summary>
 public virtual void Visit(YearlySchedule s)
 {
     OnDescriptionChanged(s, Format(s));
 }