public void register_simple_rules_by_filter() { theSource = new LambdaFieldValidationSource(new RequiredFieldRule()); theSource.If(a => a.Name.StartsWith("Address")); rulesFor(x => x.Name).Any().ShouldBeFalse(); rulesFor(x => x.Address1).Single().ShouldBeOfType<RequiredFieldRule>(); rulesFor(x => x.Address2).Single().ShouldBeOfType<RequiredFieldRule>(); }
public void register_simple_rules_by_filter() { theSource = new LambdaFieldValidationSource(new RequiredFieldRule()); theSource.If(a => a.Name.StartsWith("Address")); rulesFor(x => x.Name).Any().ShouldBeFalse(); rulesFor(x => x.Address1).Single().ShouldBeOfType <RequiredFieldRule>(); rulesFor(x => x.Address2).Single().ShouldBeOfType <RequiredFieldRule>(); }
public void register_simple_rules_by_rule_func() { theSource = new LambdaFieldValidationSource(a => { var length = int.Parse(a.Name.Substring(7, 1)); return new MaximumLengthRule(length); }); theSource.If(a => a.Name.StartsWith("Address")); rulesFor(x => x.Name).Any().ShouldBeFalse(); rulesFor(x => x.Address1).Single().ShouldBeOfType<MaximumLengthRule>().Length.ShouldEqual(1); rulesFor(x => x.Address2).Single().ShouldBeOfType<MaximumLengthRule>().Length.ShouldEqual(2); }
public void register_simple_rules_by_rule_func() { theSource = new LambdaFieldValidationSource(a => { var length = int.Parse(a.Name.Substring(7, 1)); return(new MaximumLengthRule(length)); }); theSource.If(a => a.Name.StartsWith("Address")); rulesFor(x => x.Name).Any().ShouldBeFalse(); rulesFor(x => x.Address1).Single().ShouldBeOfType <MaximumLengthRule>().Length.ShouldEqual(1); rulesFor(x => x.Address2).Single().ShouldBeOfType <MaximumLengthRule>().Length.ShouldEqual(2); }