public void RegisteredHandlerDataProviderIsCalledWithNoOverrides() { MockConfigurationElementManageabilityProvider registeredProvider = new MockConfigurationElementManageabilityProvider(); Dictionary <Type, ConfigurationElementManageabilityProvider> subProviders = new Dictionary <Type, ConfigurationElementManageabilityProvider>(); subProviders.Add(typeof(ReplaceHandlerData), registeredProvider); provider = new ExceptionHandlingSettingsManageabilityProvider(subProviders); ExceptionPolicyData policy1 = new ExceptionPolicyData("policy1"); section.ExceptionPolicies.Add(policy1); ExceptionTypeData exceptionType1 = new ExceptionTypeData("type1", typeof(Exception), PostHandlingAction.None); policy1.ExceptionTypes.Add(exceptionType1); ExceptionHandlerData handlerData1 = new ReplaceHandlerData("handler1", "msg", typeof(ArgumentException).AssemblyQualifiedName); exceptionType1.ExceptionHandlers.Add(handlerData1); provider.OverrideWithGroupPoliciesAndGenerateWmiObjects(section, true, machineKey, userKey, false, wmiSettings); Assert.IsTrue(registeredProvider.called); Assert.AreSame(handlerData1, registeredProvider.LastConfigurationObject); Assert.AreEqual(null, registeredProvider.machineKey); Assert.AreEqual(null, registeredProvider.userKey); }
public void SetUp() { provider = new ReplaceHandlerDataManageabilityProvider(); machineKey = new MockRegistryKey(true); userKey = new MockRegistryKey(true); configurationObject = new ReplaceHandlerData(); }
public void WmiSettingsForExceptionHandlerAreGeneratedWithCorrectPolicyAndTypeIfWmiIsEnabled() { Dictionary <Type, ConfigurationElementManageabilityProvider> subProviders = new Dictionary <Type, ConfigurationElementManageabilityProvider>(); subProviders.Add(typeof(ReplaceHandlerData), new ReplaceHandlerDataManageabilityProvider()); provider = new ExceptionHandlingSettingsManageabilityProvider(subProviders); ExceptionPolicyData policy1 = new ExceptionPolicyData("policy1"); section.ExceptionPolicies.Add(policy1); ExceptionTypeData exceptionType1 = new ExceptionTypeData("type1", typeof(Exception), PostHandlingAction.None); policy1.ExceptionTypes.Add(exceptionType1); ReplaceHandlerData handler1 = new ReplaceHandlerData("handler1", "message", typeof(ArgumentNullException).AssemblyQualifiedName); exceptionType1.ExceptionHandlers.Add(handler1); provider.OverrideWithGroupPoliciesAndGenerateWmiObjects(section, false, machineKey, userKey, true, wmiSettings); Assert.AreEqual(3, wmiSettings.Count); IDictionary <String, ExceptionHandlerSetting> handlerSettings = SelectWmiSettings <ExceptionHandlerSetting>(wmiSettings); Assert.AreEqual(1, handlerSettings.Count); Assert.IsTrue(handlerSettings.ContainsKey("handler1")); Assert.AreEqual("message", ((ReplaceHandlerSetting)handlerSettings["handler1"]).ExceptionMessage); Assert.AreEqual(typeof(ArgumentNullException).AssemblyQualifiedName, ((ReplaceHandlerSetting)handlerSettings["handler1"]).ReplaceExceptionType); Assert.AreEqual("policy1", handlerSettings["handler1"].Policy); Assert.AreEqual("type1", handlerSettings["handler1"].ExceptionType); Assert.AreEqual(0, handlerSettings["handler1"].Order); }
/// <summary> /// Initialize a new instance of the <see cref="ReplaceHandlerNode"/> class with a <see cref="ReplaceHandlerData"/> instance. /// </summary> /// <param name="replaceHandlerData">A <see cref="ReplaceHandlerData"/> instance</param> public ReplaceHandlerNode(ReplaceHandlerData replaceHandlerData) { if (null == replaceHandlerData) throw new ArgumentNullException("replaceHandlerData"); Rename(replaceHandlerData.Name); this.message = replaceHandlerData.ExceptionMessage; this.type = replaceHandlerData.ReplaceExceptionType; }
public void Setup() { handlerData = new ReplaceHandlerData( "replace", "exception", typeof(Exception).AssemblyQualifiedName); }
public void CanGetExceptionMessageFromResource() { const string resourceName = "ExceptionMessage"; ExceptionPolicyData exceptionPolicyData = new ExceptionPolicyData("policy"); settings.ExceptionPolicies.Add(exceptionPolicyData); ExceptionTypeData exceptionTypeData = new ExceptionTypeData("type1", typeof(Exception), PostHandlingAction.ThrowNewException); exceptionPolicyData.ExceptionTypes.Add(exceptionTypeData); ReplaceHandlerData exceptionHandlerData = new ReplaceHandlerData("handler1", "replaced", typeof(ArgumentException).AssemblyQualifiedName); exceptionHandlerData.ExceptionMessageResourceName = resourceName; exceptionHandlerData.ExceptionMessageResourceType = typeof(Resources).AssemblyQualifiedName; string resourceValue = Resources.ExceptionMessage; 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 (ArgumentException e) { Assert.AreEqual(resourceValue, e.Message); Assert.IsNull(e.InnerException); } }
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); ExceptionHandlerData exceptionHandlerData = new ReplaceHandlerData("handler1", "replaced", typeof(ArgumentException).AssemblyQualifiedName); 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 (ArgumentException e) { Assert.AreEqual("replaced", e.Message); Assert.IsNull(e.InnerException); } }
public void Setup() { handlerData = new ReplaceHandlerData("replace", "exception", typeof(Exception).AssemblyQualifiedName) { ExceptionMessageResourceName = "ExceptionMessage", ExceptionMessageResourceType = typeof(Resources).AssemblyQualifiedName }; }
public void SetUp() { provider = new ConfigurationElementManageabilityProviderWrapper(new ReplaceHandlerDataManageabilityProvider()); machineKey = new MockRegistryKey(true); userKey = new MockRegistryKey(true); wmiSettings = new List <ConfigurationSetting>(); configurationObject = new ReplaceHandlerData(); }
public static bool SaveChanges(ReplaceHandlerSetting replaceHandlerSettingSetting, ConfigurationElement sourceElement) { ReplaceHandlerData element = (ReplaceHandlerData)sourceElement; element.ReplaceExceptionTypeName = replaceHandlerSettingSetting.ReplaceExceptionType; element.ExceptionMessage = replaceHandlerSettingSetting.ExceptionMessage; return(true); }
public static void GenerateWmiObjects(ReplaceHandlerData configurationObject, ICollection <ConfigurationSetting> wmiSettings) { wmiSettings.Add( new ReplaceHandlerSetting(configurationObject, configurationObject.Name, configurationObject.ExceptionMessage, configurationObject.ReplaceExceptionType.AssemblyQualifiedName)); }
/// <summary> /// Initialize a new instance of the <see cref="ReplaceHandlerNode"/> class with a <see cref="ReplaceHandlerData"/> instance. /// </summary> /// <param name="replaceHandlerData">A <see cref="ReplaceHandlerData"/> instance</param> public ReplaceHandlerNode(ReplaceHandlerData replaceHandlerData) { if (null == replaceHandlerData) { throw new ArgumentNullException("replaceHandlerData"); } Rename(replaceHandlerData.Name); this.message = replaceHandlerData.ExceptionMessage; this.type = replaceHandlerData.ReplaceExceptionType; }
public void CanGetExceptionMessageFromResourceForDifferentLocales() { const string resourceName = "ExceptionMessage"; ExceptionPolicyData exceptionPolicyData = new ExceptionPolicyData("policy"); settings.ExceptionPolicies.Add(exceptionPolicyData); ExceptionTypeData exceptionTypeData = new ExceptionTypeData("type1", typeof(Exception), PostHandlingAction.ThrowNewException); exceptionPolicyData.ExceptionTypes.Add(exceptionTypeData); ReplaceHandlerData exceptionHandlerData = new ReplaceHandlerData("handler1", "replaced", typeof(ArgumentException).AssemblyQualifiedName); exceptionHandlerData.ExceptionMessageResourceName = resourceName; exceptionHandlerData.ExceptionMessageResourceType = typeof(Resources).AssemblyQualifiedName; exceptionTypeData.ExceptionHandlers.Add(exceptionHandlerData); container.AddExtension(new ExceptionHandlingBlockExtension()); ExceptionPolicyImpl policy = container.Resolve <ExceptionPolicyImpl>("policy"); Exception originalException = new Exception("to be replaced"); string enMessage = null; string esMessage = null; CultureInfo currentUICulture = CultureInfo.CurrentUICulture; try { Thread.CurrentThread.CurrentUICulture = new CultureInfo("en"); try { policy.HandleException(originalException); Assert.Fail("a new exception should have been thrown"); } catch (ArgumentException e) { Assert.AreEqual(Resources.ExceptionMessage, e.Message); Assert.IsNull(e.InnerException); enMessage = e.Message; } Thread.CurrentThread.CurrentUICulture = new CultureInfo("es"); try { policy.HandleException(originalException); Assert.Fail("a new exception should have been thrown"); } catch (ArgumentException e) { Assert.AreEqual(Resources.ExceptionMessage, e.Message); Assert.IsNull(e.InnerException); esMessage = e.Message; } Assert.AreNotEqual(enMessage, esMessage); } finally { Thread.CurrentThread.CurrentUICulture = currentUICulture; } }
public ExceptionConfigurationReplaceWithBuilder(IExceptionConfigurationAddExceptionHandlers context, Type replacingExceptionType) : base(context) { replaceHandlerData = new ReplaceHandlerData() { Name = replacingExceptionType.FullName, ReplaceExceptionType = replacingExceptionType }; base.CurrentExceptionTypeData.ExceptionHandlers.Add(replaceHandlerData); }
/// <summary> /// <para>Initializes the provider with a <see cref="ExceptionHandlingConfigurationView"/>.</para> /// </summary> /// <param name="configurationView"> /// <para>A <see cref="ExceptionHandlingConfigurationView"/> object.</para> /// </param> public override void Initialize(ConfigurationView configurationView) { ArgumentValidation.CheckForNullReference(configurationView, "configurationView"); ArgumentValidation.CheckExpectedType(configurationView, typeof(ExceptionHandlingConfigurationView)); ExceptionHandlingConfigurationView exceptionHandlingConfigurationView = (ExceptionHandlingConfigurationView)configurationView; ExceptionHandlerData exceptionHandlerData = exceptionHandlingConfigurationView.GetExceptionHandlerData(CurrentPolicyName, CurrentExceptionTypeName, ConfigurationName); ArgumentValidation.CheckExpectedType(exceptionHandlerData, typeof(ReplaceHandlerData)); replaceHandlerData = (ReplaceHandlerData)exceptionHandlerData; }
public void ReplaceHandlerPropertiesTest() { ReplaceHandlerData data = new ReplaceHandlerData(); string exceptionMessage = "test message"; string replaceExecptionTypeName = "Test Replace TypeName"; data.ExceptionMessage = exceptionMessage; data.ReplaceExceptionTypeName = replaceExecptionTypeName; Assert.AreEqual(exceptionMessage, data.ExceptionMessage); Assert.AreEqual(replaceExecptionTypeName, data.ReplaceExceptionTypeName); }
public void Then_ConfigurationSectionMatchesConfiguration() { var policyData = base.GetExceptionPolicyData(); Assert.AreEqual(policyName, policyData.Name); var exceptionData = policyData.ExceptionTypes.Single <ExceptionTypeData>(); Assert.AreSame(typeof(ArgumentNullException), exceptionData.Type); Assert.AreEqual(PostHandlingAction.None, exceptionData.PostHandlingAction); ReplaceHandlerData handlerData = exceptionData.ExceptionHandlers.Single() as ReplaceHandlerData; Assert.AreEqual("An exception occurred somewhere", handlerData.ExceptionMessage); }
public void ReplaceHandlerGetDataTest() { ReplaceHandlerData data = new ReplaceHandlerData(); string replaceExceptionTypeName = "TestType"; string name = "ReplaceHandler"; data.ReplaceExceptionTypeName = replaceExceptionTypeName; data.Name = name; ReplaceHandlerNode node = new ReplaceHandlerNode(data); CreateHierarchyAndAddToHierarchyService(node, CreateDefaultConfiguration()); ReplaceHandlerData nodeData = (ReplaceHandlerData) node.ExceptionHandlerData; Assert.AreEqual(name, nodeData.Name); Assert.AreEqual(replaceExceptionTypeName, nodeData.ReplaceExceptionTypeName); }
public void SavesChangesToConfigurationObject() { ReplaceHandlerData sourceElement = new ReplaceHandlerData("name", "ExcpetionMessage", "System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); List <ConfigurationSetting> settings = new List <ConfigurationSetting>(1); ReplaceHandlerDataWmiMapper.GenerateWmiObjects(sourceElement, settings); Assert.AreEqual(1, settings.Count); ReplaceHandlerSetting setting = settings[0] as ReplaceHandlerSetting; Assert.IsNotNull(setting); setting.ExceptionMessage = "Changed"; setting.Commit(); Assert.AreEqual(setting.ExceptionMessage, sourceElement.ExceptionMessage); Assert.AreEqual(setting.ReplaceExceptionType, sourceElement.ReplaceExceptionTypeName); }
public void ReplaceHandlerGetDataTest() { ReplaceHandlerData data = new ReplaceHandlerData(); string replaceExceptionTypeName = "TestType"; string name = "ReplaceHandler"; data.ReplaceExceptionTypeName = replaceExceptionTypeName; data.Name = name; ReplaceHandlerNode node = new ReplaceHandlerNode(data); CreateHierarchyAndAddToHierarchyService(node, CreateDefaultConfiguration()); ReplaceHandlerData nodeData = (ReplaceHandlerData)node.ExceptionHandlerData; Assert.AreEqual(name, nodeData.Name); Assert.AreEqual(replaceExceptionTypeName, nodeData.ReplaceExceptionTypeName); }
public void ReplaceHandlerDataTest() { string name = "some name"; string message = "some message"; Type replaceExceptionType = typeof(ApplicationException); ReplaceHandlerData data = new ReplaceHandlerData(); data.Name = name; data.ExceptionMessage = message; data.ReplaceExceptionType = replaceExceptionType; ReplaceHandlerNode node = new ReplaceHandlerNode(data); Assert.AreEqual(name, node.Name); Assert.AreEqual(message, node.ExceptionMessage); Assert.AreEqual(replaceExceptionType, node.ReplaceExceptionType); }
void IContainerPolicyCreator.CreatePolicies( IPolicyList policyList, string instanceName, ConfigurationElement configurationObject, IConfigurationSource configurationSource) { ReplaceHandlerData castConfigurationObject = (ReplaceHandlerData)configurationObject; new PolicyBuilder <ReplaceHandler, ReplaceHandlerData>( NamedTypeBuildKey.Make <ReplaceHandler>(instanceName), castConfigurationObject, c => new ReplaceHandler( new ResourceStringResolver( c.ExceptionMessageResourceType, c.ExceptionMessageResourceName, c.ExceptionMessage), c.ReplaceExceptionType)) .AddPoliciesToPolicyList(policyList); }
public void ReplaceHandlerNodeDataTest() { string name = "some name"; string message = "some message"; Type replaceExceptionType = typeof(ApplicationException); string resourceName = "resource name"; string resourceType = "resource type"; ReplaceHandlerData replaceHandlerData = new ReplaceHandlerData(); replaceHandlerData.Name = name; replaceHandlerData.ExceptionMessage = message; replaceHandlerData.ReplaceExceptionType = replaceExceptionType; replaceHandlerData.ExceptionMessageResourceName = resourceName; replaceHandlerData.ExceptionMessageResourceType = resourceType; ReplaceHandlerNode replaceHandlerNode = new ReplaceHandlerNode(replaceHandlerData); ReplaceHandlerData nodeData = (ReplaceHandlerData)replaceHandlerNode.ExceptionHandlerData; Assert.AreEqual(name, nodeData.Name); Assert.AreEqual(message, nodeData.ExceptionMessage); Assert.AreEqual(replaceExceptionType, nodeData.ReplaceExceptionType); Assert.AreEqual(resourceName, nodeData.ExceptionMessageResourceName); Assert.AreEqual(resourceType, nodeData.ExceptionMessageResourceType); }
public void Setup() { handlerData = new ReplaceHandlerData("replace", "exception", typeof(Exception).AssemblyQualifiedName); }
public void RegisteredHandlerDataProviderIsCalledWithCorrectOverrides() { MockConfigurationElementManageabilityProvider registeredProvider = new MockConfigurationElementManageabilityProvider(); Dictionary <Type, ConfigurationElementManageabilityProvider> subProviders = new Dictionary <Type, ConfigurationElementManageabilityProvider>(); subProviders.Add(typeof(ReplaceHandlerData), registeredProvider); provider = new ExceptionHandlingSettingsManageabilityProvider(subProviders); ExceptionPolicyData policy1 = new ExceptionPolicyData("policy1"); section.ExceptionPolicies.Add(policy1); ExceptionTypeData exceptionType1 = new ExceptionTypeData("type1", typeof(Exception), PostHandlingAction.None); policy1.ExceptionTypes.Add(exceptionType1); ExceptionHandlerData handlerData1 = new ReplaceHandlerData("handler1", "msg", typeof(ArgumentException).AssemblyQualifiedName); exceptionType1.ExceptionHandlers.Add(handlerData1); MockRegistryKey machinePoliciesKey = new MockRegistryKey(false); machineKey.AddSubKey(ExceptionHandlingSettingsManageabilityProvider.PoliciesKeyName, machinePoliciesKey); MockRegistryKey machinePolicy1Key = new MockRegistryKey(false); machinePoliciesKey.AddSubKey("policy1", machinePolicy1Key); MockRegistryKey machinePolicy1TypesKey = new MockRegistryKey(false); machinePolicy1Key.AddSubKey(ExceptionHandlingSettingsManageabilityProvider.PolicyTypesPropertyName, machinePolicy1TypesKey); MockRegistryKey machinePolicy1Type1Key = new MockRegistryKey(false); machinePolicy1TypesKey.AddSubKey("type1", machinePolicy1Type1Key); MockRegistryKey machineHandlersKey = new MockRegistryKey(false); machinePolicy1Type1Key.AddSubKey(ExceptionHandlingSettingsManageabilityProvider.PolicyTypeHandlersPropertyName, machineHandlersKey); machinePolicy1Type1Key.AddEnumValue( ExceptionHandlingSettingsManageabilityProvider.PolicyTypePostHandlingActionPropertyName, PostHandlingAction.None); MockRegistryKey machineHandlerKey = new MockRegistryKey(false); machineHandlersKey.AddSubKey("handler1", machineHandlerKey); MockRegistryKey userPoliciesKey = new MockRegistryKey(false); userKey.AddSubKey(ExceptionHandlingSettingsManageabilityProvider.PoliciesKeyName, userPoliciesKey); MockRegistryKey userPolicy1Key = new MockRegistryKey(false); userPoliciesKey.AddSubKey("policy1", userPolicy1Key); MockRegistryKey userPolicy1TypesKey = new MockRegistryKey(false); userPolicy1Key.AddSubKey(ExceptionHandlingSettingsManageabilityProvider.PolicyTypesPropertyName, userPolicy1TypesKey); MockRegistryKey userPolicy1Type1Key = new MockRegistryKey(false); userPolicy1TypesKey.AddSubKey("type1", userPolicy1Type1Key); MockRegistryKey userHandlersKey = new MockRegistryKey(false); userPolicy1Type1Key.AddSubKey(ExceptionHandlingSettingsManageabilityProvider.PolicyTypeHandlersPropertyName, userHandlersKey); userPolicy1Type1Key.AddEnumValue( ExceptionHandlingSettingsManageabilityProvider.PolicyTypePostHandlingActionPropertyName, PostHandlingAction.None); MockRegistryKey userHandlerKey = new MockRegistryKey(false); userHandlersKey.AddSubKey("handler1", userHandlerKey); provider.OverrideWithGroupPoliciesAndGenerateWmiObjects(section, true, machineKey, userKey, false, wmiSettings); Assert.IsTrue(registeredProvider.called); Assert.AreSame(handlerData1, registeredProvider.LastConfigurationObject); Assert.AreSame(machineHandlerKey, registeredProvider.machineKey); Assert.AreSame(userHandlerKey, registeredProvider.userKey); Assert.IsTrue(MockRegistryKey.CheckAllClosed(machinePoliciesKey, machinePolicy1Key, machinePolicy1TypesKey, machinePolicy1Type1Key, machineHandlersKey, machineHandlerKey, userPolicy1Key, userPolicy1TypesKey, userPolicy1Type1Key, userHandlersKey, userHandlerKey)); }
/// <summary> /// Constructs the node with config data. /// </summary> /// <param name="replaceHandlerData">The config data to initialize this node.</param> public ReplaceHandlerNode(ReplaceHandlerData replaceHandlerData) : base(replaceHandlerData) { this.replaceHandlerData = replaceHandlerData; }
public void RegisteredHandlerDataProviderIsCalledWithCorrectOverrides() { MockConfigurationElementManageabilityProvider registeredProvider = new MockConfigurationElementManageabilityProvider(); Dictionary<Type, ConfigurationElementManageabilityProvider> subProviders = new Dictionary<Type, ConfigurationElementManageabilityProvider>(); subProviders.Add(typeof(ReplaceHandlerData), registeredProvider); provider = new ExceptionHandlingSettingsManageabilityProvider(subProviders); ExceptionPolicyData policy1 = new ExceptionPolicyData("policy1"); section.ExceptionPolicies.Add(policy1); ExceptionTypeData exceptionType1 = new ExceptionTypeData("type1", typeof(Exception), PostHandlingAction.None); policy1.ExceptionTypes.Add(exceptionType1); ExceptionHandlerData handlerData1 = new ReplaceHandlerData("handler1", "msg", typeof(ArgumentException).AssemblyQualifiedName); exceptionType1.ExceptionHandlers.Add(handlerData1); MockRegistryKey machinePoliciesKey = new MockRegistryKey(false); machineKey.AddSubKey(ExceptionHandlingSettingsManageabilityProvider.PoliciesKeyName, machinePoliciesKey); MockRegistryKey machinePolicy1Key = new MockRegistryKey(false); machinePoliciesKey.AddSubKey("policy1", machinePolicy1Key); MockRegistryKey machinePolicy1TypesKey = new MockRegistryKey(false); machinePolicy1Key.AddSubKey(ExceptionHandlingSettingsManageabilityProvider.PolicyTypesPropertyName, machinePolicy1TypesKey); MockRegistryKey machinePolicy1Type1Key = new MockRegistryKey(false); machinePolicy1TypesKey.AddSubKey("type1", machinePolicy1Type1Key); MockRegistryKey machineHandlersKey = new MockRegistryKey(false); machinePolicy1Type1Key.AddSubKey(ExceptionHandlingSettingsManageabilityProvider.PolicyTypeHandlersPropertyName, machineHandlersKey); machinePolicy1Type1Key.AddEnumValue( ExceptionHandlingSettingsManageabilityProvider.PolicyTypePostHandlingActionPropertyName, PostHandlingAction.None); MockRegistryKey machineHandlerKey = new MockRegistryKey(false); machineHandlersKey.AddSubKey("handler1", machineHandlerKey); MockRegistryKey userPoliciesKey = new MockRegistryKey(false); userKey.AddSubKey(ExceptionHandlingSettingsManageabilityProvider.PoliciesKeyName, userPoliciesKey); MockRegistryKey userPolicy1Key = new MockRegistryKey(false); userPoliciesKey.AddSubKey("policy1", userPolicy1Key); MockRegistryKey userPolicy1TypesKey = new MockRegistryKey(false); userPolicy1Key.AddSubKey(ExceptionHandlingSettingsManageabilityProvider.PolicyTypesPropertyName, userPolicy1TypesKey); MockRegistryKey userPolicy1Type1Key = new MockRegistryKey(false); userPolicy1TypesKey.AddSubKey("type1", userPolicy1Type1Key); MockRegistryKey userHandlersKey = new MockRegistryKey(false); userPolicy1Type1Key.AddSubKey(ExceptionHandlingSettingsManageabilityProvider.PolicyTypeHandlersPropertyName, userHandlersKey); userPolicy1Type1Key.AddEnumValue( ExceptionHandlingSettingsManageabilityProvider.PolicyTypePostHandlingActionPropertyName, PostHandlingAction.None); MockRegistryKey userHandlerKey = new MockRegistryKey(false); userHandlersKey.AddSubKey("handler1", userHandlerKey); provider.OverrideWithGroupPolicies(section, true, machineKey, userKey); Assert.IsTrue(registeredProvider.called); Assert.AreSame(handlerData1, registeredProvider.LastConfigurationObject); Assert.AreSame(machineHandlerKey, registeredProvider.machineKey); Assert.AreSame(userHandlerKey, registeredProvider.userKey); Assert.IsTrue(MockRegistryKey.CheckAllClosed(machinePoliciesKey, machinePolicy1Key, machinePolicy1TypesKey, machinePolicy1Type1Key, machineHandlersKey, machineHandlerKey, userPolicy1Key, userPolicy1TypesKey, userPolicy1Type1Key, userHandlersKey, userHandlerKey)); }
public void RegisteredHandlerDataProviderIsCalledWithNoOverrides() { MockConfigurationElementManageabilityProvider registeredProvider = new MockConfigurationElementManageabilityProvider(); Dictionary<Type, ConfigurationElementManageabilityProvider> subProviders = new Dictionary<Type, ConfigurationElementManageabilityProvider>(); subProviders.Add(typeof(ReplaceHandlerData), registeredProvider); provider = new ExceptionHandlingSettingsManageabilityProvider(subProviders); ExceptionPolicyData policy1 = new ExceptionPolicyData("policy1"); section.ExceptionPolicies.Add(policy1); ExceptionTypeData exceptionType1 = new ExceptionTypeData("type1", typeof(Exception), PostHandlingAction.None); policy1.ExceptionTypes.Add(exceptionType1); ExceptionHandlerData handlerData1 = new ReplaceHandlerData("handler1", "msg", typeof(ArgumentException).AssemblyQualifiedName); exceptionType1.ExceptionHandlers.Add(handlerData1); provider.OverrideWithGroupPolicies(section, true, machineKey, userKey); Assert.IsTrue(registeredProvider.called); Assert.AreSame(handlerData1, registeredProvider.LastConfigurationObject); Assert.AreEqual(null, registeredProvider.machineKey); Assert.AreEqual(null, registeredProvider.userKey); }