public void ConstructExceptionPolicyEntryWithNullHandlersThrows() { ExceptionPolicyEntry entry = new ExceptionPolicyEntry( typeof(Exception), PostHandlingAction.ThrowNewException, null); }
public void ConstructExceptionPolicyEntryWithNullExceptionTypeThrows() { ExceptionPolicyEntry entry = new ExceptionPolicyEntry( null, PostHandlingAction.ThrowNewException, new List<IExceptionHandler>()); }
public void HandleExceptionWithBadExceptionHandlerThatThrows() { List<IExceptionHandler> handlers = new List<IExceptionHandler>(); handlers.Add(new MockThrowingExceptionHandler()); ExceptionPolicyEntry entry = new ExceptionPolicyEntry( PostHandlingAction.None, handlers); entry.Handle(new ApplicationException()); }
public void ExceptionHandlerInChainReturnsNullThrows() { List<IExceptionHandler> handlers = new List<IExceptionHandler>(); handlers.Add(new MockReturnNullExceptionHandler()); ExceptionPolicyEntry entry = new ExceptionPolicyEntry( PostHandlingAction.ThrowNewException, handlers); entry.Handle(new ApplicationException()); }
public void HandleExceptionWithThrowNewException() { List<IExceptionHandler> handlers = new List<IExceptionHandler>(); handlers.Add(new WrapHandler("message", typeof(ArgumentException))); ExceptionPolicyEntry entry = new ExceptionPolicyEntry( PostHandlingAction.ThrowNewException, handlers); entry.Handle(new InvalidOperationException()); }
public void HandleExceptionWithNoPostHandling() { List<IExceptionHandler> handlers = new List<IExceptionHandler>(); handlers.Add(new WrapHandler("message", typeof(ArgumentException))); ExceptionPolicyEntry entry = new ExceptionPolicyEntry( PostHandlingAction.None, handlers); bool handled = entry.Handle(new ApplicationException()); Assert.IsFalse(handled); }
public void SetUp() { exceptionHandlerExecutedCallbackCalled = false; exceptionHandledCallbackCalled = false; var handlers = new List<IExceptionHandler> { new MockExceptionHandler(new NameValueCollection()) }; var instrumentationProvider = new TestInstrumentationProvider(this); policyEntry = new ExceptionPolicyEntry(typeof(Exception), PostHandlingAction.None, handlers, instrumentationProvider); }
private ExceptionPolicyEntry CreatePolicyEntry(IExceptionHandler exceptionHandler, PostHandlingAction postHandlingAction) { List<IExceptionHandler> handlerList = new List<IExceptionHandler>(); handlerList.Add(exceptionHandler); ExceptionPolicyEntry policyEntry = new ExceptionPolicyEntry(postHandlingAction, handlerList); instrumentationProvider = new ExceptionHandlingInstrumentationProvider(); instrumentationProvider.exceptionHandlingErrorOccurred += new EventHandler<ExceptionHandlingErrorEventArgs>(ErrorCallback); policyEntry.SetInstrumentationProvider(instrumentationProvider); return policyEntry; }
ExceptionPolicyEntry CreatePolicyEntry(IExceptionHandler exceptionHandler, PostHandlingAction postHandlingAction) { List<IExceptionHandler> handlerList = new List<IExceptionHandler>(); handlerList.Add(exceptionHandler); ExceptionPolicyEntry policyEntry = new ExceptionPolicyEntry( typeof(Exception), postHandlingAction, handlerList, new TestInstrumentationProvider(this)); return policyEntry; }
public void SetUp() { IExceptionHandler[] handlers = new IExceptionHandler[] { new MockThrowingExceptionHandler() }; ExceptionPolicyEntry policyEntry = new ExceptionPolicyEntry(PostHandlingAction.None, handlers); Dictionary<Type, ExceptionPolicyEntry> policyEntries = new Dictionary<Type,ExceptionPolicyEntry>(); policyEntries.Add(typeof(ArgumentException), policyEntry); exceptionPolicy = new ExceptionPolicyImpl(policyName, policyEntries); ReflectionInstrumentationAttacher attacher = new ReflectionInstrumentationAttacher( exceptionPolicy.GetInstrumentationEventProvider(), typeof(ExceptionHandlingInstrumentationListener), new object[] { policyName, true, true, true }); attacher.BindInstrumentation(); }
ExceptionPolicyEntry CreatePolicyEntry(IExceptionHandler exceptionHandler, PostHandlingAction postHandlingAction) { List <IExceptionHandler> handlerList = new List <IExceptionHandler>(); handlerList.Add(exceptionHandler); ExceptionPolicyEntry policyEntry = new ExceptionPolicyEntry( typeof(Exception), postHandlingAction, handlerList, new TestInstrumentationProvider(this)); return(policyEntry); }
public void SetUp() { IExceptionHandler[] handlers = new IExceptionHandler[] { new MockThrowingExceptionHandler() }; ExceptionPolicyEntry policyEntry = new ExceptionPolicyEntry(PostHandlingAction.None, handlers); Dictionary <Type, ExceptionPolicyEntry> policyEntries = new Dictionary <Type, ExceptionPolicyEntry>(); policyEntries.Add(typeof(ArgumentException), policyEntry); exceptionPolicy = new ExceptionPolicyImpl(policyName, policyEntries); ReflectionInstrumentationAttacher attacher = new ReflectionInstrumentationAttacher( exceptionPolicy.GetInstrumentationEventProvider(), typeof(ExceptionHandlingInstrumentationListener), new object[] { policyName, true, true, true }); attacher.BindInstrumentation(); }
public void SetUp() { var handlers = new IExceptionHandler[] { new MockThrowingExceptionHandler() }; var instrumentationProvider = new ExceptionHandlingInstrumentationProvider(policyName, true, true, "ApplicationInstanceName"); var policyEntry = new ExceptionPolicyEntry(typeof(ArgumentException), PostHandlingAction.None, handlers, instrumentationProvider); var policyEntries = new Dictionary <Type, ExceptionPolicyEntry> { { typeof(ArgumentException), policyEntry } }; exceptionPolicy = new ExceptionPolicyImpl(policyName, policyEntries); nameFormatter = new FixedPrefixNameFormatter("Prefix - "); provider = new ExceptionHandlingInstrumentationProvider(instanceName, true, true, nameFormatter); formattedInstanceName = nameFormatter.CreateName(instanceName); totalExceptionHandlersExecuted = new EnterpriseLibraryPerformanceCounter(counterCategoryName, TotalExceptionHandlersExecuted, formattedInstanceName); totalExceptionsHandled = new EnterpriseLibraryPerformanceCounter(counterCategoryName, TotalExceptionsHandled, formattedInstanceName); }
public void SetUp() { var handlers = new IExceptionHandler[] { new MockThrowingExceptionHandler() }; var instrumentationProvider = new ExceptionHandlingInstrumentationProvider(policyName, true, true, "ApplicationInstanceName"); var policyEntry = new ExceptionPolicyEntry(typeof(ArgumentException), PostHandlingAction.None, handlers, instrumentationProvider); var policyEntries = new Dictionary<Type, ExceptionPolicyEntry> { {typeof (ArgumentException), policyEntry} }; exceptionPolicy = new ExceptionPolicyImpl(policyName, policyEntries); nameFormatter = new FixedPrefixNameFormatter("Prefix - "); provider = new ExceptionHandlingInstrumentationProvider(instanceName, true, true, nameFormatter); formattedInstanceName = nameFormatter.CreateName(instanceName); totalExceptionHandlersExecuted = new EnterpriseLibraryPerformanceCounter(counterCategoryName, TotalExceptionHandlersExecuted, formattedInstanceName); totalExceptionsHandled = new EnterpriseLibraryPerformanceCounter(counterCategoryName, TotalExceptionsHandled, formattedInstanceName); }
public void SetUp() { IExceptionHandler[] handlers = new IExceptionHandler[] { new MockThrowingExceptionHandler() }; ExceptionPolicyEntry policyEntry = new ExceptionPolicyEntry(PostHandlingAction.None, handlers); Dictionary <Type, ExceptionPolicyEntry> policyEntries = new Dictionary <Type, ExceptionPolicyEntry>(); policyEntries.Add(typeof(ArgumentException), policyEntry); exceptionPolicy = new ExceptionPolicyImpl(policyName, policyEntries); ReflectionInstrumentationAttacher attacher = new ReflectionInstrumentationAttacher( exceptionPolicy.GetInstrumentationEventProvider(), typeof(ExceptionHandlingInstrumentationListener), new object[] { policyName, true, true, true, "ApplicationInstanceName" }); attacher.BindInstrumentation(); nameFormatter = new FixedPrefixNameFormatter("Prefix - "); listener = new ExceptionHandlingInstrumentationListener(instanceName, true, true, true, nameFormatter); formattedInstanceName = nameFormatter.CreateName(instanceName); totalExceptionHandlersExecuted = new EnterpriseLibraryPerformanceCounter(counterCategoryName, TotalExceptionHandlersExecuted, formattedInstanceName); totalExceptionsHandled = new EnterpriseLibraryPerformanceCounter(counterCategoryName, TotalExceptionsHandled, formattedInstanceName); }
public void CreatesExceptionPolicyForThrowNewExceptionPostHandlingAction() { var excepionPolicies = new List <ExceptionPolicyDefinition>(); var excepionPolicyEntries = new List <ExceptionPolicyEntry>(); var exceptionPolicy = new ExceptionPolicyEntry(typeof(Exception), PostHandlingAction.ThrowNewException, new IExceptionHandler[] { }); excepionPolicyEntries.Add(exceptionPolicy); excepionPolicies.Add(new ExceptionPolicyDefinition("EH", excepionPolicyEntries)); var exceptionManager = new ExceptionManager(excepionPolicies); var originalException = new Exception(); ExceptionAssertHelper.Throws <Exception>(() => exceptionManager.HandleException(originalException, "EH")); Exception exception = null; bool rethrow = exceptionManager.HandleException(new Exception(), "EH", out exception); Assert.IsInstanceOfType(exception, typeof(Exception)); Assert.IsTrue(rethrow); }
public void CreatesCustomExceptionHandlerForNotifyRethrowPostHandlingAction() { var excepionPolicies = new List <ExceptionPolicyDefinition>(); var excepionPolicyEntries = new List <ExceptionPolicyEntry>(); var exceptionHandler = new CustomExceptionHandler(null); var exceptionPolicy = new ExceptionPolicyEntry(typeof(Exception), PostHandlingAction.NotifyRethrow, new IExceptionHandler[] { exceptionHandler }); excepionPolicyEntries.Add(exceptionPolicy); excepionPolicies.Add(new ExceptionPolicyDefinition("EH", excepionPolicyEntries)); var exceptionManager = new ExceptionManager(excepionPolicies); bool rethrow = exceptionManager.HandleException(new Exception(), "EH"); Assert.IsTrue(rethrow); Exception exception = null; bool rethrowWithOutput = exceptionManager.HandleException(new Exception(), "EH", out exception); Assert.IsNull(exception); Assert.IsTrue(rethrowWithOutput); }
public void CreatesReplaceExceptionHandlerWithMessageForThrowNewExceptionPostHandlingAction() { var excepionPolicies = new List <ExceptionPolicyDefinition>(); var excepionPolicyEntries = new List <ExceptionPolicyEntry>(); var exceptionHandler = new ReplaceHandler("string", typeof(InvalidCastException)); var exceptionPolicy = new ExceptionPolicyEntry(typeof(Exception), PostHandlingAction.ThrowNewException, new IExceptionHandler[] { exceptionHandler }); excepionPolicyEntries.Add(exceptionPolicy); excepionPolicies.Add(new ExceptionPolicyDefinition("EH", excepionPolicyEntries)); var exceptionManager = new ExceptionManager(excepionPolicies); ExceptionAssertHelper.Throws <InvalidCastException>(() => exceptionManager.HandleException(new Exception(), "EH")); Exception exception = null; bool rethrow = exceptionManager.HandleException(new Exception(), "EH", out exception); Assert.IsInstanceOfType(exception, typeof(InvalidCastException)); Assert.AreEqual("string", exception.Message); Assert.IsNull(exception.InnerException); Assert.IsTrue(rethrow); }
public void SetUp() { exceptionHandlerExecutedCallbackCalled = false; exceptionHandledCallbackCalled = false; List<IExceptionHandler> handlers = new List<IExceptionHandler>(); handlers.Add(new MockExceptionHandler(new NameValueCollection())); policyEntry = new ExceptionPolicyEntry(PostHandlingAction.None, handlers); instrumentationProvider = new ExceptionHandlingInstrumentationProvider(); instrumentationProvider.exceptionHandled += new EventHandler<EventArgs>(ExceptionHandledCallback); instrumentationProvider.exceptionHandlerExecuted += new EventHandler<EventArgs>(ExceptionHandlerExecutedCallback) ; policyEntry.SetInstrumentationProvider(instrumentationProvider); }
public void HandleExceptionWithNullExceptionThrows() { List<IExceptionHandler> handlers = new List<IExceptionHandler>(); handlers.Add(new WrapHandler("message", typeof(ArgumentException))); ExceptionPolicyEntry entry = new ExceptionPolicyEntry( typeof(Exception), PostHandlingAction.ThrowNewException, handlers); entry.Handle(null); }
public void ConstructExceptionPolicyEntryWithNullHandlersThrows() { ExceptionPolicyEntry entry = new ExceptionPolicyEntry( PostHandlingAction.ThrowNewException, null); }
public GivenTwoPolicyEntries() { entry1 = new ExceptionPolicyEntry(typeof(ArgumentNullException), PostHandlingAction.None, new List<IExceptionHandler>(){handler1}); entry2 = new ExceptionPolicyEntry(typeof(Exception), PostHandlingAction.None, new List<IExceptionHandler>(){handler2}); }
public void ExceptionHandlerInChainReturnsNullThrows() { var handlers = new List<IExceptionHandler> {new MockReturnNullExceptionHandler()}; var entry = new ExceptionPolicyEntry( typeof(Exception), PostHandlingAction.ThrowNewException, handlers); entry.Handle(new ApplicationException()); }