public void WillNotPassUntilBugIsFixed()
        {
            // Assemble
            var startTime = new DateTime(2014, 7, 14);
            var mailRule  = new MailRule
            {
                IsActive    = true,
                Description = "This will fail until the week of month bug is fixed",
                MailPattern = MailPattern.Montly,
                DayNumber   = 2,
                DaysOfWeek  = new Dictionary <DayOfWeek, bool> {
                    { DayOfWeek.Monday, true }
                }
            };

            var mailRules = new List <MailRule> {
                mailRule
            };

            // Act
            var result = this.parser.ParseRules(mailRules, startTime);

            // Assert
            Assert.IsTrue(result.Count == 1);
            Assert.IsTrue(result.Contains(mailRule));
        }
        public void GetMatchedRulesAcceptsMailRuleIfAnyMatcherMatchesIt()
        {
            // Assemble
            var startTime = DateTime.Now;
            var mailRule1 = new MailRule();
            var mailRule2 = new MailRule();
            var mailRule3 = new MailRule();
            var mailRule4 = new MailRule();
            var mailRules = new List <MailRule> {
                mailRule1, mailRule2, mailRule3, mailRule4
            };

            var matcher1 = MockRepository.GenerateStrictMock <IMailRuleMatcher>();
            var matcher2 = MockRepository.GenerateStrictMock <IMailRuleMatcher>();
            var matcher3 = MockRepository.GenerateStrictMock <IMailRuleMatcher>();
            var matchers = new List <IMailRuleMatcher> {
                matcher1, matcher2, matcher3
            };

            // Matcher1 is not proper for any mail rule.
            matcher1.Expect(e1 => e1.IsProperMatcher(mailRule1)).Return(false);
            matcher1.Expect(e1 => e1.IsProperMatcher(mailRule2)).Return(false);
            matcher1.Expect(e1 => e1.IsProperMatcher(mailRule3)).Return(false);
            matcher1.Expect(e1 => e1.IsProperMatcher(mailRule4)).Return(false);

            // Matcher2 does not evaluate rule 1, accepts rule 2, refuses rules 3 and 4
            matcher2.Expect(e2 => e2.IsProperMatcher(mailRule1)).Return(false);
            matcher2.Expect(e2 => e2.IsProperMatcher(mailRule2)).Return(true);
            matcher2.Expect(e2 => e2.IsProperMatcher(mailRule3)).Return(true);
            matcher2.Expect(e2 => e2.IsProperMatcher(mailRule4)).Return(true);
            matcher2.Expect(e2 => e2.ShouldBeRun(mailRule2, startTime)).Return(true);
            matcher2.Expect(e2 => e2.ShouldBeRun(mailRule3, startTime)).Return(false);
            matcher2.Expect(e2 => e2.ShouldBeRun(mailRule4, startTime)).Return(false);

            // Matcher3 rejects rule 1, accepts rules 2 and 3, rejects rule 4
            matcher3.Expect(e3 => e3.IsProperMatcher(mailRule1)).Return(true);
            matcher3.Expect(e3 => e3.IsProperMatcher(mailRule2)).Return(true);
            matcher3.Expect(e3 => e3.IsProperMatcher(mailRule3)).Return(true);
            matcher3.Expect(e3 => e3.IsProperMatcher(mailRule4)).Return(true);
            matcher3.Expect(e3 => e3.ShouldBeRun(mailRule1, startTime)).Return(false);
            matcher3.Expect(e3 => e3.ShouldBeRun(mailRule2, startTime)).Return(true);
            matcher3.Expect(e3 => e3.ShouldBeRun(mailRule3, startTime)).Return(true);
            matcher3.Expect(e3 => e3.ShouldBeRun(mailRule4, startTime)).Return(false);

            // Act
            this.ruleMatcher = new RuleMatcher(matchers);
            var result = this.ruleMatcher.GetMatchedRules(mailRules, startTime);

            // Assert
            Assert.AreEqual(result.Count, 2);
            Assert.IsFalse(result.Contains(mailRule1));
            Assert.IsTrue(result.Contains(mailRule2));
            Assert.IsTrue(result.Contains(mailRule3));
            Assert.IsFalse(result.Contains(mailRule4));
        }
        public void GetMailRulesNotEliminatedRejectsMailRuleIfAnyEliminatorRejectsIt()
        {
            // Assemble
            var startTime = DateTime.Now;
            var mailRule1 = new MailRule();
            var mailRule2 = new MailRule();
            var mailRule3 = new MailRule();
            var mailRule4 = new MailRule();
            var mailRules = new List <MailRule> {
                mailRule1, mailRule2, mailRule3, mailRule4
            };

            var eliminator1 = MockRepository.GenerateStrictMock <IMailRuleEliminator>();
            var eliminator2 = MockRepository.GenerateStrictMock <IMailRuleEliminator>();
            var eliminator3 = MockRepository.GenerateStrictMock <IMailRuleEliminator>();
            var eliminators = new List <IMailRuleEliminator> {
                eliminator1, eliminator2, eliminator3
            };

            // Eliminator1 is not proper for any mail rule.
            eliminator1.Expect(e1 => e1.IsProperEliminator(mailRule1)).Return(false);
            eliminator1.Expect(e1 => e1.IsProperEliminator(mailRule2)).Return(false);
            eliminator1.Expect(e1 => e1.IsProperEliminator(mailRule3)).Return(false);
            eliminator1.Expect(e1 => e1.IsProperEliminator(mailRule4)).Return(false);

            // Eliminator2 does not evaluate rule 1, rejects rule 2, passes rules 3 and 4
            eliminator2.Expect(e2 => e2.IsProperEliminator(mailRule1)).Return(false);
            eliminator2.Expect(e2 => e2.IsProperEliminator(mailRule2)).Return(true);
            eliminator2.Expect(e2 => e2.IsProperEliminator(mailRule3)).Return(true);
            eliminator2.Expect(e2 => e2.IsProperEliminator(mailRule4)).Return(true);
            eliminator2.Expect(e2 => e2.ShouldBeEliminated(mailRule2, startTime)).Return(true);
            eliminator2.Expect(e2 => e2.ShouldBeEliminated(mailRule3, startTime)).Return(false);
            eliminator2.Expect(e2 => e2.ShouldBeEliminated(mailRule4, startTime)).Return(false);

            // Eliminator3 passes rule 1, rejects rules 2 and 3, passes rule 4
            eliminator3.Expect(e3 => e3.IsProperEliminator(mailRule1)).Return(true);
            eliminator3.Expect(e3 => e3.IsProperEliminator(mailRule2)).Return(true);
            eliminator3.Expect(e3 => e3.IsProperEliminator(mailRule3)).Return(true);
            eliminator3.Expect(e3 => e3.IsProperEliminator(mailRule4)).Return(true);
            eliminator3.Expect(e3 => e3.ShouldBeEliminated(mailRule1, startTime)).Return(false);
            eliminator3.Expect(e3 => e3.ShouldBeEliminated(mailRule2, startTime)).Return(true);
            eliminator3.Expect(e3 => e3.ShouldBeEliminated(mailRule3, startTime)).Return(true);
            eliminator3.Expect(e3 => e3.ShouldBeEliminated(mailRule4, startTime)).Return(false);

            // Act
            this.ruleEliminator = new RuleEliminator(eliminators);
            var result = this.ruleEliminator.GetMailRulesNotEliminated(mailRules, startTime);

            // Assert
            Assert.AreEqual(result.Count, 2);
            Assert.IsTrue(result.Contains(mailRule1));
            Assert.IsFalse(result.Contains(mailRule2));
            Assert.IsFalse(result.Contains(mailRule3));
            Assert.IsTrue(result.Contains(mailRule4));
        }
