Example #1
0
        public void EventsOnDateDate()
        {
            var offKey = new List <string> {
                "dayOf"
            };
            var workKey = new List <string> {
                "dayOn"
            };
            var bothOffWork = new List <string>();

            bothOffWork.AddRange(offKey);
            bothOffWork.AddRange(workKey);
            var date = DateTime.Now;

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddYearlyDateEvent(offKey[0], true, date.Month, date.Day, false, false);
            CalendarDateTime.AddYearlyDateEvent(workKey[0], false, date.Month, date.Day, false, false);

            var dayOff  = date.EventsOnDate(false, true).ToList();
            var workday = date.EventsOnDate(true, false).ToList();
            var both    = date.EventsOnDate(true, true).ToList();
            var neither = date.EventsOnDate(false, false).ToList();

            Assert.NotStrictEqual(dayOff, offKey);
            Assert.NotStrictEqual(workday, workKey);
            Assert.Empty(neither);
            Assert.NotStrictEqual(bothOffWork, both);
            Assert.Empty(date.AddDays(1).EventsOnDate(true, true));
        }
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 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 #4
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 #5
0
        public void KeysYearlyEvents()
        {
            const string m1   = "m1";
            const string m2   = "m2";
            var          mSet = new List <string> {
                m1, m2
            };

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddYearlyDateEvent(m1, false, 1, 2, false, false);
            CalendarDateTime.AddYearlyDateEvent(m2, false, 1, 2, false, false);
            Assert.Equal(mSet, CalendarDateTime.KeysEvents.ToList());
            Assert.Equal(mSet, CalendarDateTime.KeysYearlyEvents.ToList());
        }
Example #6
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 #7
0
        public void CountYearly()
        {
            CalendarDateTime.ClearCalendar();
            Assert.Equal(0, CalendarDateTime.CountYearlyEvents);
            Assert.Equal(0, CalendarDateTime.CountEvents);

            CalendarDateTime.AddYearlyDateEvent("y1", false, 1, 2, false, false);
            Assert.Equal(1, CalendarDateTime.CountYearlyEvents);
            Assert.Equal(1, CalendarDateTime.CountEvents);

            CalendarDateTime.AddYearlyDateEvent("y2", false, 1, 2, false, false);
            Assert.Equal(2, CalendarDateTime.CountYearlyEvents);
            Assert.Equal(2, CalendarDateTime.CountEvents);

            CalendarDateTime.ClearCalendar();
            Assert.Equal(0, CalendarDateTime.CountYearlyEvents);
            Assert.Equal(0, CalendarDateTime.CountEvents);
        }
Example #8
0
 public void AddYearlyInvalidDateEventThrowsDays()
 {
     CalendarDateTime.ClearCalendar();
     CalendarDateTime.AddYearlyDateEvent("good0", false, 1, 1, false, false);
     Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddYearlyDateEvent("test0", false, 1, 0, false, false));
     Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddYearlyDateEvent("test1", false, 1, 32, false, false));
     Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddYearlyDateEvent("test2", false, 2, 30, false, false));
     Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddYearlyDateEvent("test3", false, 3, 32, false, false));
     Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddYearlyDateEvent("test4", false, 4, 31, false, false));
     Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddYearlyDateEvent("test5", false, 5, 32, false, false));
     Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddYearlyDateEvent("test6", false, 6, 31, false, false));
     Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddYearlyDateEvent("test7", false, 7, 32, false, false));
     Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddYearlyDateEvent("test8", false, 8, 32, false, false));
     Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddYearlyDateEvent("test9", false, 9, 31, false, false));
     Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddYearlyDateEvent("test10", false, 10, 32, false, false));
     Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddYearlyDateEvent("test11", false, 11, 31, false, false));
     Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddYearlyDateEvent("test12", false, 12, 32, false, false));
 }
Example #9
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 #10
0
        /// -------------------------------------------------------------------------------------------------
        ///  <summary>	Add Independence Day (4th of July). </summary>
        /// <param name="dayOff">			Day off (not a workday). </param>
        /// <param name="saturdayBack">     If the date is Saturday observe on Friday. </param>
        /// <param name="sundayForward">	if the date is on Sunday observe on Monday. </param>
        /// <example>
        ///     <code>
        ///     // using ThisDate.DefinedCalendars.USA;
        ///     CalendarDateTime.Halloween(true);
        ///     </code>
        ///  </example>
        /// -------------------------------------------------------------------------------------------------
        public static void IndependenceDay(bool dayOff, bool saturdayBack, bool sundayForward)
        {
            var start = new DateTime(1776, 1, 1);               // Seems no official start year

            CalendarDateTime.AddYearlyDateEvent(HolidayNames.IndependentsDayText, dayOff, 7, 4, saturdayBack, sundayForward, start);
        }
Example #11
0
 public void AddYearlyDateEventThrowsLowMonth()
 {
     CalendarDateTime.ClearCalendar();
     CalendarDateTime.AddYearlyDateEvent("test4", false, 1, 1, false, false);
     Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddYearlyDateEvent("test8", false, 0, 1, false, false));
 }
Example #12
0
 public void AddYearlyDateEventThrowsHighMonth()
 {
     CalendarDateTime.ClearCalendar();
     CalendarDateTime.AddYearlyDateEvent("test0", false, 12, 1, false, false);
     Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddYearlyDateEvent("test2", false, 13, 1, false, false));
 }
