Exemple #1
0
        TestResultEvent createResultEvent()
        {
            RESULT_TYPE type  = RESULT_TYPE.SUCCESS;
            Exception   error = null;

            ExpectedExceptionAttribute attr = Method.GetCustomAttribute <ExpectedExceptionAttribute>();

            if (attr != null)
            {
                type  = RESULT_TYPE.FAILED_ASSERTION;
                error = new AssertException("Expected " + attr.ExpectedExceptionType
                                            + " but test method did not raise an exception");
            }
            return(new TestResultEvent(type, this, error));
        }
Exemple #2
0
        TestResultEvent createResultEvent(Exception ex)
        {
            RESULT_TYPE type  = RESULT_TYPE.SUCCESS;
            Exception   error = ex;

            ExpectedExceptionAttribute attr = Method.GetCustomAttribute <ExpectedExceptionAttribute>();

            if (attr != null)
            {
                Type ExpectedExceptionType = attr.ExpectedExceptionType;
                Type ActualExceptionType   = ex.GetType();
                if (ExpectedExceptionType.IsAssignableFrom(ActualExceptionType))
                {
                    if (attr.Message == null || ex.Message.Contains(attr.Message))
                    {
                        type  = RESULT_TYPE.SUCCESS;
                        error = ex;
                    }
                    else
                    {
                        type  = RESULT_TYPE.FAILED_ASSERTION;
                        error = new AssertException("Expected exception message to contain " +
                                                    "[" + attr.Message + "] but actual message was " +
                                                    "[" + ex.Message + "]");
                    }
                }
                else
                {
                    type  = RESULT_TYPE.FAILED_ASSERTION;
                    error = new AssertException("Expected " + ExpectedExceptionType
                                                + " but was " + ActualExceptionType);
                }
            }
            else
            {
                error = ex;
                type  = ex is AssertException
                      ? RESULT_TYPE.FAILED_ASSERTION: RESULT_TYPE.FAILED_EXECUTION;
            }
            return(new TestResultEvent(type, this, error));
        }