예제 #4
0
        public void IsProperEliminatorReturnsTrueForAllRules()
        {
            // Assemble
            var mailRule = new MailRule();

            // Act
            var result = this.eliminator.IsProperEliminator(mailRule);

            // Assert
            Assert.IsTrue(result);
        }
예제 #5
0
        public void IsProperEliminatorReturnsFalseIfRuleStartDateNotSet()
        {
            // Assemble
            var mailRule = new MailRule {
                StartDate = null
            };

            // Act
            var result = this.eliminator.IsProperEliminator(mailRule);

            // Assert
            Assert.IsFalse(result);
        }
        public void IsProperHandlerReturnsFalseIfRuleDayNumberDoesNotHaveValue()
        {
            // Assemble
            var mailRule = new MailRule {
                MailPattern = MailPattern.Yearly, DayNumber = null
            };

            // Act
            var result = this.matcher.IsProperMatcher(mailRule);

            // Assert
            Assert.IsFalse(result);
        }
        /// <summary>
        /// Determines if a rule matches the SubRule.
        /// </summary>
        /// <param name="rule">The MailRule to be evaluated.</param>
        /// <param name="startTime">The time at which the process started.</param>
        /// <returns>A value indicating whether the rule matches the SubRule.</returns>
        public bool ShouldBeRun(MailRule rule, DateTime startTime)
        {
            return(rule.DayNumber.Value == startTime.GetWeekOfMonth());

            var weekOfMonth = startTime.GetWeekOfMonth();

            if (new DateTime(startTime.Year, startTime.Month, 1).DayOfWeek > startTime.DayOfWeek)
            {
                weekOfMonth--;
            }

            return(rule.DayNumber.Value == weekOfMonth);
        }
        public void IsProperHandlerReturnsFalseIfRuleMailPatternIsNotYearly(MailPattern mailPattern)
        {
            // Assemble
            var mailRule = new MailRule {
                MailPattern = mailPattern, DayNumber = 4
            };

            // Act
            var result = this.matcher.IsProperMatcher(mailRule);

            // Assert
            Assert.IsFalse(result);
        }
        public void IsProperEliminatorReturnsTrueIfRuleEndDateSet()
        {
            // Assemble
            var mailRule = new MailRule {
                EndDate = DateTime.Today
            };

            // Act
            var result = this.eliminator.IsProperEliminator(mailRule);

            // Assert
            Assert.IsTrue(result);
        }
        public void IsProperHandlerReturnsFalseIfRuleMaxRecurrencesNotSet()
        {
            // Assemble
            var mailRule = new MailRule {
                MaxOccurences = null
            };

            // Act
            var result = this.eliminator.IsProperEliminator(mailRule);

            // Assert
            Assert.IsFalse(result);
        }
