public void AggregateARuleSetWithValidRulesResultsInAValidResult() { ValidationAggregator testee = new ValidationAggregator(this.validationFactory, false); IRuleSet<IValidationRule> ruleSet = new ValidationRuleSet { this.mockery.NewMock<IValidationRule>(), this.mockery.NewMock<IValidationRule>() }; Expect.On(ruleSet[0]).Method("Evaluate").Will(Return.Value(new ValidationResult(true))); Expect.On(ruleSet[1]).Method("Evaluate").Will(Return.Value(new ValidationResult(true))); string logInfo; IValidationResult result = testee.Aggregate(ruleSet, out logInfo); Assert.IsTrue(result.Valid, "aggregated result has to be valid if all rules are valid."); }
public void AggregateARuleSetWithInvalidRulesResultsInAnInvalidResult() { ValidationAggregator testee = new ValidationAggregator(this.validationFactory, false); IRuleSet<IValidationRule> ruleSet = new ValidationRuleSet { this.mockery.NewMock<IValidationRule>(), this.mockery.NewMock<IValidationRule>() }; Expect.On(ruleSet[0]).Method("Evaluate").Will(Return.Value(new ValidationResult(true))); ValidationResult invalidResult = new ValidationResult(false); invalidResult.Violations.Add(new ValidationViolation("test")); Expect.On(ruleSet[1]).Method("Evaluate").Will(Return.Value(invalidResult)); string logInfo; IValidationResult result = testee.Aggregate(ruleSet, out logInfo); Assert.IsFalse(result.Valid, "aggregated result has to be valid if all rules are valid."); Assert.AreEqual(1, result.Violations.Count, "violation was not passed to result."); }
public void StopOnFirstViolation() { ValidationAggregator testee = new ValidationAggregator(this.validationFactory, true); IRuleSet<IValidationRule> ruleSet = new ValidationRuleSet { this.mockery.NewMock<IValidationRule>(), this.mockery.NewMock<IValidationRule>() }; Expect.On(ruleSet[0]).Method("Evaluate").Will(Return.Value(new ValidationResult(false))); ValidationResult invalidResult = new ValidationResult(false); invalidResult.Violations.Add(new ValidationViolation("test")); Expect.On(ruleSet[1]).Method("Evaluate").Will(Return.Value(invalidResult)); string logInfo; IValidationResult result = testee.Aggregate(ruleSet, out logInfo); Assert.IsFalse(result.Valid, "aggregated result has to be valid if all rules are valid."); Assert.AreEqual(0, result.Violations.Count, "the violation of the second rule should not be in the result because aggregation should have stopped on first invalid rule."); }