public void CanCreatePoliciesForHandler() { ExceptionPolicyData exceptionPolicyData = new ExceptionPolicyData("policy"); settings.ExceptionPolicies.Add(exceptionPolicyData); ExceptionTypeData exceptionTypeData = new ExceptionTypeData("type1", typeof(Exception), PostHandlingAction.ThrowNewException); exceptionPolicyData.ExceptionTypes.Add(exceptionTypeData); CustomHandlerData exceptionHandlerData = new CustomHandlerData("handler1", typeof(TestCustomExceptionHandler)); exceptionHandlerData.Attributes.Add(TestCustomExceptionHandler.AttributeKey, "custom handler"); exceptionTypeData.ExceptionHandlers.Add(exceptionHandlerData); container.AddExtension(new ExceptionHandlingBlockExtension()); ExceptionPolicyImpl policy = container.Resolve<ExceptionPolicyImpl>("policy"); Exception originalException = new Exception("to be replaced"); try { policy.HandleException(originalException); Assert.Fail("a new exception should have been thrown"); } catch (Exception e) { Assert.AreEqual("custom handler", e.Message); Assert.AreSame(originalException, e.InnerException); Assert.AreSame(originalException, TestCustomExceptionHandler.handledException); } }
public void CustomHandlerNodeDataTest() { string attributeKey = "attKey"; string attributeValue = "attValue"; string name = "some name"; Type type = typeof(WrapHandlerNode); CustomHandlerData customHandlerData = new CustomHandlerData(); customHandlerData.Attributes.Add(attributeKey, attributeValue); customHandlerData.Name = name; customHandlerData.Type = type; CustomHandlerNode customHandlerNode = new CustomHandlerNode(customHandlerData); CustomHandlerData nodeData = (CustomHandlerData)customHandlerNode.ExceptionHandlerData; Assert.AreEqual(name, nodeData.Name); Assert.AreEqual(type, nodeData.Type); Assert.AreEqual(attributeKey, nodeData.Attributes.AllKeys[0]); Assert.AreEqual(attributeValue, nodeData.Attributes[attributeKey]); }
public void CustomHandlerDataTest() { string attributeKey = "attKey"; string attributeValue = "attValue"; string name = "some name"; Type type = typeof(WrapHandlerNode); CustomHandlerData data = new CustomHandlerData(); data.Name = name; data.Type = type; data.Attributes.Add(attributeKey, attributeValue); CustomHandlerNode node = new CustomHandlerNode(data); Assert.AreEqual(name, node.Name); Assert.AreEqual(type, node.Type); Assert.AreEqual(attributeKey, node.Attributes[0].Key); Assert.AreEqual(attributeValue, node.Attributes[0].Value); }
public MockThrowingExceptionHandler(CustomHandlerData customHandlerData) : this() { }
public void PoliciesForExceptionManagerAreCreated() { ExceptionPolicyData exceptionPolicy1Data = new ExceptionPolicyData("policy1"); settings.ExceptionPolicies.Add(exceptionPolicy1Data); ExceptionTypeData exceptionTypeData11 = new ExceptionTypeData("type1", typeof(Exception), PostHandlingAction.ThrowNewException); exceptionPolicy1Data.ExceptionTypes.Add(exceptionTypeData11); CustomHandlerData exceptionHandlerData11 = new CustomHandlerData("handler1", typeof(TestCustomExceptionHandler)); exceptionHandlerData11.Attributes.Add(TestCustomExceptionHandler.AttributeKey, "handler1"); exceptionTypeData11.ExceptionHandlers.Add(exceptionHandlerData11); using(var container = new UnityContainer().AddExtension(new EnterpriseLibraryCoreExtension(configurationSource))) { ExceptionManager manager = container.Resolve<ExceptionManager>(); Assert.IsNotNull(manager); Exception exceptionToThrow = new Exception("some message"); try { manager.Process(() => { throw exceptionToThrow; }, "policy1"); Assert.Fail("a new exception should have been thrown"); } catch (Exception e) { Assert.AreSame(exceptionToThrow, e.InnerException); Assert.AreEqual("handler1", e.Message); } } }