public void ToodleDoOnXDayFrequencyTest4()
        {
            ICustomFrequency frequency = ToodleDoRecurrencyHelpers.Get2DayRecurrency("The 4th sun of each month");
            OnXDayFrequency  freq      = frequency as OnXDayFrequency;

            Assert.IsNotNull(freq);
            Assert.AreEqual(DayOfWeek.Sunday, freq.DayOfWeek);
            Assert.AreEqual(RankingPosition.Fourth, freq.RankingPosition);
        }
        public void ToodleDoOnXDayFrequencyTest6()
        {
            ICustomFrequency frequency = ToodleDoRecurrencyHelpers.Get2DayRecurrency("The LasT WeD of each month");
            OnXDayFrequency  freq      = frequency as OnXDayFrequency;

            Assert.IsNotNull(freq);
            Assert.AreEqual(DayOfWeek.Wednesday, freq.DayOfWeek);
            Assert.AreEqual(RankingPosition.Last, freq.RankingPosition);
        }
        public void ToodleDoOnXDayFrequencyTest2()
        {
            ICustomFrequency frequency = ToodleDoRecurrencyHelpers.Get2DayRecurrency("The 2ND THU of each month");
            OnXDayFrequency  freq      = frequency as OnXDayFrequency;

            Assert.IsNotNull(freq);
            Assert.AreEqual(DayOfWeek.Thursday, freq.DayOfWeek);
            Assert.AreEqual(RankingPosition.Second, freq.RankingPosition);
        }
        public void ToodleDoOnXDayFrequencyTest3()
        {
            ICustomFrequency frequency = ToodleDoRecurrencyHelpers.Get2DayRecurrency("The 3rd SaT of each month");
            OnXDayFrequency  freq      = frequency as OnXDayFrequency;

            Assert.IsNotNull(freq);
            Assert.AreEqual(DayOfWeek.Saturday, freq.DayOfWeek);
            Assert.AreEqual(RankingPosition.Third, freq.RankingPosition);
        }
        private static ICustomFrequency Get2DayOnXDayFrequency(string toodleDoFrequency)
        {
            Regex regex = new Regex(ToodleDoConstants.RecurrencyToodleDoOnXDayRegex, RegexOptions.IgnoreCase);
            Match match = regex.Match(toodleDoFrequency);

            if (match == null || !match.Success)
            {
                return(null);
            }
            OnXDayFrequency frequency = new OnXDayFrequency();
            string          position  = match.Groups["Position"].Value;
            string          day       = match.Groups["DayOfWeek"].Value;

            #region Position
            if (position.Equals(ToodleDoConstants.RecurrencyFirstShort, StringComparison.OrdinalIgnoreCase))
            {
                frequency.RankingPosition = RankingPosition.First;
            }
            else if (position.Equals(ToodleDoConstants.RecurrencySecondShort, StringComparison.OrdinalIgnoreCase))
            {
                frequency.RankingPosition = RankingPosition.Second;
            }
            else if (position.Equals(ToodleDoConstants.RecurrencyThirdShort, StringComparison.OrdinalIgnoreCase))
            {
                frequency.RankingPosition = RankingPosition.Third;
            }
            else if (position.Equals(ToodleDoConstants.RecurrencyFourthShort, StringComparison.OrdinalIgnoreCase))
            {
                frequency.RankingPosition = RankingPosition.Fourth;
            }
            else if (position.Equals(ToodleDoConstants.RecurrencyFifthShort, StringComparison.OrdinalIgnoreCase))
            {
                frequency.RankingPosition = RankingPosition.Last;
            }
            else if (position.Equals(ToodleDoConstants.RecurrencyLast, StringComparison.OrdinalIgnoreCase))
            {
                frequency.RankingPosition = RankingPosition.Last;
            }
            else
            {
                return(null);
            }
            #endregion

            #region Day

            DayOfWeek?dayOfWeek = GetDayOfWeekFromShortString(day);
            if (!dayOfWeek.HasValue)
            {
                return(null);
            }
            frequency.DayOfWeek = dayOfWeek.Value;

            #endregion

            return(frequency);
        }
Beispiel #6
0
        public void OnXDayFrequencyComputeNextDateTest4()
        {
            OnXDayFrequency freq = new OnXDayFrequency();

            freq.DayOfWeek       = DayOfWeek.Wednesday;
            freq.RankingPosition = RankingPosition.Fourth;
            DateTime referenceDate = new DateTime(2013, 2, 5);
            DateTime result        = freq.ComputeNextDate(referenceDate);

            Assert.AreEqual(new DateTime(2013, 2, 27), result);
            referenceDate = new DateTime(2013, 2, 28);
            result        = freq.ComputeNextDate(referenceDate);
            Assert.AreEqual(new DateTime(2013, 3, 27), result);
        }
Beispiel #7
0
        public void OnXDayFrequencyComputeNextDateTest1()
        {
            OnXDayFrequency freq = new OnXDayFrequency();

            freq.DayOfWeek       = DayOfWeek.Monday;
            freq.RankingPosition = RankingPosition.First;
            DateTime referenceDate = new DateTime(2013, 1, 1);
            DateTime result        = freq.ComputeNextDate(referenceDate);

            Assert.AreEqual(new DateTime(2013, 1, 7), result);
            referenceDate = new DateTime(2013, 1, 10);
            result        = freq.ComputeNextDate(referenceDate);
            Assert.AreEqual(new DateTime(2013, 2, 4), result);
        }
Beispiel #8
0
        public void OnXDayFrequencyComputeNextDateTest5()
        {
            OnXDayFrequency freq = new OnXDayFrequency();

            freq.DayOfWeek       = DayOfWeek.Tuesday;
            freq.RankingPosition = RankingPosition.Last;
            DateTime referenceDate = new DateTime(2013, 2, 5);
            DateTime result        = freq.ComputeNextDate(referenceDate);

            Assert.AreEqual(new DateTime(2013, 2, 26), result);
            referenceDate = new DateTime(2013, 2, 28);
            result        = freq.ComputeNextDate(referenceDate);
            Assert.AreEqual(new DateTime(2013, 3, 26), result);
            referenceDate = new DateTime(2013, 3, 27);
            result        = freq.ComputeNextDate(referenceDate);
            // It's the fifth tuesday in April
            Assert.AreEqual(new DateTime(2013, 4, 30), result);
        }
        private static string GetToodleDoOnXDayRecurrency(ICustomFrequency customFrequency)
        {
            OnXDayFrequency frequency = customFrequency as OnXDayFrequency;

            if (frequency == null)
            {
                return(ToodleDoConstants.RecurrencyNone);
            }

            string positionString = String.Empty;

            switch (frequency.RankingPosition)
            {
            case RankingPosition.First:
                positionString = ToodleDoConstants.RecurrencyFirst;
                break;

            case RankingPosition.Second:
                positionString = ToodleDoConstants.RecurrencySecond;
                break;

            case RankingPosition.Third:
                positionString = ToodleDoConstants.RecurrencyThird;
                break;

            case RankingPosition.Fourth:
                positionString = ToodleDoConstants.RecurrencyFourth;
                break;

            case RankingPosition.Last:
                positionString = ToodleDoConstants.RecurrencyLast;
                break;
            }
            return(string.Format(
                       CultureInfo.InvariantCulture,
                       ToodleDoConstants.RecurrencyOnXDayPattern,
                       positionString,
                       GetDayOfWeekString(frequency.DayOfWeek)));
        }