public void SavesMergedConfiguration() { File.SetAttributes(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, FileAttributes.Normal); ApplicationNode.Hierarchy.Load(); Assert.AreEqual(0, ServiceHelper.GetErrorService(ServiceProvider).ConfigurationErrorCount); ApplicationNode.Hierarchy.Open(); Assert.AreEqual(0, ServiceHelper.GetErrorService(ServiceProvider).ConfigurationErrorCount); InstrumentationNode instrumentationNode = (InstrumentationNode)ApplicationNode.Hierarchy.FindNodeByType(typeof(InstrumentationNode)); // test the settings from the original configuration file Assert.IsNotNull(instrumentationNode); Assert.IsTrue(instrumentationNode.EventLoggingEnabled); Assert.IsFalse(instrumentationNode.PerformanceCountersEnabled); Assert.IsTrue(instrumentationNode.WmiEnabled); // load the environment override ConfigurationNode overridesNode = ApplicationNode.Hierarchy.FindNodeByType(typeof(EnvironmentalOverridesNode)); Assert.IsNotNull(overridesNode); EnvironmentNode overrideNode = new EnvironmentNodeBuilder(ServiceProvider).Build("Environment.dconfig", overridesNode.Hierarchy); overridesNode.AddNode(overrideNode); // run the save merged environment command SaveMergedEnvironmentCommand command = new SaveMergedEnvironmentCommand(ServiceProvider); command.Execute(overrideNode); Assert.IsTrue(command.MergeSucceeded); // load the resulting configuration ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = Path.Combine( Path.GetDirectoryName(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile), overrideNode.EnvironmentConfigurationFile); System.Configuration.Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); // get the instrumentation node InstrumentationConfigurationSection instrumentationSection = (InstrumentationConfigurationSection)configuration.GetSection(InstrumentationConfigurationSection.SectionName); // test the settings from the merged configuration file Assert.IsNotNull(instrumentationSection); Assert.IsFalse(instrumentationSection.EventLoggingEnabled); Assert.IsTrue(instrumentationSection.PerformanceCountersEnabled); Assert.IsTrue(instrumentationSection.WmiEnabled); }
private EnvironmentNode LoadConfigurationMergeFile(IConfigurationUIHierarchy mainConfigurationHierarchy, string configurationMergeFile, IServiceProvider serviceProvider) { EnvironmentNodeBuilder nodeBuilder = new EnvironmentNodeBuilder(serviceProvider); EnvironmentNode environmentNode = nodeBuilder.Build(configurationMergeFile, mainConfigurationHierarchy); EnvironmentalOverridesNode environmentNodeContainer = mainConfigurationHierarchy.FindNodeByType(typeof(EnvironmentalOverridesNode)) as EnvironmentalOverridesNode; if (environmentNodeContainer == null) { throw new ApplicationException(Resources.ErrorNoEnvironmentContainer); } environmentNodeContainer.AddNode(environmentNode); return(environmentNode); }
public void MergingOverridesRemovesTheConfigurationSourcesSection() { ApplicationNode.Hierarchy.Load(); Assert.AreEqual(0, ServiceHelper.GetErrorService(ServiceProvider).ConfigurationErrorCount); ApplicationNode.Hierarchy.Open(); Assert.AreEqual(0, ServiceHelper.GetErrorService(ServiceProvider).ConfigurationErrorCount); ConfigurationNode configurationSourceSectionNode = ApplicationNode.Hierarchy.FindNodeByType(typeof(ConfigurationSourceSectionNode)); Assert.IsNotNull(configurationSourceSectionNode); // load the environment override ConfigurationNode overridesNode = ApplicationNode.Hierarchy.FindNodeByType(typeof(EnvironmentalOverridesNode)); Assert.IsNotNull(overridesNode); EnvironmentNode overrideNode = new EnvironmentNodeBuilder(ServiceProvider).Build("Environment.dconfig", overridesNode.Hierarchy); overridesNode.AddNode(overrideNode); // run the save merged environment command SaveMergedEnvironmentCommand command = new SaveMergedEnvironmentCommand(ServiceProvider); command.Execute(overrideNode); Assert.IsTrue(command.MergeSucceeded); // load the resulting configuration ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = Path.Combine( Path.GetDirectoryName(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile), overrideNode.EnvironmentConfigurationFile); System.Configuration.Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); // get the instrumentation node ConfigurationSection configurationSourceSection = configuration.GetSection(ConfigurationSourceSection.SectionName); Assert.IsNull(configurationSourceSection); }