public void Setup() { MockExceptionHandler.Clear(); handlerData = new CustomHandlerData("custom", typeof(TestHandlerWithMissingConstructor)); handlerData.Attributes["foo"] = "bar"; }
public void SetUp() { provider = new CustomHandlerDataManageabilityProvider(); machineKey = new MockRegistryKey(true); userKey = new MockRegistryKey(true); configurationObject = new CustomHandlerData(); }
public void Setup() { MockExceptionHandler.Clear(); handlerData = new CustomHandlerData(); handlerData.Attributes["foo"] = "bar"; }
public void RuntimeTest() { ExceptionPolicyData policyData = new ExceptionPolicyData(); policyData.Name = "Default Policy"; ExceptionTypeData typeData = new ExceptionTypeData(); typeData.Name = "ApplicationException"; CustomHandlerData handlerData = new CustomHandlerData(); handlerData.Name = "MockExceptionHandler"; ExceptionHandlingSettings settings = new ExceptionHandlingSettings(); settings.ExceptionPolicies.Add(policyData); //settings.ExceptionPolicies[policyData.Name].ExceptionTypes = new ExceptionTypeDataCollection(); settings.ExceptionPolicies[policyData.Name].ExceptionTypes.Add(typeData); //settings.ExceptionPolicies[policyData.Name].ExceptionTypes[typeData.Name].ExceptionHandlers = new ExceptionHandlerDataCollection(); settings.ExceptionPolicies[policyData.Name].ExceptionTypes[typeData.Name].ExceptionHandlers.Add(handlerData); ExceptionHandlingSettingsNode settingsNode = new ExceptionHandlingSettingsNode(settings); HierarchyService.SelectedHierarchy.RootNode.Nodes.Add(settingsNode); Assert.AreEqual(policyData.Name, settingsNode.Nodes[0].Name); Assert.AreEqual(typeData.Name, settingsNode.Nodes[0].Nodes[0].Name); Assert.AreEqual(handlerData.Name, settingsNode.Nodes[0].Nodes[0].Nodes[0].Name); }
public void CanOpenAndSaveWithCustomHandler() { System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ExceptionHandlingSettings settings = (ExceptionHandlingSettings)config.Sections[ExceptionHandlingSettings.SectionName]; CustomHandlerData data = (CustomHandlerData)settings.ExceptionPolicies.Get(customPolicy).ExceptionTypes.Get(exceptionType).ExceptionHandlers.Get(customHandler); data.Attributes.Add("Money", "0"); config.Save(ConfigurationSaveMode.Full); ConfigurationManager.RefreshSection(ExceptionHandlingSettings.SectionName); settings = (ExceptionHandlingSettings)ConfigurationManager.GetSection(ExceptionHandlingSettings.SectionName); data = (CustomHandlerData)settings.ExceptionPolicies.Get(customPolicy).ExceptionTypes.Get(exceptionType).ExceptionHandlers.Get(customHandler); Assert.IsNotNull(data); Assert.AreEqual(3, data.Attributes.Count); Assert.AreEqual("0", data.Attributes.Get("Money")); data = null; config = null; // reset config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); settings = (ExceptionHandlingSettings)config.Sections[ExceptionHandlingSettings.SectionName]; data = (CustomHandlerData)settings.ExceptionPolicies.Get(customPolicy).ExceptionTypes.Get(exceptionType).ExceptionHandlers.Get(customHandler); data.Attributes.Remove("Money"); config.Save(ConfigurationSaveMode.Full); ConfigurationManager.RefreshSection(ExceptionHandlingSettings.SectionName); settings = (ExceptionHandlingSettings)ConfigurationManager.GetSection(ExceptionHandlingSettings.SectionName); data = (CustomHandlerData)settings.ExceptionPolicies.Get(customPolicy).ExceptionTypes.Get(exceptionType).ExceptionHandlers.Get(customHandler); Assert.AreEqual(2, data.Attributes.Count); }
public void Setup() { MockExceptionHandler.Clear(); handlerData = new CustomHandlerData("custom", "an invalid type name"); handlerData.Attributes["foo"] = "bar"; }
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); container.AddExtension(new ExceptionHandlingBlockExtension()); 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); } }
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 SetUp() { provider = new ConfigurationElementManageabilityProviderWrapper(new CustomHandlerDataManageabilityProvider()); machineKey = new MockRegistryKey(true); userKey = new MockRegistryKey(true); wmiSettings = new List <ConfigurationSetting>(); configurationObject = new CustomHandlerData(); }
public void ThenCustomHandlerHasSpecifiedType() { CustomHandlerData customHandler = (CustomHandlerData)GetExceptionTypeData() .ExceptionHandlers .Where(x => x.GetType() == typeof(CustomHandlerData)) .First(); Assert.AreEqual(customHandlerType, customHandler.Type); }
public void ThenCustomHandlerHasNoAttributes() { CustomHandlerData customHandler = (CustomHandlerData)GetExceptionTypeData() .ExceptionHandlers .Where(x => x.GetType() == typeof(CustomHandlerData)) .First(); Assert.AreEqual(0, customHandler.Attributes.Count); }
public static void GenerateWmiObjects(CustomHandlerData data, ICollection <ConfigurationSetting> wmiSettings) { wmiSettings.Add( new CustomHandlerSetting(data, data.Name, data.Type.AssemblyQualifiedName, CustomDataWmiMapperHelper.GenerateAttributesArray(data.Attributes))); }
public override void Initialize(ConfigurationView configurationView) { ExceptionHandlingConfigurationView exceptionHandlingConfigurationView = (ExceptionHandlingConfigurationView)configurationView; CustomHandlerData data = (CustomHandlerData)exceptionHandlingConfigurationView.GetExceptionHandlerData(CurrentPolicyName, CurrentExceptionTypeName, ConfigurationName); if (data.Attributes["TestProperty"] != null) { testProperty = data.Attributes["TestProperty"]; } }
/// <summary> /// Initialize a new instance of the <see cref="CustomHandlerNode"/> class with a <see cref="CustomHandlerData"/> instance. /// </summary> /// <param name="customHandlerData">A <see cref="CustomHandlerData"/> instance.</param> public CustomHandlerNode(CustomHandlerData customHandlerData) { if (null == customHandlerData) throw new ArgumentNullException("customHandlerData"); Rename(customHandlerData.Name); this.type = customHandlerData.Type; foreach (string key in customHandlerData.Attributes) { editableAttributes.Add(new EditableKeyValue(key, customHandlerData.Attributes[key])); } }
/// <summary> /// Initialize a new instance of the <see cref="CustomHandlerNode"/> class with a <see cref="CustomHandlerData"/> instance. /// </summary> /// <param name="customHandlerData">A <see cref="CustomHandlerData"/> instance.</param> public CustomHandlerNode(CustomHandlerData customHandlerData) { if (null == customHandlerData) { throw new ArgumentNullException("customHandlerData"); } Rename(customHandlerData.Name); this.type = customHandlerData.Type; foreach (string key in customHandlerData.Attributes) { editableAttributes.Add(new EditableKeyValue(key, customHandlerData.Attributes[key])); } }
internal static bool SaveChanges(CustomHandlerSetting customHandlerSetting, ConfigurationElement sourceElement) { CustomHandlerData element = (CustomHandlerData)sourceElement; element.Attributes.Clear(); foreach (string attribute in customHandlerSetting.Attributes) { string[] splittedAttribute = attribute.Split('='); element.Attributes.Add(splittedAttribute[0], splittedAttribute[1]); } return(true); }
public void ThenCustomHandlerContainsAllAttributes() { CustomHandlerData customHandler = (CustomHandlerData)GetExceptionTypeData() .ExceptionHandlers .Where(x => x.GetType() == typeof(CustomHandlerData)) .First(); Assert.AreEqual(attributes.Count, customHandler.Attributes.Count); foreach (string key in attributes) { Assert.AreEqual(attributes[key], customHandler.Attributes[key]); } }
public ExceptionConfigurationCustomHandlerBuilder(IExceptionConfigurationAddExceptionHandlers context, Type customHandlerType, NameValueCollection customHandlerSettings) : base(context) { var customHandler = new CustomHandlerData { Name = customHandlerType.FullName, Type = customHandlerType }; customHandler.Attributes.Add(customHandlerSettings); CurrentExceptionTypeData.ExceptionHandlers.Add(customHandler); }
public void SavesChangesToConfigurationObject() { CustomHandlerData sourceElement = new CustomHandlerData("name", "System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); List <ConfigurationSetting> settings = new List <ConfigurationSetting>(1); CustomExceptionHandlerDataWmiMapper.GenerateWmiObjects(sourceElement, settings); Assert.AreEqual(1, settings.Count); CustomHandlerSetting setting = (CustomHandlerSetting)settings[0]; Assert.IsNotNull(setting); setting.Commit(); Assert.AreEqual(setting.ExceptionType, sourceElement.Attributes["ExceptionType"]); }
public void CustomHandlerPropertiesTest() { CustomHandlerData data = new CustomHandlerData(); string name = "Test Name"; string typeName = "Test TypeName"; NameValueItemCollection attributes = new NameValueItemCollection(); attributes.Add(new NameValueItem("TEST", "VALUE")); data.Name = name; data.TypeName = typeName; data.Attributes.Add(attributes[0]); Assert.AreEqual(name, data.Name); Assert.AreEqual(typeName, data.TypeName); Assert.AreEqual(attributes["TEST"], data.Attributes["TEST"]); }
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.AssemblyQualifiedName, node.Type); Assert.AreEqual(attributeKey, node.Attributes[0].Key); Assert.AreEqual(attributeValue, node.Attributes[0].Value); }
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 CustomHandlerGetDataTest() { CustomHandlerData data = new CustomHandlerData(); string typeName = "TestType"; string name = "TestName"; NameValueItemCollection attributes = new NameValueItemCollection(); attributes.Add(new NameValueItem("NAME", "VALUE")); data.TypeName = typeName; data.Name = name; data.Attributes.Add(attributes[0]); CustomHandlerNode node = new CustomHandlerNode(data); CreateHierarchyAndAddToHierarchyService(node, CreateDefaultConfiguration()); CustomHandlerData nodeData = (CustomHandlerData) node.ExceptionHandlerData; Assert.AreEqual(typeName, nodeData.TypeName); Assert.AreEqual(name, nodeData.Name); Assert.AreEqual(attributes["NAME"], nodeData.Attributes["NAME"]); }
public void CustomHandlerGetDataTest() { CustomHandlerData data = new CustomHandlerData(); string typeName = "TestType"; string name = "TestName"; NameValueItemCollection attributes = new NameValueItemCollection(); attributes.Add(new NameValueItem("NAME", "VALUE")); data.TypeName = typeName; data.Name = name; data.Attributes.Add(attributes[0]); CustomHandlerNode node = new CustomHandlerNode(data); CreateHierarchyAndAddToHierarchyService(node, CreateDefaultConfiguration()); CustomHandlerData nodeData = (CustomHandlerData)node.ExceptionHandlerData; Assert.AreEqual(typeName, nodeData.TypeName); Assert.AreEqual(name, nodeData.Name); Assert.AreEqual(attributes["NAME"], nodeData.Attributes["NAME"]); }
public void Setup() { handlerData = new CustomHandlerData("custom", typeof(MockExceptionHandler)); handlerData.Attributes["foo"] = "bar"; }
/// <summary> /// Initializes node with specified data. /// </summary> /// <param name="customHandlerData">Sepecified configuration data.</param> public CustomHandlerNode(CustomHandlerData customHandlerData) : base(customHandlerData) { this.customHandlerData = customHandlerData; }
public MockThrowingExceptionHandler(CustomHandlerData customHandlerData) : this() { }