Exemple #1
0
        /// <summary>
        /// Validates an action
        /// </summary>
        /// <typeparam name="TAction">The type of the action.</typeparam>
        /// <typeparam name="TObject">The type of the object.</typeparam>
        /// <param name="validate">The validate.</param>
        /// <returns></returns>
        public ValidationResult Validate <TAction, TObject>(TAction validate) where TAction : SystemAction <TObject>
        {
            FluentValidation.Results.ValidationResult validationResult;
            if (validate.ActionAgainst == null)
            {
                validationResult = new FluentValidation.Results.ValidationResult();
                validationResult.Errors.Add(new ValidationFailure("ActionObject", "Please provide an object"));
            }
            else
            {
                try
                {
                    validationResult = GetValidator <TAction, TObject>()
                                       .Validate(validate.ActionAgainst);
                }
                catch (ComponentNotRegisteredException)
                {
                    try
                    {
                        validationResult = GetValidator <TAction>()
                                           .Validate(validate);
                    }
                    catch (ComponentNotRegisteredException)
                    {
                        return(new ValidationResult());
                    }
                }
            }

            return(FluentConverter.ToProjectValidationResult(validationResult));
        }
Exemple #2
0
        /// <summary>
        /// Validates any object
        /// </summary>
        /// <typeparam name="TObject">The type of the object.</typeparam>
        /// <param name="validate">The validate.</param>
        /// <returns></returns>
        public ValidationResult Validate <TObject>(TObject validate)
        {
            FluentValidation.Results.ValidationResult validationResult;
            if (validate == null)
            {
                validationResult = new FluentValidation.Results.ValidationResult();
                validationResult.Errors.Add(new ValidationFailure("ActionObject", "Please provide some input"));
            }
            else
            {
                var validator = GetValidator <TObject>();
                validationResult = validator.Validate(validate);
            }

            return(FluentConverter.ToProjectValidationResult(validationResult));
        }