예제 #11
0
        public void IsProperHandlerReturnsTrueIfRuleStartDateIsSet()
        {
            // Assemble
            var mailRule = new MailRule {
                StartDate = DateTime.Now
            };

            // Act
            var result = this.eliminator.IsProperEliminator(mailRule);

            // Assert
            Assert.IsTrue(result);
        }
예제 #12
0
        public void ShouldBeRunReturnsTrueOnSecondMondayOfMonthWhenDayNumberIsTwo()
        {
            // Assemble
            var startTime = new DateTime(2014, 7, 14);
            var mailRule  = new MailRule {
                DayNumber = 2
            };

            // Act
            var result = this.subMatcher.ShouldBeRun(mailRule, startTime);

            // Assert
            Assert.IsTrue(result);
        }
        public void ShouldBeEliminatedReturnsFalseIfMailRuleIsActive()
        {
            // Assemble
            var mailRule = new MailRule {
                IsActive = true
            };
            var startTime = DateTime.Today;

            // Act
            var result = this.eliminator.ShouldBeEliminated(mailRule, startTime);

            // Assert
            Assert.IsFalse(result);
        }
예제 #14
0
        public void ShouldBeRunReturnsFalseInFourthWeekOfMonthWhenDayNumberIsTwo()
        {
            // Assemble
            var startTime = new DateTime(2014, 6, 22);
            var mailRule  = new MailRule {
                DayNumber = 2
            };

            // Act
            var result = this.subMatcher.ShouldBeRun(mailRule, startTime);

            // Assert
            Assert.IsFalse(result);
        }
        public void ShouldBeRunReturnsFalseIfStartTimeMonthIsGreaterThanMailRuleMonth()
        {
            // Assemble
            var       startTime = new DateTime(2014, 6, 14);
            const int Month     = 5;
            var       mailRule  = new MailRule {
                Month = Month
            };

            // Act
            var result = this.subMatcher.ShouldBeRun(mailRule, startTime);

            // Assert
            Assert.IsFalse(result);
        }
        public void ShouldBeRunReturnsFalseIfNumberOfExceedsYearsSeperatingLastSentAndStartTime()
        {
            // Assemble
            var lastSent = new DateTime(2014, 6, 1);
            var mailRule = new MailRule {
                LastSent = lastSent, NumberOf = 2
            };
            var startTime = new DateTime(2015, 12, 15);

            // Act
            var result = this.subMatcher.ShouldBeRun(mailRule, startTime);

            // Assert
            Assert.IsFalse(result);
        }
        public void ShouldBeRunReturnsFalseIfStillInSameYearAsLastSent()
        {
            // Assemble
            var lastSent = new DateTime(2014, 6, 1);
            var mailRule = new MailRule {
                LastSent = lastSent, NumberOf = 2
            };
            var startTime = new DateTime(2014, 12, 15);

            // Act
            var result = this.subMatcher.ShouldBeRun(mailRule, startTime);

            // Assert
            Assert.IsFalse(result);
        }
        public void ShouldBeRunReturnsTrueIfStartTimeMonthIsGreaterThanNumberOfMonthsSinceStartTime()
        {
            // Assemble
            var lastSent = new DateTime(2014, 6, 1);
            var mailRule = new MailRule {
                LastSent = lastSent, NumberOf = 1
            };
            var startTime = new DateTime(2014, 8, 23);

            // Act
            var result = this.subMatcher.ShouldBeRun(mailRule, startTime);

            // Assert
            Assert.IsTrue(result);
        }
        public void ShouldBeRunReturnsTrueIfStartTimeYearIsEqualToNumberOfYearsSinceStartTime()
        {
            // Assemble
            var lastSent = new DateTime(2014, 6, 1);
            var mailRule = new MailRule {
                LastSent = lastSent, NumberOf = 2
            };
            var startTime = new DateTime(2016, 1, 4);

            // Act
            var result = this.subMatcher.ShouldBeRun(mailRule, startTime);

            // Assert
            Assert.IsTrue(result);
        }
        public void IsProperHandlerReturnsTrueIfRuleMailPatternIsYearlyAndRuleIsNotDayOfWeekRestrictedAndRuleDayNumberHasValue()
        {
            // Assemble
            var mailRule = new MailRule {
                MailPattern = MailPattern.Yearly, DayNumber = 4
            };

            Assert.IsFalse(mailRule.IsDayOfWeekRestricted, "Test is not configured properly");

            // Act
            var result = this.matcher.IsProperMatcher(mailRule);

            // Assert
            Assert.IsTrue(result);
        }
        public void ShouldBeRunReturnsFalseIfStartTimeDayOfWeekIsListedAsDoNotRunInMailRule()
        {
            // Assemble
            var mailRule = new MailRule();

            mailRule.DaysOfWeek.Add(DayOfWeek.Tuesday, false);
            mailRule.DaysOfWeek.Add(DayOfWeek.Friday, true);
            var startTime = new DateTime(2014, 6, 24);

            Assert.IsTrue(startTime.DayOfWeek == DayOfWeek.Tuesday, "Test is not valid");

            // Act
            var result = this.subMatcher.ShouldBeRun(mailRule, startTime);

            // Assert
            Assert.IsFalse(result);
        }