Example #13
0
 public void AddYearlyDateEventThrowsEmptyEvent()
 {
     Assert.Throws <ArgumentNullException>(() => CalendarDateTime.AddYearlyDateEvent("", false, 1, 1, false, false));
 }
Example #14
0
        /// -------------------------------------------------------------------------------------------------
        ///  <summary>	Add Veterans Day, November 11. </summary>
        /// <param name="dayOff">			Day off (not a workday). </param>
        /// <param name="saturdayBack">     Move back to Friday if on Saturday. </param>
        /// <param name="sundayForward">	Move forward to Monday if on Sunday. </param>
        /// <example>
        ///     <code>
        ///     // using ThisDate.DefinedCalendars.USA;
        ///     CalendarDateTime.VeteransDay(false);
        ///     </code>
        ///  </example>
        /// -------------------------------------------------------------------------------------------------
        public static void VeteransDay(bool dayOff, bool saturdayBack, bool sundayForward)
        {
            var start = new DateTime(1954, 1, 1);

            CalendarDateTime.AddYearlyDateEvent(HolidayNames.VeteransDayText, dayOff, 11, 11, saturdayBack, sundayForward, start);
        }
Example #15
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>	Add Saint Patrick's Day. </summary>
        ///
        /// <param name="dayOff">	Day off (not a workday). </param>
        ///
        /// <example>
        ///     <code>
        ///     // using ThisDate.DefinedCalendars.USA;
        ///     CalendarDateTime.ValentinesDay(false);
        ///     </code>
        /// </example>
        ///-------------------------------------------------------------------------------------------------
        public static void ValentinesDay(bool dayOff)
        {
            var start = new DateTime(300, 1, 1);

            CalendarDateTime.AddYearlyDateEvent(HolidayNames.ValentinesDayText, dayOff, 2, 14, false, false, start);
        }
Example #16
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>	Add Saint Patrick's Day. </summary>
        ///
        /// <param name="dayOff">	Day off (not a workday). </param>
        ///
        /// <example>
        ///     <code>
        ///     // using ThisDate.DefinedCalendars.USA;
        ///     CalendarDateTime.SaintPatrickDay(false);
        ///     </code>
        /// </example>
        ///-------------------------------------------------------------------------------------------------
        public static void SaintPatrickDay(bool dayOff)
        {
            var start = new DateTime(1762, 1, 1);

            CalendarDateTime.AddYearlyDateEvent(HolidayNames.SaintPatrickDayText, dayOff, 3, 17, false, false, start);
        }
Example #17
0
 /// -------------------------------------------------------------------------------------------------
 ///  <summary>	Adds the new years day. </summary>
 /// <param name="dayOff">			Day off (not a workday). </param>
 /// <param name="saturdayBack">     If date falls on Saturday then observe Friday. </param>
 /// <param name="sundayForward">	If date falls on Sunday then observe on Monday. </param>
 /// <example>
 ///     <code>
 ///     // using ThisDate.DefinedCalendars.USA;
 ///     CalendarDateTime.NewYearsDay(true);
 ///     </code>
 ///  </example>
 /// -------------------------------------------------------------------------------------------------
 public static void NewYearsDay(bool dayOff, bool saturdayBack, bool sundayForward)
 {
     CalendarDateTime.AddYearlyDateEvent(HolidayNames.NewYearsDayText, dayOff, 1, 1, saturdayBack, sundayForward);
 }
Example #18
0
 /// -------------------------------------------------------------------------------------------------
 ///  <summary>	Add Christmas Day. </summary>
 /// <param name="dayOff">			Day off (not a workday). </param>
 /// <param name="saturdayBack">     If the date is Saturday then observe on Friday. </param>
 /// <param name="sundayForward">	If the date is Sunday then observe on Monday. </param>
 /// <example>
 ///     <code>
 ///     // using ThisDate.DefinedCalendars.USA;
 ///     Holiday.ChristmasDay(false, true, true);
 ///     </code>
 ///  </example>
 /// -------------------------------------------------------------------------------------------------
 public static void ChristmasDay(bool dayOff, bool saturdayBack, bool sundayForward)
 {
     CalendarDateTime.AddYearlyDateEvent(HolidayNames.ChristmasDayText, dayOff, 12, 25, saturdayBack, sundayForward);
 }
Example #19
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>	Add Halloween. </summary>
        ///
        /// <param name="dayOff">	Day off (not a workday). </param>
        ///
        /// <example>
        ///     <code>
        ///     // using ThisDate.DefinedCalendars.USA;
        ///     CalendarDateTime.Halloween(false);
        ///     </code>
        /// </example>
        ///-------------------------------------------------------------------------------------------------
        public static void Halloween(bool dayOff)
        {
            var start = new DateTime(1850, 1, 1);               // Seems no official start year

            CalendarDateTime.AddYearlyDateEvent(HolidayNames.HalloweenText, dayOff, 10, 31, false, false, start);
        }
Example #20
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>	Groundhog day. </summary>
        ///
        /// <param name="dayOff">	Day off (not a workday). </param>
        ///
        /// <example>
        ///     <code>
        ///     // using ThisDate.DefinedCalendars.USA;
        ///     CalendarDateTime.GroundhogDay(false);
        ///     </code>
        /// </example>
        ///-------------------------------------------------------------------------------------------------
        public static void GroundhogDay(bool dayOff)
        {
            var start = new DateTime(1887, 1, 1);

            CalendarDateTime.AddYearlyDateEvent(HolidayNames.GroundHogDayText, dayOff, 2, 2, false, false, start);
        }