Beispiel #1
0
        public void TestPreserveStackTrace()
        {
            StackTrace stackTrace = null;

            try
            {
                try
                {
                    Action bar = () =>
                    {
                        try
                        {
                            //delegate to the failing method
                            Action foo = () =>
                            {
                                stackTrace = new StackTrace(false);
                                throw new InvalidOperationException();
                            };

                            foo();

                            Assert.Fail("Exception was not thrown - 1");
                        }
                        catch (InvalidOperationException iopex)
                        {
                            //wrap the exception to make sure that there is an
                            //inner exception that can be re-thrown later on
                            throw new ArgumentException(string.Empty, iopex);
                        };
                    };

                    bar();

                    Assert.Fail("Exception was not thrown - 2");
                }
                catch (ArgumentException aex)
                {
                    //preserve the stack trace of the nested exception and re-throw it
                    ExceptionUtil.PreserveStackTrace(aex.InnerException);
                    throw aex.InnerException;
                }

                Assert.Fail("Exception was not thrown - 3");
            }
            catch (InvalidOperationException iopex)
            {
                ExceptionUtilTestHelpers.AssertStackTrace(iopex, stackTrace);
            }
        }
        public void TestStackTraceOfExceptionThrownByConnectorFacade()
        {
            ConnectorFacadeFactory factory = ConnectorFacadeFactory.GetInstance();
            Configuration          config  = new MockConfiguration();
            ConnectorFacade        facade  = factory.NewInstance(
                TestHelpers.CreateTestConfiguration(SafeType <Connector> .Get <SpyConnector>(), config));

            try
            {
                facade.Test();

                Assert.Fail("Exception was not thrown");
            }
            catch (EUTestException eutex)
            {
                ExceptionUtilTestHelpers.AssertStackTrace(eutex, SpyConnector.StackTrace);
            }
        }