public void Can_add_and_use_prebuilt_rule_set() { var context = new TestValidationContext(); var set = MockRuleSet <Person>(); context.AddRuleSet(set); var result = context.GetRuleSetsForType <Person>(); Assert.That(result[0], Is.EqualTo(set)); }
public void Should_use_all_matching_rule_sets() { var context = new TestValidationContext(); context.AddRuleSet <Person>(new List <IRule>()); context.AddRuleSet <Man>(new List <IRule>()); context.AddRuleSet <IMale>(new List <IRule>()); context.AddRuleSet <ISentient>(new List <IRule>()); context.AddRuleSet <Item>(new List <IRule>()); // unrelated var results = context.GetRuleSetsForType <Man>(); Assert.That(results.Count, Is.EqualTo(4)); }
public void Should_order_matching_rulesets_by_specificity() { var context = new TestValidationContext(); context.AddRuleSet <Person>(new List <IRule>()); context.AddRuleSet <Man>(new List <IRule>()); context.AddRuleSet <IMale>(new List <IRule>()); context.AddRuleSet <ISentient>(new List <IRule>()); var results = context.GetRuleSetsForType <Man>(); Assert.That(results[0].ValidatedType, Is.EqualTo(typeof(Man))); Assert.That(results[1].ValidatedType, Is.EqualTo(typeof(IMale))); Assert.That(results[2].ValidatedType, Is.EqualTo(typeof(Person))); Assert.That(results[3].ValidatedType, Is.EqualTo(typeof(ISentient))); }