Example #1
0
        public static void Range(bool rangeCondition, string parameterName, string message)
        {
            Expect.NotNullOrEmpty(parameterName);

            if (!rangeCondition)
            {
                throw new ArgumentOutOfRangeException(parameterName, message);
            }
        }
Example #2
0
        public static void True(bool testCondition, string parameterName, string message)
        {
            Expect.NotNullOrEmpty(parameterName);

            if (!testCondition)
            {
                throw new ArgumentException(message, parameterName);
            }
        }
Example #3
0
        public static void True(bool testCondition, string parameterName)
        {
            Expect.NotNullOrEmpty(parameterName);

            if (!testCondition)
            {
                throw new ArgumentException(Strings.Argument_TestFailed, parameterName);
            }
        }
Example #4
0
        public static void NotWhiteSpace(string value, string parameterName)
        {
            Expect.NotNullOrEmpty(parameterName);

            if (Check.IsWhiteSpace(value))
            {
                throw new ArgumentException(Strings.Argument_WhiteSpaceString, parameterName);
            }
        }
Example #5
0
        /// <summary>
        /// Validates that the specified argument is in a given range, range borders included.
        /// </summary>
        /// <typeparam name="T">The type of <paramref name="value"/>.</typeparam>
        /// <param name="value">The argument to check.</param>
        /// <param name="minInclusive">The minimum value (inclusive).</param>
        /// <param name="maxInclusive">The maximum value (inclusive).</param>
        /// <param name="parameterName">The name of the parameter.</param>
        /// <exception cref="ArgumentException">Thrown if <paramref name="minInclusive"/> is greater than
        /// or equal to <paramref name="maxInclusive"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="value"/> is outside
        /// the allowable range of values.</exception>
        public static void Range <T>(T value, T minInclusive, T maxInclusive, string parameterName)
            where T : struct, IComparable <T>
        {
            // We only accept generics of value type; adding reference types would make
            // each method check too many things at a time (null-checks).
            Expect.True(minInclusive.CompareTo(maxInclusive) <= 0);
            Expect.NotNullOrEmpty(parameterName);

            if (value.CompareTo(minInclusive) < 0 || value.CompareTo(maxInclusive) > 0)
            {
                throw new ArgumentOutOfRangeException(
                          parameterName,
                          value,
                          String.Format(
                              CultureInfo.CurrentCulture,
                              Strings.ArgumentOutOfRange,
                              parameterName,
                              minInclusive,
                              maxInclusive));
            }
        }
Example #6
0
 public static void NotNullOrEmpty_Passes_ForNullOrEmptyString()
 {
     Expect.NotNullOrEmpty(null);
     Expect.NotNullOrEmpty(String.Empty);
 }
Example #7
0
 public static void NotNullOrEmpty_Passes_ForNonNullOrEmptyString()
 => Expect.NotNullOrEmpty("value");