Exemple #1
0
        public void Validation_should_return_aggregated_broken_rules()
        {
            var man         = new Man();
            var ruleResult1 = new RuleExecutionResult(new List <BrokenRule> {
                new BrokenRule(null, null, "", "", null)
            });
            var ruleResult2 = new RuleExecutionResult(new List <BrokenRule> {
                new BrokenRule(null, null, "", "", null), new BrokenRule(null, null, "", "", null)
            });

            var context = new TestValidationContext();

            var manRules = MockRuleSet <Man>();

            manRules.Expect(r => r.Validate(man)).Return(ruleResult1);
            context.AddRuleSet(manRules);

            var personRules = MockRuleSet <Person>();

            personRules.Expect(r => r.Validate(man)).Return(ruleResult2);
            context.AddRuleSet(personRules);

            var result = context.Validate(man);

            Assert.That(result.IsValid, Is.False);
            Assert.That(result.BrokenRules.Count, Is.EqualTo(3));
        }
Exemple #2
0
        public void Can_stop_validation()
        {
            var man        = new Man();
            var ruleResult = new RuleExecutionResult {
                StopEvaluation = true
            };

            var context = new TestValidationContext();

            var manRules = MockRuleSet <Man>();

            manRules.Expect(r => r.Validate(man)).Return(ruleResult);
            context.AddRuleSet(manRules);

            var personRules = MockRuleSet <Person>();

            personRules.Expect(r => r.Validate(man)).Repeat.Never();
            context.AddRuleSet(personRules);

            context.Validate(man);

            VerifyAll();
        }
Exemple #3
0
        public void Should_validate_against_each_matching_rulesets()
        {
            var man        = new Man();
            var ruleResult = new RuleExecutionResult();

            var context = new TestValidationContext();

            var personRules = MockRuleSet <Person>();

            personRules.Expect(r => r.Validate(man)).Return(ruleResult);
            context.AddRuleSet(personRules);

            var manRules = MockRuleSet <Man>();

            manRules.Expect(r => r.Validate(man)).Return(ruleResult);
            context.AddRuleSet(manRules);

            var maleRules = MockRuleSet <IMale>();

            maleRules.Expect(r => r.Validate(man)).Return(ruleResult);
            context.AddRuleSet(maleRules);

            var sentientRules = MockRuleSet <ISentient>();

            sentientRules.Expect(r => r.Validate(man)).Return(ruleResult);
            context.AddRuleSet(sentientRules);

            // unrelated
            var itemRules = MockRuleSet <Item>();

            itemRules.Expect(r => r.Validate(man)).Repeat.Never();
            context.AddRuleSet(itemRules);

            context.Validate(man);

            VerifyAll();
        }