Exemple #1
0
        public void ConfigurationObjectIsModifiedIfThereAreUserPolicyOverrides()
        {
            configurationObject.FileName  = "file name";
            configurationObject.Formatter = "formatter";
            configurationObject.RollFileExistsBehavior = RollFileExistsBehavior.Increment;
            configurationObject.RollInterval           = RollInterval.Month;
            configurationObject.RollSizeKB             = 100;
            configurationObject.TimeStampPattern       = "pattern";
            configurationObject.TraceOutputOptions     = TraceOptions.None;
            configurationObject.Header = "header";
            configurationObject.Footer = "footer";

            userKey.AddStringValue(RollingFlatFileTraceListenerDataManageabilityProvider.FileNamePropertyName, "overriden file name");
            userKey.AddStringValue(RollingFlatFileTraceListenerDataManageabilityProvider.FormatterPropertyName, "overriden formatter");
            userKey.AddEnumValue <RollFileExistsBehavior>(RollingFlatFileTraceListenerDataManageabilityProvider.RollFileExistsBehaviorPropertyName, RollFileExistsBehavior.Overwrite);
            userKey.AddEnumValue <RollInterval>(RollingFlatFileTraceListenerDataManageabilityProvider.RollIntervalPropertyName, RollInterval.Day);
            userKey.AddIntValue(RollingFlatFileTraceListenerDataManageabilityProvider.RollSizeKBPropertyName, 200);
            userKey.AddStringValue(RollingFlatFileTraceListenerDataManageabilityProvider.TimeStampPatternPropertyName, "overriden pattern");
            userKey.AddEnumValue <TraceOptions>(RollingFlatFileTraceListenerDataManageabilityProvider.TraceOutputOptionsPropertyName, TraceOptions.ProcessId | TraceOptions.ThreadId);
            userKey.AddStringValue(RollingFlatFileTraceListenerDataManageabilityProvider.HeaderPropertyName, "overriden header");
            userKey.AddStringValue(RollingFlatFileTraceListenerDataManageabilityProvider.FooterPropertyName, "overriden footer");

            provider.InvokeOverrideWithGroupPoliciesAndGenerateWmiObjects(configurationObject, true, null, userKey, true, wmiSettings);

            Assert.AreEqual("overriden file name", configurationObject.FileName);
            Assert.AreEqual("overriden formatter", configurationObject.Formatter);
            Assert.AreEqual(RollFileExistsBehavior.Overwrite, configurationObject.RollFileExistsBehavior);
            Assert.AreEqual(RollInterval.Day, configurationObject.RollInterval);
            Assert.AreEqual(200, configurationObject.RollSizeKB);
            Assert.AreEqual("overriden pattern", configurationObject.TimeStampPattern);
            Assert.AreEqual(TraceOptions.ProcessId | TraceOptions.ThreadId, configurationObject.TraceOutputOptions);
            Assert.AreEqual("overriden header", configurationObject.Header);
            Assert.AreEqual("overriden footer", configurationObject.Footer);
        }
        public void ConfigurationObjectIsModifiedIfThereAreUserPolicyOverrides()
        {
            configurationObject.FileName  = "file name";
            configurationObject.Formatter = "formatter";
            configurationObject.RollFileExistsBehavior = RollFileExistsBehavior.Increment;
            configurationObject.RollInterval           = RollInterval.Month;
            configurationObject.RollSizeKB             = 100;
            configurationObject.TimeStampPattern       = "pattern";
            configurationObject.TraceOutputOptions     = TraceOptions.None;
            configurationObject.Filter           = SourceLevels.Error;
            configurationObject.Header           = "header";
            configurationObject.Footer           = "footer";
            configurationObject.MaxArchivedFiles = 10;

            userKey.AddStringValue(RollingFlatFileTraceListenerDataManageabilityProvider.FileNamePropertyName, "overriden file name");
            userKey.AddStringValue(RollingFlatFileTraceListenerDataManageabilityProvider.FormatterPropertyName, "overriden formatter");
            userKey.AddEnumValue <RollFileExistsBehavior>(RollingFlatFileTraceListenerDataManageabilityProvider.RollFileExistsBehaviorPropertyName, RollFileExistsBehavior.Overwrite);
            userKey.AddEnumValue <RollInterval>(RollingFlatFileTraceListenerDataManageabilityProvider.RollIntervalPropertyName, RollInterval.Day);
            userKey.AddIntValue(RollingFlatFileTraceListenerDataManageabilityProvider.RollSizeKBPropertyName, 200);
            userKey.AddStringValue(RollingFlatFileTraceListenerDataManageabilityProvider.TimeStampPatternPropertyName, "overriden pattern");
            userKey.AddEnumValue <SourceLevels>(RollingFlatFileTraceListenerDataManageabilityProvider.FilterPropertyName, SourceLevels.Critical);
            userKey.AddStringValue(RollingFlatFileTraceListenerDataManageabilityProvider.HeaderPropertyName, "overriden header");
            userKey.AddStringValue(RollingFlatFileTraceListenerDataManageabilityProvider.FooterPropertyName, "overriden footer");
            userKey.AddIntValue(RollingFlatFileTraceListenerDataManageabilityProvider.MaxArchivedFilesPropertyName, 20);
            userKey.AddSubKey(RollingFlatFileTraceListenerDataManageabilityProvider.TraceOutputOptionsPropertyName, userOptionsKey);
            userOptionsKey.AddIntValue(TraceOptions.ProcessId.ToString(), 1);
            userOptionsKey.AddIntValue(TraceOptions.ThreadId.ToString(), 1);

            provider.OverrideWithGroupPolicies(configurationObject, true, null, userKey);

            Assert.AreEqual("overriden file name", configurationObject.FileName);
            Assert.AreEqual("overriden formatter", configurationObject.Formatter);
            Assert.AreEqual(RollFileExistsBehavior.Overwrite, configurationObject.RollFileExistsBehavior);
            Assert.AreEqual(RollInterval.Day, configurationObject.RollInterval);
            Assert.AreEqual(200, configurationObject.RollSizeKB);
            Assert.AreEqual("overriden pattern", configurationObject.TimeStampPattern);
            Assert.AreEqual(TraceOptions.ProcessId | TraceOptions.ThreadId, configurationObject.TraceOutputOptions);
            Assert.AreEqual(SourceLevels.Critical, configurationObject.Filter);
            Assert.AreEqual("overriden header", configurationObject.Header);
            Assert.AreEqual("overriden footer", configurationObject.Footer);
            Assert.AreEqual(20, configurationObject.MaxArchivedFiles);
        }
        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));
        }
        public void ExceptionTypeWithDisabledPolicyIsRemoved()
        {
            ExceptionPolicyData policy1 = new ExceptionPolicyData("policy1");

            section.ExceptionPolicies.Add(policy1);
            ExceptionTypeData exceptionType11 = new ExceptionTypeData("type11", typeof(Exception), PostHandlingAction.None);

            policy1.ExceptionTypes.Add(exceptionType11);
            ExceptionTypeData exceptionType12 = new ExceptionTypeData("type12", typeof(Exception), PostHandlingAction.None);

            policy1.ExceptionTypes.Add(exceptionType12);
            ExceptionPolicyData policy2 = new ExceptionPolicyData("policy2");

            section.ExceptionPolicies.Add(policy2);
            ExceptionTypeData exceptionType21 = new ExceptionTypeData("type21", typeof(Exception), PostHandlingAction.None);

            policy2.ExceptionTypes.Add(exceptionType21);

            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 userPolicy1Type11Key = new MockRegistryKey(false);

            userPolicy1TypesKey.AddSubKey("type11", userPolicy1Type11Key);
            userPolicy1Type11Key.AddBooleanValue(ExceptionHandlingSettingsManageabilityProvider.PolicyValueName, false);
            userPolicy1Type11Key.AddEnumValue(
                ExceptionHandlingSettingsManageabilityProvider.PolicyTypePostHandlingActionPropertyName, PostHandlingAction.None);
            MockRegistryKey userPolicy1Type12Key = new MockRegistryKey(false);

            userPolicy1TypesKey.AddSubKey("type12", userPolicy1Type12Key);
            userPolicy1Type12Key.AddBooleanValue(ExceptionHandlingSettingsManageabilityProvider.PolicyValueName, true);
            userPolicy1Type12Key.AddEnumValue(
                ExceptionHandlingSettingsManageabilityProvider.PolicyTypePostHandlingActionPropertyName, PostHandlingAction.None);
            MockRegistryKey userPolicy2Key = new MockRegistryKey(false);

            userPoliciesKey.AddSubKey("policy2", userPolicy2Key);
            MockRegistryKey userPolicy2TypesKey = new MockRegistryKey(false);

            userPolicy2Key.AddSubKey(ExceptionHandlingSettingsManageabilityProvider.PolicyTypesPropertyName, userPolicy2TypesKey);
            MockRegistryKey userPolicy2Type21Key = new MockRegistryKey(false);

            userPolicy2TypesKey.AddSubKey("type21", userPolicy2Type21Key);
            userPolicy2Type21Key.AddBooleanValue(ExceptionHandlingSettingsManageabilityProvider.PolicyValueName, false);
            userPolicy2Type21Key.AddEnumValue(
                ExceptionHandlingSettingsManageabilityProvider.PolicyTypePostHandlingActionPropertyName, PostHandlingAction.None);

            provider.OverrideWithGroupPoliciesAndGenerateWmiObjects(section, true, machineKey, userKey, true, wmiSettings);

            Assert.AreEqual(2, section.ExceptionPolicies.Count);
            Assert.IsNotNull(section.ExceptionPolicies.Get("policy1"));
            Assert.AreEqual(1, section.ExceptionPolicies.Get("policy1").ExceptionTypes.Count);
            Assert.IsNotNull(section.ExceptionPolicies.Get("policy1").ExceptionTypes.Get("type12"));
            Assert.IsNotNull(section.ExceptionPolicies.Get("policy2"));
            Assert.AreEqual(0, section.ExceptionPolicies.Get("policy2").ExceptionTypes.Count);

            Assert.IsTrue(MockRegistryKey.CheckAllClosed(userPoliciesKey,
                                                         userPolicy1Key, userPolicy1TypesKey, userPolicy1Type11Key,
                                                         userPolicy1Type12Key,
                                                         userPolicy2Key, userPolicy2TypesKey, userPolicy2Type21Key));
        }
        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 ExceptionTypeWithDisabledPolicyIsRemoved()
        {
            ExceptionPolicyData policy1 = new ExceptionPolicyData("policy1");
            section.ExceptionPolicies.Add(policy1);
            ExceptionTypeData exceptionType11 = new ExceptionTypeData("type11", typeof(Exception), PostHandlingAction.None);
            policy1.ExceptionTypes.Add(exceptionType11);
            ExceptionTypeData exceptionType12 = new ExceptionTypeData("type12", typeof(Exception), PostHandlingAction.None);
            policy1.ExceptionTypes.Add(exceptionType12);
            ExceptionPolicyData policy2 = new ExceptionPolicyData("policy2");
            section.ExceptionPolicies.Add(policy2);
            ExceptionTypeData exceptionType21 = new ExceptionTypeData("type21", typeof(Exception), PostHandlingAction.None);
            policy2.ExceptionTypes.Add(exceptionType21);

            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 userPolicy1Type11Key = new MockRegistryKey(false);
            userPolicy1TypesKey.AddSubKey("type11", userPolicy1Type11Key);
            userPolicy1Type11Key.AddBooleanValue(ExceptionHandlingSettingsManageabilityProvider.PolicyValueName, false);
            userPolicy1Type11Key.AddEnumValue(
                ExceptionHandlingSettingsManageabilityProvider.PolicyTypePostHandlingActionPropertyName, PostHandlingAction.None);
            MockRegistryKey userPolicy1Type12Key = new MockRegistryKey(false);
            userPolicy1TypesKey.AddSubKey("type12", userPolicy1Type12Key);
            userPolicy1Type12Key.AddBooleanValue(ExceptionHandlingSettingsManageabilityProvider.PolicyValueName, true);
            userPolicy1Type12Key.AddEnumValue(
                ExceptionHandlingSettingsManageabilityProvider.PolicyTypePostHandlingActionPropertyName, PostHandlingAction.None);
            MockRegistryKey userPolicy2Key = new MockRegistryKey(false);
            userPoliciesKey.AddSubKey("policy2", userPolicy2Key);
            MockRegistryKey userPolicy2TypesKey = new MockRegistryKey(false);
            userPolicy2Key.AddSubKey(ExceptionHandlingSettingsManageabilityProvider.PolicyTypesPropertyName, userPolicy2TypesKey);
            MockRegistryKey userPolicy2Type21Key = new MockRegistryKey(false);
            userPolicy2TypesKey.AddSubKey("type21", userPolicy2Type21Key);
            userPolicy2Type21Key.AddBooleanValue(ExceptionHandlingSettingsManageabilityProvider.PolicyValueName, false);
            userPolicy2Type21Key.AddEnumValue(
                ExceptionHandlingSettingsManageabilityProvider.PolicyTypePostHandlingActionPropertyName, PostHandlingAction.None);

            provider.OverrideWithGroupPolicies(section, true, machineKey, userKey);

            Assert.AreEqual(2, section.ExceptionPolicies.Count);
            Assert.IsNotNull(section.ExceptionPolicies.Get("policy1"));
            Assert.AreEqual(1, section.ExceptionPolicies.Get("policy1").ExceptionTypes.Count);
            Assert.IsNotNull(section.ExceptionPolicies.Get("policy1").ExceptionTypes.Get("type12"));
            Assert.IsNotNull(section.ExceptionPolicies.Get("policy2"));
            Assert.AreEqual(0, section.ExceptionPolicies.Get("policy2").ExceptionTypes.Count);

            Assert.IsTrue(MockRegistryKey.CheckAllClosed(userPoliciesKey,
                                                         userPolicy1Key, userPolicy1TypesKey, userPolicy1Type11Key,
                                                         userPolicy1Type12Key,
                                                         userPolicy2Key, userPolicy2TypesKey, userPolicy2Type21Key));
        }
        public void MachineKeySourceOverrideWithoutListenersSubKeyTakesPrecedenceOverUserKeyOverrides()
        {
            TraceSourceData sourceData = new TraceSourceData("source1", SourceLevels.Critical, true);
            section.TraceSources.Add(sourceData);
            sourceData.TraceListeners.Add(new TraceListenerReferenceData("listener1"));
            sourceData.TraceListeners.Add(new TraceListenerReferenceData("listener2"));

            MockRegistryKey machineTraceSourcesKey = new MockRegistryKey(false);
            machineKey.AddSubKey(LoggingSettingsManageabilityProvider.CategorySourcesKeyName, machineTraceSourcesKey);
            MockRegistryKey machineSource1Key = new MockRegistryKey(false);
            machineTraceSourcesKey.AddSubKey("source1", machineSource1Key);
            machineSource1Key.AddEnumValue<SourceLevels>(LoggingSettingsManageabilityProvider.SourceDefaultLevelPropertyName, SourceLevels.ActivityTracing);
            machineSource1Key.AddBooleanValue(LoggingSettingsManageabilityProvider.SourceAutoFlushPropertyName, false);
            MockRegistryKey userTraceSourcesKey = new MockRegistryKey(false);
            userKey.AddSubKey(LoggingSettingsManageabilityProvider.CategorySourcesKeyName, userTraceSourcesKey);
            MockRegistryKey userSource1Key = new MockRegistryKey(false);
            userTraceSourcesKey.AddSubKey("source1", userSource1Key);
            userSource1Key.AddEnumValue<SourceLevels>(LoggingSettingsManageabilityProvider.SourceDefaultLevelPropertyName, SourceLevels.ActivityTracing);
            userSource1Key.AddBooleanValue(LoggingSettingsManageabilityProvider.SourceAutoFlushPropertyName, false);
            MockRegistryKey userSource1ListenersKey = new MockRegistryKey(false);
            userSource1Key.AddSubKey(LoggingSettingsManageabilityProvider.SourceTraceListenersPropertyName, userSource1ListenersKey);
            userSource1ListenersKey.AddBooleanValue("listener6", true);
            userSource1ListenersKey.AddBooleanValue("listener7", true);
            userSource1ListenersKey.AddBooleanValue("listener8", true);

            provider.OverrideWithGroupPolicies(section, true, machineKey, userKey);

            Assert.AreEqual(0, sourceData.TraceListeners.Count);

            Assert.IsTrue(
                MockRegistryKey.CheckAllClosed(
                    machineTraceSourcesKey, machineSource1Key,
                    userTraceSourcesKey, userSource1Key, userSource1ListenersKey));
        }
        public void TraceSourceTraceListenersAreOverridenIfListenerKeyIsPresentInUserKey()
        {
            TraceSourceData sourceData = new TraceSourceData("source1", SourceLevels.Critical, true);
            section.TraceSources.Add(sourceData);
            sourceData.TraceListeners.Add(new TraceListenerReferenceData("listener1"));
            sourceData.TraceListeners.Add(new TraceListenerReferenceData("listener2"));

            MockRegistryKey userTraceSourcesKey = new MockRegistryKey(false);
            userKey.AddSubKey(LoggingSettingsManageabilityProvider.CategorySourcesKeyName, userTraceSourcesKey);
            MockRegistryKey userSource1Key = new MockRegistryKey(false);
            userTraceSourcesKey.AddSubKey("source1", userSource1Key);
            userSource1Key.AddEnumValue<SourceLevels>(LoggingSettingsManageabilityProvider.SourceDefaultLevelPropertyName, SourceLevels.ActivityTracing);
            userSource1Key.AddBooleanValue(LoggingSettingsManageabilityProvider.SourceAutoFlushPropertyName, false);
            MockRegistryKey userSource1ListenersKey = new MockRegistryKey(false);
            userSource1Key.AddSubKey(LoggingSettingsManageabilityProvider.SourceTraceListenersPropertyName, userSource1ListenersKey);
            userSource1ListenersKey.AddBooleanValue("listener3", true);
            userSource1ListenersKey.AddBooleanValue("listener4", true);
            userSource1ListenersKey.AddBooleanValue("listener5", true);

            provider.OverrideWithGroupPolicies(section, true, machineKey, userKey);

            Assert.AreEqual(3, sourceData.TraceListeners.Count);
            Assert.IsNotNull(sourceData.TraceListeners.Get("listener3"));
            Assert.IsNotNull(sourceData.TraceListeners.Get("listener4"));
            Assert.IsNotNull(sourceData.TraceListeners.Get("listener5"));

            Assert.IsTrue(MockRegistryKey.CheckAllClosed(userTraceSourcesKey, userSource1Key, userSource1ListenersKey));
        }