Example #1
0
        public static void AddMonthlyDayOfWeekReverseEventsInRange()
        {
            var eventName = "someName";
            var start     = _startTestDate;
            var end       = _endTestDate.LastDateOfMonth();

            CalendarDateTime.ClearCalendar();

            CalendarDateTime.AddMonthlyDayOfWeekReverseEvent(eventName, true, DayOfWeek.Monday, 1, start, end);             // Last Monday of every month
            var foundLastMonday = false;

            // dateEnd need to seed in as equal or after the last Monday of the month to work (last day of the month works).
            for (var currentDate = end; currentDate >= start; currentDate = currentDate.AddDays(-1))
            {
                if (currentDate.IsLastDayOfMonth())
                {
                    foundLastMonday = false;
                }

                if (!foundLastMonday && currentDate.DayOfWeek == DayOfWeek.Monday)
                {
                    foundLastMonday = true;
                    var actual = currentDate.EventsOnDate(true, true);
                    Assert.Contains(eventName, actual);
                }
                else
                {
                    Assert.Empty(currentDate.EventsOnDate(true, true));
                }
            }
        }
Example #2
0
        public static void AddMonthlyDayOfWeekReverseEventDuplicateThrows()
        {
            const string dupName = "dup";

            CalendarDateTime.AddMonthlyDayOfWeekReverseEvent(dupName, true, DayOfWeek.Monday, 2);
            Assert.Throws <ArgumentException>(() => CalendarDateTime.AddMonthlyDayOfWeekReverseEvent(dupName, true, DayOfWeek.Monday, 2));
        }
Example #3
0
        public void EventDatesMonthlyOfWeekReverseEvent()
        {
            const string    eventName       = "Tango";
            const int       targetWeek      = 2;
            const DayOfWeek targetDayOfWeek = DayOfWeek.Wednesday;

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddMonthlyDayOfWeekReverseEvent(eventName, true, targetDayOfWeek, targetWeek, _startTestDate, _endTestDate);
            var actual   = eventName.EventDatesBetween(_startTestDate, _endTestDate);
            var expected = new List <DateTime>();
            int week     = 0;

            for (var date = _endTestDate; date >= _startTestDate; date = date.AddDays(-1))
            {
                if (date.IsLastDayOfMonth())
                {
                    week = 0;
                }

                if (date.DayOfWeek == targetDayOfWeek)
                {
                    week++;
                }

                if (week == targetWeek && date.DayOfWeek == targetDayOfWeek)
                {
                    expected.Add(date);
                }
            }

            expected = expected.OrderBy(s => s).ToList();
            Assert.Equal(expected, actual);
        }
Example #4
0
        public static void AddMonthlyDayOfWeekReverseEventsOutsideRange()
        {
            var start = DateTime.Now.AddYears(-1);
            var end   = DateTime.Now.AddYears(1);

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddMonthlyDayOfWeekReverseEvent("1", true, DayOfWeek.Monday, 1, start, end);
            for (var currentDate = start.AddYears(-2); currentDate <= end.AddYears(2); currentDate = currentDate.AddDays(1))
            {
                if (!currentDate.IsBetweenEqual(start, end))
                {
                    Assert.Empty(currentDate.EventsOnDate(true, true));
                }
            }
        }
Example #5
0
 public static void AddMonthlyDayOfWeekReverseEventWeeksBackNegThrows()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddMonthlyDayOfWeekReverseEvent("event", false, DayOfWeek.Saturday, 0));
 }
Example #6
0
 public static void AddMonthlyDayOfWeekReverseEventNameThrows()
 {
     Assert.Throws <ArgumentNullException>(() => CalendarDateTime.AddMonthlyDayOfWeekReverseEvent(null, false, DayOfWeek.Friday, 2));
     Assert.Throws <ArgumentNullException>(() => CalendarDateTime.AddMonthlyDayOfWeekReverseEvent(string.Empty, false, DayOfWeek.Friday, 2));
 }