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); }
public void MergeAndSaveConfiguration(string configurationFile) { IConfigurationUIHierarchy mainConfigurationHierarchy = LoadMainConfiguration(mainConfigurationFile, serviceContainer); EnvironmentNode environmentNode = LoadConfigurationMergeFile(mainConfigurationHierarchy, configurationMergeFile, serviceContainer); if (!String.IsNullOrEmpty(configurationFile)) { environmentNode.EnvironmentConfigurationFile = configurationFile; } SaveMergedEnvironmentCommand saveMergedConfigurationComand = new SaveMergedEnvironmentCommand(serviceContainer); saveMergedConfigurationComand.Execute(environmentNode); mergeSucceeded = saveMergedConfigurationComand.MergeSucceeded; mergedConfigurationFile = saveMergedConfigurationComand.MergedConfigurationFile; }
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); }