Esempio n. 1
0
        public void CtorTests()
        {
            var obj = new PeriodicMonthMatcher(1, null, 2);

            Assert.AreEqual(2, obj.Period);

            Assert.ThrowsException <ArgumentException>(() => new PeriodicMonthMatcher(2, 2, 2),
                                                       "Single year range invalid");
            Assert.ThrowsException <ArgumentException>(() => new PeriodicMonthMatcher(1, 12, 1),
                                                       "Invalid period");
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => new PeriodicMonthMatcher(1, 13, 2));
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => new PeriodicMonthMatcher(13, null, 2));
        }
Esempio n. 2
0
 public void TryParseTests()
 {
     // Testing object factory
     Assert.IsTrue(PeriodicMonthMatcher.TryParse("1..4/2", out var obj));
     Assert.IsNotNull(obj);
     Assert.AreEqual(1, obj.Left);
     Assert.AreEqual(4, obj.Right);
     Assert.AreEqual(2, obj.Period);
     Assert.IsTrue(PeriodicMonthMatcher.TryParse("1../3", out obj));
     Assert.IsNotNull(obj);
     Assert.AreEqual(1, obj.Left);
     Assert.AreEqual(12, obj.Right);
     Assert.AreEqual(3, obj.Period);
 }
Esempio n. 3
0
        /// <summary>
        ///     Parse a month match expression.
        ///     <example>
        ///         Valid expression are:
        ///         * => Every month
        ///         11 => Only for november
        ///         ..11 => Every month until november
        ///         2.. => Every month starting from february
        ///         2..11 => Every month between february and november
        ///         1..7/2 => Starting from january every 2 years until july
        ///         3../2 => Starting from march every 2 months
        ///         1..7%2 => Every month which reminder modulo 2 is zero between january and july
        ///         2..%3 => Starting from february every month which reminder modulo 3 is zero
        ///     </example>
        /// </summary>
        public override bool TryParse(string value, out IMonthMatcher monthMatcher)
        {
            if (RangeMonthMatcher.TryParse(value, out var rangeMonthMatcher))
            {
                monthMatcher = rangeMonthMatcher;
                return(true);
            }

            if (ModuloMonthMatcher.TryParse(value, out var moduloMonthMatcher))
            {
                monthMatcher = moduloMonthMatcher;
                return(true);
            }

            if (PeriodicMonthMatcher.TryParse(value, out var periodicMonthMatcher))
            {
                monthMatcher = periodicMonthMatcher;
                return(true);
            }

            monthMatcher = default;
            return(false);
        }
Esempio n. 4
0
        public void MatchTests()
        {
            var m1 = new DateTime(2000, 1, 1);
            var m2 = new DateTime(2000, 2, 1);
            var m3 = new DateTime(2000, 3, 1);
            var m4 = new DateTime(2000, 4, 1);

            var obj = new PeriodicMonthMatcher(1, null, 2);

            Assert.IsTrue(obj.Match(m1));
            Assert.IsFalse(obj.Match(m2));
            Assert.IsTrue(obj.Match(m3));
            Assert.IsFalse(obj.Match(m4));
            obj = new PeriodicMonthMatcher(2, null, 2);
            Assert.IsFalse(obj.Match(m1));
            Assert.IsTrue(obj.Match(m2));
            Assert.IsFalse(obj.Match(m3));
            Assert.IsTrue(obj.Match(m4));
            obj = new PeriodicMonthMatcher(3, null, 2);
            Assert.IsFalse(obj.Match(m1));
            Assert.IsFalse(obj.Match(m2));
            Assert.IsTrue(obj.Match(m3));
            Assert.IsFalse(obj.Match(m4));
        }