Exemplo n.º 1
0
        private static Func <IEnumerable <SpecificationProperty>, IEnumerable <Error> > EnforceRequired()
        {
            return(specProps =>
            {
                var setsWithTrue =
                    specProps
                    .Where(sp => sp.Specification.IsOption() &&
                           sp.Value.IsJust() && sp.Specification.Required)
                    .Select(s => ((OptionSpecification)s.Specification).SetName).ToList();

                var requiredButEmpty =
                    specProps
                    .Where(sp => sp.Specification.IsOption())
                    .Where(sp => sp.Value.IsNothing() &&
                           sp.Specification.Required &&
                           !setsWithTrue.Contains(((OptionSpecification)sp.Specification).SetName))
                    .Concat(specProps
                            .Where(sp => sp.Specification.IsValue() &&
                                   sp.Value.IsNothing() &&
                                   sp.Specification.Required)).ToList();
                if (requiredButEmpty.Any())
                {
                    return requiredButEmpty.Select(s => new MissingRequiredOptionError(
                                                       NameExtensions.FromSpecification(s.Specification)));
                }
                return Enumerable.Empty <Error>();
            });
        }
Exemplo n.º 2
0
 private static Func <IEnumerable <SpecificationProperty>, IEnumerable <Error> > EnforceRange()
 {
     return(specProps =>
     {
         var options = specProps.Where(
             sp => sp.Specification.TargetType == TargetType.Sequence &&
             sp.Value.IsJust() &&
             (
                 (sp.Specification.Min.IsJust() && ((Array)sp.Value.FromJust()).Length < sp.Specification.Min.FromJust()) ||
                 (sp.Specification.Max.IsJust() && ((Array)sp.Value.FromJust()).Length > sp.Specification.Max.FromJust())
             )
             );
         if (options.Any())
         {
             return options.Select(s => new SequenceOutOfRangeError(
                                       NameExtensions.FromSpecification(s.Specification)));
         }
         return Enumerable.Empty <Error>();
     });
 }