Example #1
0
        public void IsOffDay1And3Wednesday()
        {
            var testDayOfWeek = DayOfWeek.Wednesday;

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddWeeklyInMonthEvent("FirstThird", true, testDayOfWeek, new List <int> {
                1, 3
            });
            var occurrence   = -99;
            var currentDate  = _startTestDate;
            var dayOfWeekInc = currentDate.DayOfWeek;
            var dateEnd      = _endTestDate;

            while (currentDate <= dateEnd)
            {
                if (currentDate.Day == 1)
                {
                    occurrence   = 1;
                    dayOfWeekInc = currentDate.DayOfWeek;
                }
                else if (currentDate.DayOfWeek == dayOfWeekInc)
                {
                    occurrence++;
                }

                var expected = currentDate.DayOfWeek == testDayOfWeek && (occurrence == 1 || occurrence == 3);
                var actual   = currentDate.IsDayOff();
                Assert.True(expected == actual, "Failed on, " + currentDate);
                currentDate = currentDate.AddDays(1);
            }
        }
Example #2
0
        public void Remove()
        {
            const string monthlyKey = "monthlyKey";
            const string weekKey    = "WeekKey";
            const string yearlyKey  = "YearlyKey";
            const string dateKey    = "dateKey";

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddYearlyDateEvent(yearlyKey, false, 1, 2, false, false);
            CalendarDateTime.AddMonthlyDateEvent(monthlyKey, true, 12);
            CalendarDateTime.AddWeeklyInMonthEvent(weekKey, false, DayOfWeek.Friday);
            CalendarDateTime.AddDateEvent(dateKey, false, DateTime.Now);

            Assert.False(CalendarDateTime.RemoveEvent("nothingRemoved"));
            Assert.True(CalendarDateTime.CountEvents == 4);
            Assert.True(CalendarDateTime.RemoveEvent(weekKey));
            Assert.True(CalendarDateTime.CountEvents == 3);
            Assert.True(CalendarDateTime.RemoveEvent(dateKey));
            Assert.True(CalendarDateTime.CountEvents == 2);
            Assert.True(CalendarDateTime.RemoveEvent(yearlyKey));
            Assert.True(CalendarDateTime.CountEvents == 1);
            Assert.False(CalendarDateTime.RemoveEvent("notHere"));
            Assert.True(CalendarDateTime.CountEvents == 1);
            Assert.True(CalendarDateTime.RemoveEvent(monthlyKey));
            Assert.True(CalendarDateTime.CountEvents == 0);
        }
Example #3
0
        public void AddWeeklyInMonthEventEventNameNullEmptyThrows()
        {
            var dayOfWeeks = DayOfWeek.Monday;

            Assert.Throws <ArgumentNullException>(() => CalendarDateTime.AddWeeklyInMonthEvent(null, true, dayOfWeeks));
            Assert.Throws <ArgumentNullException>(() => CalendarDateTime.AddWeeklyInMonthEvent(string.Empty, true, dayOfWeeks));
        }
Example #4
0
        public void DuplicateKeysThrows()
        {
            const string weekKey = "WeekKey";

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddWeeklyInMonthEvent(weekKey, false, DayOfWeek.Friday);
            Assert.Throws <ArgumentException>(() => CalendarDateTime.AddYearlyDateEvent(weekKey, false, 1, 2, false, false));
        }
Example #5
0
        public void AddWeeklyInMonthEventEventMaxSixThrows()
        {
            // TODO: change to single int, remove collection.
            var weeks = new List <int> {
                6, 5
            };

            CalendarDateTime.ClearCalendar();
            Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddWeeklyInMonthEvent("test", true, DayOfWeek.Friday, weeks));
        }
Example #6
0
        public void AddWeeklyInMonthEventEventMinZeroThrows()
        {
            // TODO: chanbe to int overload on weeks.
            var weeks = new List <int> {
                1, 0
            };

            CalendarDateTime.ClearCalendar();
            Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddWeeklyInMonthEvent("test", true, DayOfWeek.Friday, weeks));
        }
Example #7
0
        public void AddWeeklyInMonthEventEventNameDuplicatesThrows()
        {
            const string duplicate = "duplicate";

            CalendarDateTime.ClearCalendar();
            var duplicateDayOfWeeks = DayOfWeek.Friday;

            CalendarDateTime.AddWeeklyInMonthEvent(duplicate, true, duplicateDayOfWeeks);
            Assert.Throws <ArgumentException>(() => CalendarDateTime.AddWeeklyInMonthEvent(duplicate, false, duplicateDayOfWeeks));
        }
