Exemple #1
0
        /// <summary>
        /// Declares a compound assertion.
        /// </summary>
        /// <param name="message">The message to display if any of the assertions fail.</param>
        /// <param name="assertions">A list of actions to be invoked to make assertions.</param>
        /// <exception cref="ArgumentNullException"><paramref name="message"/> or <paramref name="assertions"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="message"/> is empty.</exception>
        public static void AssertAll(string message, params Action[] assertions)
        {
            Argument.NotNullOrEmpty(message, nameof(message));
            Argument.NotNull(assertions, nameof(assertions));

            AssertAll(message, (IEnumerable <Action>)assertions);
        }
Exemple #2
0
        public static void Throw(string assertionName, IEnumerable <Exception> innerExceptions, string assertionMessage, string userMessage, params object[] userArgs)
        {
            Argument.NotNullOrEmpty(assertionName, nameof(assertionName));

            var message = AssertionFailed(assertionName, assertionMessage, userMessage, userArgs);

            throw new AssertionException(message, innerExceptions);
        }
Exemple #3
0
        /// <summary>
        /// Gets the method function.
        /// </summary>
        /// <typeparam name="T">The parameters type.</typeparam>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <param name="sourceType">The source type.</param>
        /// <param name="methodName">Name of the method.</param>
        /// <returns>The <see cref="Func{T, TResult}"/>.</returns>
        internal static Func <T, TResult> GetMethodFunc <T, TResult>(this Type sourceType, string methodName)
        {
            Argument.NotNull(sourceType, nameof(sourceType));
            Argument.NotNullOrEmpty(methodName, nameof(methodName));

            var typeInfo = sourceType.GetTypeInfo();
            var method   = typeInfo.DeclaredMethods.Single(m => m.Name == methodName);

            return((Func <T, TResult>)(object) method.CreateDelegate(typeof(Func <T, TResult>)));
        }
        /// <summary>
        /// Adds a classification category.
        /// </summary>
        /// <param name="name">The name of the classification category.</param>
        /// <param name="predicate">The predicate values must pass in order to be classified in this category.</param>
        /// <exception cref="ArgumentNullException">Either <paramref name="name"/> or <paramref name="predicate"/> is null.</exception>
        /// <exception cref="ArgumentException"><para><paramref name="name"/> is empty.</para>
        /// <para>-or-</para>
        /// <para>A category with the same name already exists in the <see cref="Classifier{TValue}"/>.</para></exception>
        /// <exception cref="ArgumentNullException"><paramref name="name"/> or <paramref name="predicate"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="name"/> is empty.</exception>
        /// <exception cref="InvalidOperationException">Values have already been classified.</exception>
        public void AddClassification(string name, Predicate <TValue> predicate)
        {
            Argument.NotNullOrEmpty(name, nameof(name));
            Argument.NotNull(predicate, nameof(predicate));

            if (Count > 0)
            {
                throw new InvalidOperationException("Cannot add classifications after classifying any values.");
            }

            classifications.Add(name, new Classification(predicate));
        }
Exemple #5
0
        /// <summary>
        /// Declares a compound assertion.
        /// </summary>
        /// <param name="message">The message to display if any of the assertions fail.</param>
        /// <param name="assertions">A list of actions to be invoked to make assertions.</param>
        /// <exception cref="ArgumentNullException"><paramref name="message"/> or <paramref name="assertions"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="message"/> is empty.</exception>
        public static void AssertAll(string message, IEnumerable <Action> assertions)
        {
            Argument.NotNullOrEmpty(message, nameof(message));
            Argument.NotNull(assertions, nameof(assertions));

            var errors = new Lazy <List <Exception> >(false);

            foreach (var action in assertions)
            {
                try
                {
                    action();
                }
                catch (Exception e)
                {
                    errors.Value.Add(e);
                }
            }

            if (errors.IsValueCreated)
            {
                throw new AssertionException(message, errors.Value);
            }
        }