Beispiel #1
0
        /// <summary>
        /// Does the expected exception stuff
        /// </summary>
        protected void HandleThrownException(ExecutionContext executionContext)
        {
            if (ExpectedException == null)
            {
                return;
            }

            if (executionContext.ThrownException == null)
            {
                Fail(executionContext, string.Format("Expected exception of type {0} was never thrown.", ExpectedException.GetFriendlyName()));
                return;
            }

            var temp            = executionContext.ThrownException.GetBaseException();
            var thrownException = (temp is TestErredException && ((TestErredException)temp).CauseError != null) ? ((TestErredException)temp).CauseError : temp;

            if (thrownException.GetType() != ExpectedException)
            {
                Fail(executionContext, string.Format(
                         "Expected exception of type {0}, but exception of type {1} was thrown.",
                         ExpectedException.GetFriendlyName(),
                         thrownException.GetType().GetFriendlyName()
                         ));
            }
            else if (!string.IsNullOrEmpty(ExpectedExceptionMessage) && thrownException.Message != ExpectedExceptionMessage)
            {
                Fail(executionContext, string.Format(
                         "Expected exception message did not match actual exception message.\nExpected: {0}\nActual:   {1}",
                         ExpectedExceptionMessage,
                         thrownException.Message
                         ));
            }
            else
            {
                //the test threw the correct exception with the correct message, so the result should be pass
                Pass(executionContext);
            }
        }