Esempio n. 1
0
        public void CheckRuleYieldsAllViolations()
        {
            BusinessRule target = new RuleThatAlwaysHasTwoViolations();

            IEnumerable <BusinessRuleViolation> result = target.CheckRule();

            Assert.AreEqual(2, result.Count());
            Assert.IsTrue(result.Any(v => v.ViolationMessage == "First violation"));
            Assert.IsTrue(result.Any(v => v.ViolationMessage == "Second violation"));
        }
Esempio n. 2
0
        public void AndOperator_CombinesRules_AndResultsInViolationListThatIncludeBoth()
        {
            BusinessRule rule1 = new RuleThatAlwaysHasOneViolation();
            BusinessRule rule2 = new RuleThatAlwaysHasTwoViolations();

            BusinessRule result = rule1 & rule2;

            IEnumerable <BusinessRuleViolation> violations = result.CheckRule();

            Assert.AreEqual(3, violations.Count());
            Assert.IsTrue(violations.Any(v => v.ViolationMessage == "Always one violation"));
            Assert.IsTrue(violations.Any(v => v.ViolationMessage == "First violation"));
            Assert.IsTrue(violations.Any(v => v.ViolationMessage == "Second violation"));
        }
Esempio n. 3
0
        public void StaticThrowIfNotSatisfiedThrowsBusinessRuleViolationExceptionWithAllViolations()
        {
            BusinessRule target = new RuleThatAlwaysHasTwoViolations();

            Action act = () =>
            {
                BusinessRule.ThrowIfNotSatisfied(target);
            };

            var ex = Assert.ThrowsException <BusinessRuleViolationException>(act);

            Assert.AreEqual("Rule Violations: 2 violations have been detected.", ex.Message);
            Assert.AreEqual(2, ex.Violations.Count());
            Assert.IsTrue(ex.Violations.Any(v => v.ViolationMessage == "First violation"));
            Assert.IsTrue(ex.Violations.Any(v => v.ViolationMessage == "Second violation"));
        }