예제 #22
0
        public void IsProperHandlerReturnsFalseIfRuleMailPatternIsNotWeekly(MailPattern mailPattern)
        {
            // Assemble
            var mailRule = new MailRule
            {
                MailPattern = mailPattern,
                DaysOfWeek  = new Dictionary <DayOfWeek, bool> {
                    { DayOfWeek.Thursday, true }
                }
            };

            // Act
            var result = this.matcher.IsProperMatcher(mailRule);

            // Assert
            Assert.IsFalse(result);
        }
        public void ShouldBeRunReturnsTrueIfStartTimeDayOfWeekIsInMailRuleDaysOfWeek()
        {
            // Assemble
            var mailRule = new MailRule();

            mailRule.DaysOfWeek.Add(DayOfWeek.Monday, true);
            mailRule.DaysOfWeek.Add(DayOfWeek.Friday, true);
            var startTime = new DateTime(2014, 6, 23);

            Assert.IsTrue(startTime.DayOfWeek == DayOfWeek.Monday, "Test is not valid");

            // Act
            var result = this.subMatcher.ShouldBeRun(mailRule, startTime);

            // Assert
            Assert.IsTrue(result);
        }
        public void ShouldBeRunReturnsFalseIfDayNumberIsLessThanStartTimeDay()
        {
            // Assemble
            const int DayNumber = 14;
            var       mailRule  = new MailRule {
                DayNumber = DayNumber
            };
            var startTime = new DateTime(2014, 6, 15);

            Assert.IsTrue(DayNumber < startTime.Day);

            // Act
            var result = this.subMatcher.ShouldBeRun(mailRule, startTime);

            // Assert
            Assert.IsFalse(result);
        }
