public static void Range(bool rangeCondition, string parameterName, string message) { Expect.NotNullOrEmpty(parameterName); if (!rangeCondition) { throw new ArgumentOutOfRangeException(parameterName, message); } }
public static void True(bool testCondition, string parameterName, string message) { Expect.NotNullOrEmpty(parameterName); if (!testCondition) { throw new ArgumentException(message, parameterName); } }
public static void True(bool testCondition, string parameterName) { Expect.NotNullOrEmpty(parameterName); if (!testCondition) { throw new ArgumentException(Strings.Argument_TestFailed, parameterName); } }
public static void NotWhiteSpace(string value, string parameterName) { Expect.NotNullOrEmpty(parameterName); if (Check.IsWhiteSpace(value)) { throw new ArgumentException(Strings.Argument_WhiteSpaceString, parameterName); } }
/// <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)); } }
public static void NotNullOrEmpty_Passes_ForNullOrEmptyString() { Expect.NotNullOrEmpty(null); Expect.NotNullOrEmpty(String.Empty); }
public static void NotNullOrEmpty_Passes_ForNonNullOrEmptyString() => Expect.NotNullOrEmpty("value");