Ejemplo n.º 1
0
 public static IEnumerable <ValidationRuleError> Check(CandidateValidation candidate)
 {
     foreach (var source in candidate.Fields)
     {
         if (!TypeCompatibility.Check(source))
         {
             var errorMessage = DescribeTypeMismatch(candidate, source);
             yield return(new ValidationRuleError(errorMessage));
         }
     }
 }
Ejemplo n.º 2
0
        private static string DescribeTypeMismatch(CandidateValidation candidate, ValidationFieldSource source)
        {
            var targetFieldRef      = source.TargetField.TargetFieldInfo.Field.Describe();
            var targetType          = source.Target.GetType().Name;
            var targetFieldType     = source.TargetField.TargetFieldInfo.Type.Name;
            var validationDesc      = $"{candidate.Validation.ContainingType.Name}.{candidate.Validation.Method.Name}";
            var validationParamRef  = source.Field.Name;
            var validationParamType = source.Field.Type.Name;
            var errorMessage        =
                $"{targetFieldRef} on {targetType} has type {targetFieldType} which is not compatible with validation {validationDesc}'s {validationParamRef} which requires {validationParamType}";

            return(errorMessage);
        }
 public CandidateValidation(ValidationFieldSource extraFieldSource, CandidateValidation candidateValidation)
 {
     Validation = candidateValidation.Validation;
     Fields     = candidateValidation.Fields.Concat(Enumerate(extraFieldSource)).ToList();
 }
Ejemplo n.º 4
0
        public RequiredValidation(CandidateValidation candidateValidation)
        {
            Validation = candidateValidation.Validation;

            Targets = candidateValidation.Fields.Select(f => f.Target).Distinct().ToList();
        }