Example #8
0
        public void AddWeeklyInMonthEvent13NotPayday24Payday()
        {
            const string reportDayEvent = "Report Day";
            const string payDayEvent    = "Payday";
            var          reportWeeks    = new List <int> {
                1, 3
            };
            var paydayWeeks = new List <int> {
                2, 4
            };
            var testDayOfWeek  = DayOfWeek.Thursday;
            var testStartRange = _startTestDate.AddYears(5);
            var testEndRange   = _endTestDate.AddYears(-5);

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddWeeklyInMonthEvent(reportDayEvent, false, testDayOfWeek, reportWeeks, testStartRange, testEndRange);
            CalendarDateTime.AddWeeklyInMonthEvent(payDayEvent, false, testDayOfWeek, paydayWeeks, testStartRange, testEndRange);
            var currentWeek = -99;

            for (var currentDate = _startTestDate; currentDate <= _endTestDate; currentDate = currentDate.AddDays(1))
            {
                var actual = currentDate.EventsOnDate(true, true);
                if (!currentDate.IsBetweenEqual(testStartRange, testEndRange))
                {
                    Assert.Empty(actual);
                    continue;
                }

                if (currentDate.Day == 1)
                {
                    currentWeek = 0;
                }

                if (testDayOfWeek == currentDate.DayOfWeek)
                {
                    currentWeek++;
                }

                if (testDayOfWeek == currentDate.DayOfWeek && reportWeeks.Contains(currentWeek))
                {
                    Assert.Contains(reportDayEvent, actual);
                }
                else if (testDayOfWeek == currentDate.DayOfWeek && paydayWeeks.Contains(currentWeek))
                {
                    Assert.Contains(payDayEvent, actual);
                }
                else
                {
                    Assert.Empty(actual);
                }
            }
        }
Example #9
0
        public void ClearCalendar()
        {
            CalendarDateTime.ClearCalendar();
            Assert.Equal(0, CalendarDateTime.CountEvents);
            CalendarDateTime.AddYearlyDateEvent("yearlyKey", false, 1, 2, false, false);
            CalendarDateTime.AddMonthlyDateEvent("monthlyKey", true, 12);
            CalendarDateTime.AddWeeklyInMonthEvent("weekKey", false, DayOfWeek.Friday);
            CalendarDateTime.AddDateEvent("dateKey", false, DateTime.Now);

            Assert.True(CalendarDateTime.CountEvents == 4);
            CalendarDateTime.ClearCalendar();
            Assert.True(CalendarDateTime.CountEvents == 0);
        }
Example #10
0
        public void KeysWeeklyEvents()
        {
            const string m1   = "m1";
            const string m2   = "m2";
            var          mSet = new List <string> {
                m1, m2
            };

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddWeeklyInMonthEvent(m1, false, DayOfWeek.Friday);
            CalendarDateTime.AddWeeklyInMonthEvent(m2, false, DayOfWeek.Friday);
            Assert.Equal(mSet, CalendarDateTime.KeysEvents.ToList());
            Assert.Equal(mSet, CalendarDateTime.KeysWeeklyEvents.ToList());
        }
Example #11
0
        public void IsOffDaySaturdayOnly()
        {
            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddWeeklyInMonthEvent(DayOfWeek.Saturday.ToString(), true, DayOfWeek.Saturday);
            var currentDate = _startTestDate;
            var dateEnd     = _endTestDate;

            while (currentDate <= dateEnd)
            {
                var expected = currentDate.DayOfWeek == DayOfWeek.Saturday;
                var actual   = currentDate.IsDayOff();
                Assert.True(expected == actual, "Failed on, " + currentDate);
                currentDate = currentDate.AddDays(1);
            }
        }
Example #12
0
        public void CountCalendar()
        {
            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddYearlyDateEvent("yearlyKey", false, 1, 2, false, false);
            CalendarDateTime.AddMonthlyDateEvent("month", true, 5);
            CalendarDateTime.AddWeeklyInMonthEvent("weekKey", false, DayOfWeek.Friday);
            CalendarDateTime.AddDateEvent("datedKey", false, DateTime.Now);

            var expected = 4;
            var actual   = CalendarDateTime.CountEvents;

            Assert.Equal(expected, actual);
            CalendarDateTime.ClearCalendar();
            Assert.Equal(0, CalendarDateTime.CountEvents);
        }
