public void PropagatesCallerInfoThroughExceptionDuringSignaling()
        {
            var module = new TestErrorrTweetModule();
            var mocks = new { Context = new Mock<HttpContextBase> { DefaultValue = DefaultValue.Mock } };
            using (var app = new HttpApplication())
            {
                var context = mocks.Context.Object;
                var callerInfo = new CallerInfo("foobar", "baz.cs", 42);
                var exception = new Exception();
                IDictionary actualData = null;
                module.LogExceptionOverride = (e, _) => actualData = new Hashtable(e.Data);

                module.OnErrorSignaled(app, new ErrorSignalEventArgs(exception, context, callerInfo));

                Assert.Equal(0, exception.Data.Count);
                Assert.NotNull(actualData);
                Assert.Equal(1, actualData.Count);
                var actualCallerInfo = (CallerInfo) actualData.Cast<DictionaryEntry>().First().Value;
                Assert.Same(callerInfo, actualCallerInfo);

                module.LogExceptionOverride = delegate { throw new TestException(); };

                Assert.Throws<TestException>(() => module.OnErrorSignaled(app, new ErrorSignalEventArgs(exception, context, callerInfo)));
                Assert.Equal(0, exception.Data.Count);
            }
        }
示例#2
0
        public void PropagatesCallerInfoThroughExceptionDuringSignaling()
        {
            var module = new TestErrorrTweetModule();
            var mocks  = new { Context = new Mock <HttpContextBase> {
                                   DefaultValue = DefaultValue.Mock
                               } };

            using (var app = new HttpApplication())
            {
                var         context    = mocks.Context.Object;
                var         callerInfo = new CallerInfo("foobar", "baz.cs", 42);
                var         exception  = new Exception();
                IDictionary actualData = null;
                module.LogExceptionOverride = (e, _) => actualData = new Hashtable(e.Data);

                module.OnErrorSignaled(app, new ErrorSignalEventArgs(exception, context, callerInfo));

                Assert.Equal(0, exception.Data.Count);
                Assert.NotNull(actualData);
                Assert.Equal(1, actualData.Count);
                var actualCallerInfo = (CallerInfo)actualData.Cast <DictionaryEntry>().First().Value;
                Assert.Same(callerInfo, actualCallerInfo);

                module.LogExceptionOverride = delegate { throw new TestException(); };

                Assert.Throws <TestException>(() => module.OnErrorSignaled(app, new ErrorSignalEventArgs(exception, context, callerInfo)));
                Assert.Equal(0, exception.Data.Count);
            }
        }