Ejemplo n.º 1
0
        /// <summary>
        /// Allows the definition of an inline specification to be applied to each item in a collection.
        /// </summary>
        /// <example>
        /// Check(cust => cust.ContactCollection).Required()
        ///     .ForEachSpecification&ltContact&gt( spec => spec.Check(c =&gt c.LastName).Required(), "Contacts" );
        /// </example>
        /// <typeparam name="TCollectionType">The type of instances contained in the collection.</typeparam>
        /// <param name="rules"><see cref="Action&lt;Validates&lt;TCollectionType&gt;&gt;"/></param>
        /// <param name="itemName">Name of property to use in notification message.</param>
        /// <returns><see cref="IAndOr&lt;T, TProperty&gt;"/></returns>
        public IAndOr <T, TProperty> ForEachSpecification <TCollectionType>(Action <Validates <TCollectionType> > rules, string itemName)
        {
            var specification = new SpecificationExpression <TCollectionType>();

            rules(specification);
            var specRule = new ForEachSpecificationRule <T, TProperty, TCollectionType>(specification, itemName);

            return(AddRuleAndReturnActionJoin(specRule));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets Specification used to validate this Property to the Default
        /// </summary>
        /// <returns><see cref="IAndOr&lt;T, TProperty&gt;"/></returns>
        public IAndOr <T, TProperty> Specification(Action <Validates <TProperty> > rules)
        {
            var specification = new SpecificationExpression <TProperty>();

            rules(specification);
            var specRule = new SpecificationRule <T, TProperty>(specification);

            return(AddRuleAndReturnActionJoin(specRule));
        }
Ejemplo n.º 3
0
        public static void Assert(Action<Validates<object>> rules)
        {
            var spec = new SpecificationExpression<object>(rules);

            var vn = ValidationCatalog.Validate(spec.Instance, spec);

            //var vn = spec.Validate(spec.Instance);
            if (!vn.IsValid)
            {
                throw new ValidationException("Invalid " + spec.Instance.GetType().ToString(), vn);
            }
        }
Ejemplo n.º 4
0
 public static ValidationNotification Validate(Action<Validates<object>> rules)
 {
     var spec = new SpecificationExpression<object>(rules);
     return spec.Validate(spec.Instance);
 }