Example #13
0
        public void ClearWeekly()
        {
            CalendarDateTime.ClearCalendar();
            Assert.Equal(0, CalendarDateTime.CountWeeklyEvents);
            Assert.Equal(0, CalendarDateTime.CountEvents);

            CalendarDateTime.AddWeeklyInMonthEvent("Week1", true, DayOfWeek.Friday);
            Assert.Equal(1, CalendarDateTime.CountWeeklyEvents);
            Assert.Equal(1, CalendarDateTime.CountEvents);

            CalendarDateTime.AddWeeklyInMonthEvent("Week2", true, DayOfWeek.Friday);
            Assert.Equal(2, CalendarDateTime.CountWeeklyEvents);
            Assert.Equal(2, CalendarDateTime.CountEvents);

            CalendarDateTime.ClearCalendar();
            Assert.Equal(0, CalendarDateTime.CountWeeklyEvents);
            Assert.Equal(0, CalendarDateTime.CountEvents);
        }
Example #14
0
        public void CountWeekly()
        {
            CalendarDateTime.ClearCalendar();
            Assert.Equal(0, CalendarDateTime.CountWeeklyEvents);
            Assert.Equal(0, CalendarDateTime.CountEvents);

            CalendarDateTime.AddWeeklyInMonthEvent("w1", false, DayOfWeek.Friday);
            Assert.Equal(1, CalendarDateTime.CountWeeklyEvents);
            Assert.Equal(1, CalendarDateTime.CountEvents);

            CalendarDateTime.AddWeeklyInMonthEvent("w2", false, DayOfWeek.Saturday);
            Assert.Equal(2, CalendarDateTime.CountWeeklyEvents);
            Assert.Equal(2, CalendarDateTime.CountEvents);

            CalendarDateTime.ClearCalendar();
            Assert.Equal(0, CalendarDateTime.CountWeeklyEvents);
            Assert.Equal(0, CalendarDateTime.CountEvents);
        }
Example #15
0
        public void KeysEvents()
        {
            const string dated      = "dated";
            const string weekKey    = "WeekKey";
            const string yearlyKey  = "YearlyKey";
            const string monthlyKey = "monthlyKey";

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddYearlyDateEvent(yearlyKey, false, 1, 2, false, false);
            CalendarDateTime.AddWeeklyInMonthEvent(weekKey, false, DayOfWeek.Friday);
            CalendarDateTime.AddDateEvent(dated, false, DateTime.Now);
            CalendarDateTime.AddMonthlyDateEvent(monthlyKey, true, 2);

            var expected = new List <string> {
                yearlyKey, weekKey, dated, monthlyKey
            }.OrderBy(s => s);
            var actual = CalendarDateTime.KeysEvents.ToList().OrderBy(s => s);

            Assert.Equal(expected, actual);
        }
Example #16
0
        public void EventDatesBetweenWeeklyInMonthEvent()
        {
            const string eventName       = "Payday";
            var          dayOfWeekTarget = DayOfWeek.Thursday;
            var          startDate       = new DateTime(2018, 1, 1);
            var          endDate         = new DateTime(2018, 3, 30);
            var          intervals       = new List <int> {
                1, 3
            };
            var week = 1;

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddWeeklyInMonthEvent(eventName, false, DayOfWeek.Thursday, intervals, startDate, endDate);

            var expected = new List <DateTime>();

            for (var date = startDate; date <= endDate; date = date.AddDays(1))
            {
                if (date.Day == 1)
                {
                    week = 1;
                }
                else if (date.Day != 1 && date.DayOfWeek == DayOfWeek.Sunday)
                {
                    week++;
                }

                if (date.DayOfWeek == dayOfWeekTarget && intervals.Contains(week))
                {
                    expected.Add(date);
                }
            }

            var actual = eventName.EventDatesBetween(startDate, endDate);

            Assert.Equal(actual, expected);
        }
Example #17
0
 ///-------------------------------------------------------------------------------------------------
 /// <summary>	Weekly day off. </summary>
 ///
 /// <param name="dayOfWeek">	The day of week. </param>
 ///
 /// <example>
 ///     <code>
 ///     // using ThisDate.DefinedCalendars.USA;
 ///     CalendarDateTime.WeeklyDayOff(DayOfWeek.Friday);
 ///     </code>
 /// </example>
 ///-------------------------------------------------------------------------------------------------
 public static void WeeklyDayOff(DayOfWeek dayOfWeek)
 {
     CalendarDateTime.AddWeeklyInMonthEvent(dayOfWeek.ToString(), true, dayOfWeek);
 }