예제 #25
0
        public void IsProperHandlerReturnsTrueIfRuleDayNumberHasValueAndRuleIsDayOfWeekRestrictedAndRuleMailPatternIsYearly()
        {
            // Assemble
            var mailRule = new MailRule
            {
                MailPattern = MailPattern.Yearly,
                DaysOfWeek  = new Dictionary <DayOfWeek, bool> {
                    { DayOfWeek.Tuesday, true }
                },
                DayNumber = 4
            };

            // Act
            var result = this.matcher.IsProperMatcher(mailRule);

            // Assert
            Assert.IsTrue(result);
        }
예제 #26
0
        public void ShouldBeEliminatedReturnsFalseIfStartDateIsEqualToStartTime()
        {
            // Assemble
            var startTime = new DateTime(2014, 6, 16);
            var startDate = new DateTime(2014, 6, 16);

            Assert.IsTrue(startDate.Date == startTime.Date, "Test is not Valid");

            var mailRule = new MailRule {
                StartDate = startDate
            };

            // Act
            var result = this.eliminator.ShouldBeEliminated(mailRule, startTime);

            // Assert
            Assert.IsFalse(result);
        }
예제 #27
0
        public void IsProperHandlerReturnsFalseIfRuleDayNumberDoesNotHaveValue()
        {
            // Assemble
            var mailRule = new MailRule
            {
                MailPattern = MailPattern.Yearly,
                DaysOfWeek  = new Dictionary <DayOfWeek, bool> {
                    { DayOfWeek.Tuesday, true }
                },
                DayNumber = null
            };

            // Act
            var result = this.matcher.IsProperMatcher(mailRule);

            // Assert
            Assert.IsFalse(result);
        }
예제 #28
0
        public void IsProperHandlerReturnsFalseIfRuleIsNotDayOfWeekRestricted()
        {
            // Assemble
            var mailRule = new MailRule
            {
                MailPattern = MailPattern.Yearly,
                DaysOfWeek  = new Dictionary <DayOfWeek, bool> {
                    { DayOfWeek.Tuesday, false }
                },
                DayNumber = 4
            };

            // Act
            var result = this.matcher.IsProperMatcher(mailRule);

            // Assert
            Assert.IsFalse(result);
        }
        public void ShouldBeEliminatedReturnsTrueIfStartTimeIsPastToEndDate()
        {
            // Assemble
            var startTime = new DateTime(2014, 6, 14);
            var endDate   = new DateTime(2014, 6, 13);

            Assert.IsTrue(endDate < startTime, "Test is not Valid");

            var mailRule = new MailRule {
                EndDate = endDate
            };

            // Act
            var result = this.eliminator.ShouldBeEliminated(mailRule, startTime);

            // Assert
            Assert.IsTrue(result);
        }
예제 #30
0
        public void ShouldBeEliminatedReturnsTrueIfLastSentEqualsStartDate()
        {
            // Assemble
            var startTime = new DateTime(2014, 6, 14);
            var lastSent  = new DateTime(2014, 6, 14);

            Assert.IsTrue(lastSent == startTime, "Test is not Valid");

            var mailRule = new MailRule {
                LastSent = lastSent
            };

            // Act
            var result = this.eliminator.ShouldBeEliminated(mailRule, startTime);

            // Assert
            Assert.IsTrue(result);
        }