Пример #1
0
        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.");
        }
Пример #2
0
        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.");
        }
Пример #3
0
        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.");
        }