public static Param <short> IsLt(this Param <short> param, short limit)
        {
            if (param.Value >= limit)
            {
                throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsNotLt.Inject(param.Value, limit));
            }

            return(param);
        }
Example #2
0
        public static Param <bool> IsTrue(this Param <bool> param)
        {
            if (!param.Value)
            {
                throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsNotTrue);
            }

            return(param);
        }
Example #3
0
        public static Param <int> IsGreaterThanZero(this Param <int> param)
        {
            if (param.Value <= 0)
            {
                throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsNotGt.Inject(param.Value, 0));
            }

            return(param);
        }
Example #4
0
        public static Param <int> IsGreaterOrEqualTo(this Param <int> param, int limit)
        {
            if (!(param.Value >= limit))
            {
                throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsNotGte.Inject(param.Value, limit));
            }

            return(param);
        }
        public static Param <IDictionary <TKey, TValue> > HasItems <TKey, TValue>(this Param <IDictionary <TKey, TValue> > param)
        {
            if (param.Value == null || param.Value.Count < 1)
            {
                throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsEmptyCollection);
            }

            return(param);
        }
        public static Param <T[]> HasItems <T>(this Param <T[]> param)
        {
            if (param.Value == null || param.Value.Length < 1)
            {
                throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsEmptyCollection);
            }

            return(param);
        }
        public static Param <IEnumerable <T> > HasItems <T>(this Param <IEnumerable <T> > param)
        {
            if (param.Value == null || !param.Value.Any())
            {
                throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsEmptyCollection);
            }

            return(param);
        }
        public static Param <T> HasItems <T>(this Param <T> param) where T : class, ICollection
        {
            if (param.Value == null || param.Value.Count < 1)
            {
                throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsEmptyCollection);
            }

            return(param);
        }
        public static Param <decimal> IsGte(this Param <decimal> param, decimal limit)
        {
            if (!(param.Value >= limit))
            {
                throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsNotGte.Inject(param.Value, limit));
            }

            return(param);
        }
Example #10
0
        public static TypeParam IsOfType(this TypeParam param, Type type)
        {
            if (!param.Type.Equals(type))
            {
                throw ExceptionFactory.CreateForParamValidation(param.Name,
                                                                ExceptionMessages.EnsureExtensions_IsNotOfType.Inject(param.Type.FullName));
            }

            return(param);
        }
        public static Param <DateTime> IsInRange(this Param <DateTime> param, DateTime min, DateTime max)
        {
            if (param.Value < min)
            {
                throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsNotInRange_ToLow.Inject(param.Value, min));
            }

            if (param.Value > max)
            {
                throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsNotInRange_ToHigh.Inject(param.Value, max));
            }

            return(param);
        }
        public static Param <string> IsLongerThan(this Param <string> param, int minLength)
        {
            if (string.IsNullOrEmpty(param.Value))
            {
                throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsNotNullOrEmpty);
            }

            var length = param.Value.Length;

            if (length < minLength)
            {
                throw ExceptionFactory.CreateForParamValidation(param.Name, "The string is not long enough. Must be at least '{0}' but was '{1}' characters long.".Inject(minLength, length));
            }

            return(param);
        }
        public static Param <string> IsRelativePath(this Param <string> param)
        {
            if (string.IsNullOrWhiteSpace(param.Value))
            {
                throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsNotNullOrWhiteSpace);
            }

            if (!param.Value.EndsWith("\\"))
            {
                throw ExceptionFactory.CreateForParamValidation(param.Name, string.Format("value [{0}]  is not a valid relative path. relative paths must end with \\", param.Value));
            }

            if (param.Value.Length > 1 && param.Value.StartsWith("\\"))
            {
                throw ExceptionFactory.CreateForParamValidation(param.Name, string.Format("value [{0}]  is not a valid relative path. relative paths can not start with \\", param.Value));
            }

            return(param);
        }
        public static Param <string> IsValidPath(this Param <string> param)
        {
            if (string.IsNullOrWhiteSpace(param.Value))
            {
                throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsNotNullOrWhiteSpace);
            }

            if (param.Value.IsPathValid())
            {
                return(param);
            }

            if (OsInfo.IsWindows)
            {
                throw ExceptionFactory.CreateForParamValidation(param.Name, string.Format("value [{0}]  is not a valid Windows path. paths must be a full path eg. C:\\Windows", param.Value));
            }

            throw ExceptionFactory.CreateForParamValidation(param.Name, string.Format("value [{0}]  is not a valid *nix path. paths must start with /", param.Value));
        }
        public static Param <string> HasLengthBetween(this Param <string> param, int minLength, int maxLength)
        {
            if (string.IsNullOrEmpty(param.Value))
            {
                throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsNotNullOrEmpty);
            }

            var length = param.Value.Length;

            if (length < minLength)
            {
                throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsNotInRange_ToShort.Inject(minLength, maxLength, length));
            }

            if (length > maxLength)
            {
                throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsNotInRange_ToLong.Inject(minLength, maxLength, length));
            }

            return(param);
        }