예제 #1
0
        public virtual void When_rule_is_declared_first_as_precondition_then_as_rule_it_is_only_evaluated_once()
        {
            var precondition = new MockValidationRule <string>(false);
            var rule         = Validate.That <string>(s => s.Length > 10);

            var plan = new ValidationPlan <string>
            {
                rule.When(precondition).WithErrorCode("too short"),
                precondition
            };

            var report = plan.Execute(null);

            foreach (var failure in report.Failures)
            {
                Console.WriteLine(failure);
            }

            Assert.AreEqual(1, precondition.CallCount);
        }
예제 #2
0
        public virtual void Intermediate_preconditions_that_return_false_prevent_later_rules_from_being_evaluated()
        {
            var a = Validate.That <string>(s => false);
            var b = new MockValidationRule <string>(false);
            var c = new MockValidationRule <string>(false);

            var plan = new ValidationPlan <string>
            {
                a,
                b.When(a),
                c.When(b)
            };

            var report = plan.Execute("");

            Console.WriteLine(report);

            Assert.AreEqual(0, b.CallCount);
            Assert.AreEqual(0, c.CallCount);
        }