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")); }
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")); }
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")); }
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")); }