public void PropagatesCallerInfoThroughExceptionDuringSignaling() { var module = new TestErrorMailModule(); 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.OnErrorOverride = (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.OnErrorOverride = delegate { throw new TestException(); }; Assert.Throws <TestException>(() => module.OnErrorSignaled(app, new ErrorSignalEventArgs(exception, context, callerInfo))); Assert.Equal(0, exception.Data.Count); } }
public void PropagatesCallerInfoThroughExceptionDuringSignaling() { var module = new TestErrorMailModule(); 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.OnErrorOverride = (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.OnErrorOverride = delegate { throw new TestException(); }; Assert.Throws<TestException>(() => module.OnErrorSignaled(app, new ErrorSignalEventArgs(exception, context, callerInfo))); Assert.Equal(0, exception.Data.Count); } }