예제 #1
0
        /// <summary>
        /// Handles processing when an exception was thrown.
        /// </summary>
        /// <param name="exception">The exception.</param>
        /// <param name="context">The execution context.</param>
        public void ProcessException(Exception exception, TestExecutionContext context)
        {
            if (exception is NUnitException)
            {
                exception = exception.InnerException;
            }

            if (IsExpectedExceptionType(exception))
            {
                if (IsExpectedMessageMatch(exception))
                {
                    MethodInfo exceptionMethod = exceptionData.GetExceptionHandler(context.TestObject.GetType());
                    if (exceptionMethod != null)
                    {
                        Reflect.InvokeMethod(exceptionMethod, context.TestObject, exception);
                    }
                    else
                    {
                        IExpectException handler = context.TestObject as IExpectException;
                        if (handler != null)
                        {
                            handler.HandleException(exception);
                        }
                    }

                    context.CurrentResult.SetResult(ResultState.Success);
                }
                else
                {
#if NETCF_1_0
                    context.CurrentResult.SetResult(ResultState.Failure, WrongTextMessage(exception));
#else
                    context.CurrentResult.SetResult(ResultState.Failure, WrongTextMessage(exception), GetStackTrace(exception));
#endif
                }
            }
            else
            {
                context.CurrentResult.RecordException(exception);

                // If it shows as an error, change it to a failure due to the wrong type
                if (context.CurrentResult.ResultState == ResultState.Error)
#if NETCF_1_0
                { context.CurrentResult.SetResult(ResultState.Failure, WrongTypeMessage(exception)); }
#else
                { context.CurrentResult.SetResult(ResultState.Failure, WrongTypeMessage(exception), GetStackTrace(exception)); }
#endif
            }
        }
예제 #2
0
        /// <summary>
        /// Handles processing when an exception was thrown.
        /// </summary>
        /// <param name="exception">The exception.</param>
        /// <param name="context">The execution context.</param>
        public void ProcessException(Exception exception, TestExecutionContext context)
        {
            if (exception is NUnitException)
            {
                exception = exception.InnerException;
            }

            if (IsExpectedExceptionType(exception))
            {
                if (IsExpectedMessageMatch(exception))
                {
                    if (context.TestObject != null)
                    {
                        IExpectException handler = context.TestObject as IExpectException;
                        if (handler != null)
                        {
                            handler.HandleException(exception);
                        }
                    }

                    context.CurrentResult.SetResult(ResultState.Success);
                }
                else
                {
                    context.CurrentResult.SetResult(ResultState.Failure, WrongTextMessage(exception), ExceptionHelper.GetStackTrace(exception));
                }
            }
            else
            {
                context.CurrentResult.RecordException(exception);

                // If it shows as an error, change it to a failure due to the wrong type
                if (context.CurrentResult.ResultState == ResultState.Error)
                {
                    context.CurrentResult.SetResult(ResultState.Failure, WrongTypeMessage(exception), ExceptionHelper.GetStackTrace(exception));
                }
            }
        }