I am trying to extend MbUnit with a new test attribute
[ExpectedCOMException(int)]. You can probably guess what it does.
Inside the class, I throw exceptions such as
ExceptionTypeMismatchException (similar to how ExpectedException does
it). The problem is that when I throw these exceptions, they are not
handled by anyone and therefore cause an unhandled exception message
dialog to appear. I am confused because I though MbUnit would be
catching these somewhere and failing the test (which is what I want).
My question is, where does MbUnit catch exceptions thrown in test
methods? How can I solve this problem?

my code:

    namespace MbUnit.Framework
{
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = true,
Inherited = true)]
    public sealed class ExpectedCOMExceptionAttribute :
DecoratorPatternAttribute
    {
        private int m_nErrorCode;

        public ExpectedCOMExceptionAttribute(int errorCode)
        {
            m_nErrorCode = errorCode;
        }

        public int M_nErrorCode
        {
            get
            {
                return this.m_nErrorCode;
            }
        }

        public override IRunInvoker GetInvoker(IRunInvoker invoker)
        {
            return new ExpectedCOMExceptionRunInvoker(invoker, this);
        }

        private sealed class ExpectedCOMExceptionRunInvoker :
DecoratorRunInvoker
        {

            private ExpectedCOMExceptionAttribute attribute;
            public ExpectedCOMExceptionRunInvoker
            (
                IRunInvoker invoker,
                ExpectedCOMExceptionAttribute attribute)
                : base(invoker)
            {
                this.attribute = attribute;
            }

            public override object Execute(object o, IList args)
            {
                //invoke tagged method
                try
                {
                    this.Invoker.Execute(o, args);
                }
                catch (Exception ex)
                {

                    Exception catchedException = ex;
                    if (catchedException is TargetInvocationException)
                        catchedException = ex.InnerException;

                    if (!
typeof(System.Runtime.InteropServices.COMException).IsInstanceOfType(catchedException))
                        throw new
MbUnit.Core.Exceptions.ExceptionTypeMistmachException(typeof(System.Runtime.InteropServices.COMException),
                               "Description not implemented",
catchedException);

                    else
                    {
                        System.Runtime.InteropServices.COMException
current =
 
(System.Runtime.InteropServices.COMException)catchedException;

                        if (current.ErrorCode !=
attribute.M_nErrorCode)
                            throw new Exception("wrong error code");

                        else return null;

                    }

                }
                throw new
ExceptionNotThrownException(typeof(System.Runtime.InteropServices.COMException),
                          "Description not implemented");

            }
        }
    }
}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MbUnit.User" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/MbUnitUser?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to