public void RemoveRule_can_be_used_to_remove_a_rule_from_a_ValidatioPlan() { var notNull = Validate.That <string>(s => s != null); var notEmpty = Validate.That <string>(s => s != "").When(notNull); var plan = new ValidationPlan <string> { notNull, notEmpty }; Assert.That(plan.Check(""), Is.EqualTo(false)); plan.Remove(notEmpty); Assert.That(plan.Check(""), Is.EqualTo(true)); }
public void A_rule_removed_by_RemoveRule_can_still_be_dependend_on_by_another_rule() { var notNull = Validate.That <string>(s => s != null); var notEmpty = Validate.That <string>(s => s != "").When(notNull); var plan = new ValidationPlan <string> { notNull, notEmpty }; Assert.That(plan.Check(null), Is.EqualTo(false)); plan.Remove(notNull); Assert.That(plan.Check(null), Is.EqualTo(true)); }
public void Nested_validations_can_be_supported() { ValidationPlan <Account> accountValidator = new ValidationPlan <Account>() .ConfigureFromAttributes(); ValidationPlan <Order> orderValidator = new ValidationPlan <Order>() .ConfigureFromAttributes(); orderValidator.AddRule(o => accountValidator.Check(o.Account)); var order = new Order { Account = new Account() }; ValidationReport report = orderValidator.Execute(order); Assert.That(report.Failures.Any(f => f.Message == "What's your name?" && f.Target == order.Account)); Assert.That(report.Failures.Any(f => f.Message == "You can't place an order for nothing." && f.Target == order)); }