예제 #1
0
        public void CheckRuleYieldsViolation()
        {
            BusinessRule target = new RuleThatAlwaysHasOneViolation();

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

            Assert.AreEqual(1, result.Count());
            Assert.IsTrue(result.Any(v => v.ViolationMessage == "Always one violation"));
        }
예제 #2
0
        public void AndOperator_CombinesRules_ViolationAreNotDistinct()
        {
            BusinessRule rule1 = new RuleThatAlwaysHasOneViolation();
            BusinessRule rule2 = new RuleThatAlwaysHasOneViolation();

            BusinessRule result = rule1 & rule2;

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

            Assert.AreEqual(2, violations.Count());
            Assert.IsTrue(violations.All(v => v.ViolationMessage == "Always one violation"));
        }
예제 #3
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"));
        }
예제 #4
0
        public void StaticThrowIfNotSatisfiedThrowsBusinessRuleViolationException()
        {
            BusinessRule target = new RuleThatAlwaysHasOneViolation();

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

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

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