示例#1
0
        /// <summary>
        /// Checks that the evaluated bool is false.
        /// </summary>
        /// <param name="validation">The current assumptions that is being validated.</param>
        /// <param name="condition">An expression that must evaluate to false, or it will fail the validation.</param>
        /// <param name="message">An optional message to throw with the exception.</param>
        /// <returns>The current assumptions that is being validated.</returns>
        /// <exception cref="InternalErrorException">Thrown if the value is not false.</exception>
        public static AssumptionValidation IsFalse(this AssumptionValidation validation, bool condition, string message)
        {
            if (condition)
            {
                return(validation.SetException(new InternalErrorException(message)));
            }

            return(validation);
        }
示例#2
0
        /// <summary>
        /// Checks that the evaluated bool is true.
        /// </summary>
        /// <param name="validation">The current assumptions that is being validated.</param>
        /// <param name="condition">An expression that must evaluate to true, or it will fail the validation.</param>
        /// <returns>The current assumptions that is being validated.</returns>
        /// <exception cref="InternalErrorException">Thrown if the value is not true.</exception>
        public static AssumptionValidation IsTrue(this AssumptionValidation validation, bool condition)
        {
            if (!condition)
            {
                return(validation.SetException(new InternalErrorException()));
            }

            return(validation);
        }
示例#3
0
        /// <summary>
        /// Checks that the evaluated string is not null or empty.
        /// </summary>
        /// <param name="validation">The current assumptions that is being validated.</param>
        /// <param name="value">The string to be evaluated.</param>
        /// <returns>The current assumptions that is being validated.</returns>
        /// <exception cref="InternalErrorException">Thrown if the value is <c>null</c> or empty.</exception>
        public static AssumptionValidation IsNotNullOrEmpty(this AssumptionValidation validation, string value)
        {
            if (String.IsNullOrEmpty(value))
            {
                return(validation.SetException(new InternalErrorException()));
            }

            return(validation);
        }
示例#4
0
        /// <summary>
        /// Checks that the evaluated result is null.
        /// </summary>
        /// <typeparam name="T">The type to be evaluated.</typeparam>
        /// <param name="validation">The current assumptions that is being validated.</param>
        /// <param name="value">The value to be evaluated.</param>
        /// <returns>The current assumptions that is being validated.</returns>
        /// <exception cref="InternalErrorException">Thrown if the value is not <c>null</c>.</exception>
        public static AssumptionValidation IsNull <T>(this AssumptionValidation validation, T value)
            where T : class
        {
            if (value != null)
            {
                return(validation.SetException(new InternalErrorException()));
            }

            return(validation);
        }
示例#5
0
        public static AssumptionValidation IsNotNull <T>(this AssumptionValidation validation, T?value)
            where T : struct
        {
            if (!value.HasValue)
            {
                return(validation.SetException(new InternalErrorException()));
            }

            return(validation);
        }
示例#6
0
        /// <summary>
        /// Checks that the evaluated enumerable is not null or empty.
        /// </summary>
        /// <param name="validation">The current assumptions that is being validated.</param>
        /// <param name="enumerable">The enumerable to be evaluated.</param>
        /// <returns>The current assumptions that is being validated.</returns>
        /// <exception cref="InternalErrorException">Thrown if the value is <c>null</c> or empty.</exception>
        public static AssumptionValidation IsNotNullOrEmpty <T>(this AssumptionValidation validation, T enumerable)
            where T : IEnumerable
        {
            if (enumerable == null || enumerable.IsEnumEmpty())
            {
                return(validation.SetException(new InternalErrorException()));
            }

            return(validation);
        }
示例#7
0
        /// <summary>
        /// Checks that the evaluated result is its default value.
        /// </summary>
        /// <typeparam name="T">The type to be evaluated.</typeparam>
        /// <param name="validation">The current assumptions that is being validated.</param>
        /// <param name="value">The value to be evaluated.</param>
        /// <returns>The current assumptions that is being validated.</returns>
        /// <exception cref="InternalErrorException">Thrown if the value is not its default value.</exception>
        public static AssumptionValidation IsDefault <T>(this AssumptionValidation validation, T value)
            where T : struct
        {
            if (!value.Equals(default(T)))
            {
                return(validation.SetException(new InternalErrorException()));
            }

            return(validation);
        }
示例#8
0
        internal static AssumptionValidation SetException(this AssumptionValidation validation, Exception ex)
        {
            if (validation == null)
            {
                validation = new AssumptionValidation();
            }

            validation.SetExceptionInternal(ex);

            return(validation);
        }
示例#9
0
        /// <summary>
        /// Checks that the evaluated service object is not null.
        /// </summary>
        /// <param name="validation">The current assumptions that is being validated.</param>
        /// <param name="service">The service to verify existance.</param>
        /// <returns>The current assumptions that is being validated.</returns>
        /// <exception cref="InternalErrorException">Thrown if the service is null.</exception>
        public static AssumptionValidation IsServicePresent <T>(this AssumptionValidation validation, T service)
        {
            if (service == null)
            {
#if NET35
                var coreType = typeof(T);
#else
                var coreType = Helpers.TrimGenericWrapper(typeof(T), typeof(Lazy <>));
#endif
                return(validation.SetException(new InternalErrorException(Format(Strings.ServiceMissing, coreType.FullName))));
            }

            return(validation);
        }
示例#10
0
        public static AssumptionValidation IsType <T>(this AssumptionValidation validation, object value)
        {
            if (value == null)
            {
                return(validation);
            }

            if (!(value is T))
            {
                return(validation.SetException(new InternalErrorException()));
            }

            return(validation);
        }