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); }
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 ProviderThrowsWithConfigurationObjectOfWrongType() { provider.OverrideWithGroupPoliciesAndGenerateWmiObjects(new TestsConfigurationSection(), true, machineKey, userKey, true, wmiSettings); }
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)); }