public void LastFridayOfMonthTest()
        {
            var lastFriday = new DayInMonthTE(DayOfWeekEnum.Fri, MonthlyIntervalEnum.Last);

            Assert.IsTrue(lastFriday.Includes(new DateTime(2010, 1, 29)));
            Assert.IsTrue(lastFriday.Includes(new DateTime(2011, 6, 24)));
            Assert.IsTrue(lastFriday.Includes(new DateTime(2012, 9, 28)));

            Assert.IsFalse(lastFriday.Includes(new DateTime(2010, 1, 28)));
            Assert.IsFalse(lastFriday.Includes(new DateTime(2010, 1, 22)));
            Assert.IsFalse(lastFriday.Includes(new DateTime(2012, 7, 31)));
        }
        public void SecondTuesdayOfMonthTest()
        {
            var secondTuesday = new DayInMonthTE(DayOfWeekEnum.Tue, MonthlyIntervalEnum.Second);

            Assert.IsTrue(secondTuesday.Includes(new DateTime(2010, 6, 8)));
            Assert.IsTrue(secondTuesday.Includes(new DateTime(2011, 1, 11)));
            Assert.IsTrue(secondTuesday.Includes(new DateTime(2012, 11, 13)));

            Assert.IsFalse(secondTuesday.Includes(new DateTime(2012, 11, 19)));
            Assert.IsFalse(secondTuesday.Includes(new DateTime(2012, 1, 2)));
            Assert.IsFalse(secondTuesday.Includes(new DateTime(2012, 10, 29)));
        }
        public void SaturdayTest()
        {
            var saturday = new DayInMonthTE(DayOfWeekEnum.Sat);

            Assert.IsTrue(saturday.Includes(new DateTime(2010, 6, 26)));
            Assert.IsTrue(saturday.Includes(new DateTime(2011, 1, 1)));
            Assert.IsTrue(saturday.Includes(new DateTime(2012, 9, 29)));

            Assert.IsFalse(saturday.Includes(new DateTime(2010, 4, 29)));
            Assert.IsFalse(saturday.Includes(new DateTime(2011, 9, 1)));
            Assert.IsFalse(saturday.Includes(new DateTime(2012, 2, 10)));
        }
        public void SundayTest()
        {
            var sunday = new DayInMonthTE(DayOfWeekEnum.Sun);

            Assert.IsTrue(sunday.Includes(new DateTime(2010, 6, 27)));
            Assert.IsTrue(sunday.Includes(new DateTime(2011, 1, 2)));
            Assert.IsTrue(sunday.Includes(new DateTime(2012, 9, 30)));

            Assert.IsFalse(sunday.Includes(new DateTime(2010, 8, 14)));
            Assert.IsFalse(sunday.Includes(new DateTime(2011, 3, 15)));
            Assert.IsFalse(sunday.Includes(new DateTime(2012, 8, 1)));
        }
 public UnionTE Create()
 {
     var union = new UnionTE();
     var monthlyIntervals = EnumExtensions.GetFlags(_event.MonthlyIntervalOptions);
     foreach (MonthlyIntervalEnum monthlyInterval in monthlyIntervals)
     {
         var daysOfWeek = EnumExtensions.GetFlags(_event.DaysOfWeekOptions);
         foreach (DayOfWeekEnum dayOfWeek in daysOfWeek)
         {
             var dayInMonth = new DayInMonthTE(dayOfWeek, monthlyInterval);
             union.Add(dayInMonth);
         }
     }
     return union;
 }
        public void LastWeekendEveryMonthTest()
        {
            var weekend = new DayInMonthTE(DayOfWeekEnum.Sat | DayOfWeekEnum.Sun, MonthlyIntervalEnum.Last);
            Assert.LessOrEqual(weekend.GetHashCode(), 0);

            var lastWeekendAug2012 = new DayInMonthTE(DayOfWeekEnum.Sat | DayOfWeekEnum.Sun, MonthlyIntervalEnum.Last);
            Assert.IsTrue(weekend.Equals(lastWeekendAug2012));

            var firstWeekendAug2012 = new DayInMonthTE(DayOfWeekEnum.Sat | DayOfWeekEnum.Sun, MonthlyIntervalEnum.First);
            Assert.IsFalse(weekend.Equals(firstWeekendAug2012));

            Assert.IsFalse(weekend.Equals(null));

            Assert.IsFalse(weekend.Equals(1)); // unknown object
        }
        public void ThirdWeekendEveryMonthTest()
        {
            var weekend = new DayInMonthTE(DayOfWeekEnum.Sat | DayOfWeekEnum.Sun, MonthlyIntervalEnum.Third);
            Assert.IsTrue(weekend.GetHashCode().Equals(3));

            var thirdWeekendAug2012 = new DayInMonthTE(DayOfWeekEnum.Sat | DayOfWeekEnum.Sun, MonthlyIntervalEnum.Third);
            Assert.IsTrue(weekend.Equals(thirdWeekendAug2012));

            var firstWeekendAug2012 = new DayInMonthTE(DayOfWeekEnum.Sat | DayOfWeekEnum.Sun, MonthlyIntervalEnum.First);
            Assert.IsFalse(weekend.Equals(firstWeekendAug2012));

            Assert.IsFalse(weekend.Equals(null));
        }
        /// <summary>
        /// Street cleaning occurs from April to October on the first and third Monday of the
        /// month, excluding holidays. In this test there are two holidays: July 4 and Labor
        /// Day (first Monday in Sep). The street cleaning example is taken directly from 
        /// Martin Fowler's white paper "Recurring Events for Calendars".
        /// </summary>
        private static TemporalExpression BuildStreetCleaningTemporalExpression()
        {
            var maHolidays = new UnionTE();
            var independenceDay = new FixedHolidayTE(7, 4);
            var laborDay = new FloatingHolidayTE(9, 1, 1);

            maHolidays.Add(independenceDay);
            maHolidays.Add(laborDay);

            var firstMondayFirstWeek = new DayInMonthTE(1, 1);
            var firstMondayThirdWeek = new DayInMonthTE(1, 3);

            var firstAndThirdMonday = new UnionTE();
            firstAndThirdMonday.Add(firstMondayThirdWeek);
            firstAndThirdMonday.Add(firstMondayFirstWeek);

            var streetCleaningMonths = new IntersectionTE();
            streetCleaningMonths.Add(firstAndThirdMonday);
            streetCleaningMonths.Add(new RangeEachYearTE(3, 9));
            var diff = new DifferenceTE(streetCleaningMonths, maHolidays);
            return diff;
        }