Beispiel #1
0
        public ValidatorExtentionsTests()
        {
            var validator = new InlineValidator <Address>();

            _builder = validator.RuleFor(x => x.Country);
            _builder.Configure(_ => { });
        }
Beispiel #2
0
        public void Property_should_return_null_when_it_is_not_a_property_being_validated()
        {
            builder = _validator.RuleFor(x => "Foo");
            IValidationRule <Person, string> rule = null;

            builder.Configure(r => rule = r);
            rule.Member.ShouldBeNull();
        }
Beispiel #3
0
 public static IRuleBuilderInitial <T, TProperty> When <T, TProperty>(this IRuleBuilderInitial <T, TProperty> rule, Func <T, bool> predicate, ApplyConditionTo applyConditionTo = ApplyConditionTo.AllValidators)
 {
     return(rule.Configure(config =>
     {
         PropertyRule propertyRule = config;
         int num = (int)applyConditionTo;
         propertyRule.ApplyCondition(ctx => predicate((T)ctx.InstanceToValidate), (ApplyConditionTo)num);
     }));
 }
Beispiel #4
0
 /// <summary>
 /// Transforms the property value before validation occurs. The transformed value must be of the same type as the input value.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <typeparam name="TProperty"></typeparam>
 /// <param name="ruleBuilder"></param>
 /// <param name="transformationFunc"></param>
 /// <returns></returns>
 public static IRuleBuilderInitial <T, TProperty> Transform <T, TProperty>(this IRuleBuilderInitial <T, TProperty> ruleBuilder, Func <TProperty, TProperty> transformationFunc)
 {
     return(ruleBuilder.Configure(cfg => {
         cfg.Transformer = transformationFunc.CoerceToNonGeneric();
     }));
 }
Beispiel #5
0
 /// <summary>
 /// Specifies the cascade mode for failures.
 /// If set to 'Stop' then execution of the rule will stop once the first validator in the chain fails.
 /// If set to 'Continue' then all validators in the chain will execute regardless of failures.
 /// </summary>
 public static IRuleBuilderInitial <T, TProperty> Cascade <T, TProperty>(this IRuleBuilderInitial <T, TProperty> ruleBuilder, CascadeMode cascadeMode)
 {
     return(ruleBuilder.Configure(cfg => {
         cfg.CascadeMode = cascadeMode;
     }));
 }
Beispiel #6
0
 public RuleBuilderTests()
 {
     _validator = new InlineValidator <Person>();
     builder    = _validator.RuleFor(x => x.Surname);
     builder.Configure(rule => _rule = rule);
 }