示例#1
0
        /// <summary>
        /// Verifies that <paramref name="code"/> throws a particular exception when called.
        /// </summary>
        /// <param name="expectedExceptionType">The exception Type expected.</param>
        /// <param name="code">The code to test.</param>
        /// <param name="message">The message that will be displayed on failure.</param>
        /// <param name="parameters">An array of parameters to use when formatting <paramref name="message"/>.</param>
        /// <returns>The <see cref="Exception"/> thrown by <paramref name="code"/>.</returns>
        public static Exception Throws(Type expectedExceptionType, Action code, string message, params object[] parameters)
        {
            Exception caughtException = null;

            try
            {
                code();
            }
            catch (Exception ex)
            {
                caughtException = ex;
                TypeAssert.IsType(caughtException, expectedExceptionType, message, parameters);
            }

            if (caughtException == null)
            {
                Assert.Fail(Resources.Assertion_ExceptionNotThrown, expectedExceptionType);
            }

            return(caughtException);
        }
示例#2
0
 /// <summary>
 /// Verifies that the exception <see cref="Exception.InnerException"/>
 /// is of the specified type.
 /// </summary>
 /// <typeparam name="T">The source exception type.</typeparam>
 /// <param name="exception">The exception whose <see cref="Exception.InnerException"/>
 /// will be tested.</param>
 /// <param name="innerException">The expected type of the inner exception.</param>
 /// <returns>The original <see cref="Exception"/>.</returns>
 public static T WithInnerException <T>(this T exception, Type innerException) where T : Exception
 {
     TypeAssert.IsType(exception.InnerException, innerException);
     return(exception);
 }
示例#3
0
 /// <summary>
 /// Asserts that an object may be assigned a value of a given <see cref="Type"/>.
 /// </summary>
 /// <param name="value">The value to be tested.</param>
 /// <param name="expectedType">The expected <see cref="Type"/>.</param>
 /// <param name="message">A message to display. This message can be seen in the unit test results.</param>
 public static void IsAssignableFrom(object value, Type expectedType, string message)
 {
     TypeAssert.IsAssignableFrom(value, expectedType, message, null);
 }
示例#4
0
 /// <summary>
 /// Asserts that an object may be assigned a value of a given <see cref="Type"/>.
 /// </summary>
 /// <param name="value">The value to be tested.</param>
 /// <param name="expectedType">The expected <see cref="Type"/>.</param>
 public static void IsAssignableFrom(object value, Type expectedType)
 {
     TypeAssert.IsAssignableFrom(value, expectedType, Strings.Assertion_ExpectedToBeAssignableFrom, value, expectedType);
 }
示例#5
0
 /// <summary>
 /// Asserts that an object is of the given <see cref="Type"/>.
 /// </summary>
 /// <param name="value">The value to be tested.</param>
 /// <param name="expectedType">The expected <see cref="Type"/>.</param>
 /// <param name="message">A message to display. This message can be seen in the unit test results.</param>
 public static void IsType(object value, Type expectedType, string message)
 {
     TypeAssert.IsType(value, expectedType, message, null);
 }
示例#6
0
 /// <summary>
 /// Asserts that an object is of the given <see cref="Type"/>.
 /// </summary>
 /// <param name="value">The value to be tested.</param>
 /// <param name="expectedType">The expected <see cref="Type"/>.</param>
 public static void IsType(object value, Type expectedType)
 {
     Requires.NotNull(value, "value");
     TypeAssert.IsType(value, expectedType, Strings.Assertion_WrongType, expectedType, value.GetType());
 }
示例#7
0
 /// <summary>
 /// Asserts that an object may not be assigned a value of a given <see cref="Type"/>.
 /// </summary>
 /// <param name="value">The value to be tested.</param>
 /// <param name="expectedType">The expected <see cref="Type"/>.</param>
 public static void IsNotAssignableFrom(object value, Type expectedType)
 {
     TypeAssert.IsNotAssignableFrom(value, expectedType, Resources.Assertion_ExpectedToBeAssignableFrom, value, expectedType);
 }