Example #1
0
 public void AddMonthlyDayOfWeekForwardEventThrowsWeeksForwardInvalid()
 {
     CalendarDateTime.ClearCalendar();
     CalendarDateTime.AddMonthlyDayOfWeekForwardEvent("alpha", true, DayOfWeek.Friday, 1);
     Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddMonthlyDayOfWeekForwardEvent("beta", true, DayOfWeek.Friday, 0));
     Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddMonthlyDayOfWeekForwardEvent("delta", true, DayOfWeek.Friday, -1));
 }
Example #2
0
        public void AddMonthlyDayOfWeekForwardEventThrowsStartEndInbound()
        {
            const string eventName = "alpha";
            var          start     = new DateTime(DateTime.Now.AddYears(-2).Year, DateTime.Now.AddYears(-2).Month, 1);
            var          end       = DateTime.Now.AddYears(2);

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddMonthlyDayOfWeekForwardEvent(eventName, true, DayOfWeek.Friday, 1, start, end);
            bool foundFirstFriday = false;

            for (var currentDate = start; currentDate <= end; currentDate = currentDate.AddDays(1))
            {
                if (currentDate.IsFirstDayOfMonth())
                {
                    foundFirstFriday = false;
                }

                if (!foundFirstFriday && currentDate.DayOfWeek == DayOfWeek.Friday)
                {
                    foundFirstFriday = true;
                    Assert.Contains(eventName, currentDate.EventsOnDate(true, true));
                }
                else
                {
                    Assert.Empty(currentDate.EventsOnDate(true, true));
                }
            }
        }
Example #3
0
        public void EventDatesMonthlyDayOfWeekForwardEvent()
        {
            const string    eventName       = "Tango";
            const int       targetWeek      = 2;
            const DayOfWeek targetDayOfWeek = DayOfWeek.Wednesday;

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

            for (var date = _startTestDate; date <= _endTestDate; date = date.AddDays(1))
            {
                if (date.IsFirstDayOfMonth())
                {
                    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 void AddMonthlyDayOfWeekForwardEventThrowsDuplicate()
        {
            const string dup = "duplicate";

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddMonthlyDayOfWeekForwardEvent(dup, false, DayOfWeek.Monday, 2);
            Assert.Throws <ArgumentException>(() => CalendarDateTime.AddMonthlyDayOfWeekForwardEvent(dup, true, DayOfWeek.Friday, 1));
        }
Example #5
0
        public void AddMonthlyDayOfWeekForwardEventThrowsStartEndOutBound()
        {
            var start = DateTime.Now.AddYears(-2);
            var end   = DateTime.Now.AddYears(2);

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddMonthlyDayOfWeekForwardEvent("alpha", true, DayOfWeek.Friday, 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 #6
0
 public void AddMonthlyDayOfWeekForwardEventThrowEmptyEvent()
 {
     Assert.Throws <ArgumentNullException>(() => CalendarDateTime.AddMonthlyDayOfWeekForwardEvent(null, true, DayOfWeek.Friday, 1));
     Assert.Throws <ArgumentNullException>(() => CalendarDateTime.AddMonthlyDayOfWeekForwardEvent(string.Empty, true, DayOfWeek.Friday, 1));
 }