Ejemplo n.º 1
0
        public void AddIsReflectedInNextRequestWithoutRefresh()
        {
            string otherConfigurationFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config");

            try
            {
                File.Copy(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, otherConfigurationFile);

                using (FileConfigurationSource otherSource = new FileConfigurationSource(otherConfigurationFile, false))
                {
                    DummySection otherSection = otherSource.GetSection(localSection) as DummySection;

                    // update twice, just to make sure
                    DummySection newSection = new DummySection();
                    newSection.Value = 13;
                    otherSource.Add(localSection, newSection);

                    newSection       = new DummySection();
                    newSection.Value = 12;
                    otherSource.Add(localSection, newSection);

                    otherSection = otherSource.GetSection(localSection) as DummySection;
                    Assert.IsNotNull(otherSection);
                    Assert.AreEqual(12, otherSection.Value);
                }
            }
            finally
            {
                if (File.Exists(otherConfigurationFile))
                {
                    File.Delete(otherConfigurationFile);
                }
            }
        }
Ejemplo n.º 2
0
        public void RemoveIsReflectedInNextRequestWithoutRefresh()
        {
            string otherConfigurationFile        = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config");
            FileConfigurationParameter parameter = new FileConfigurationParameter(otherConfigurationFile);

            FileConfigurationSource.ResetImplementation(otherConfigurationFile, false);
            try
            {
                File.Copy(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, otherConfigurationFile);
                FileConfigurationSource otherSource = new FileConfigurationSource(otherConfigurationFile);

                DummySection otherSection = otherSource.GetSection(localSection) as DummySection;

                DummySection newSection = new DummySection();
                newSection.Value = 13;
                otherSource.Add(parameter, localSection, newSection);

                otherSource.Remove(parameter, localSection);

                otherSection = otherSource.GetSection(localSection) as DummySection;
                Assert.IsNull(otherSection);
            }
            finally
            {
                FileConfigurationSource.ResetImplementation(otherConfigurationFile, true);
                if (File.Exists(otherConfigurationFile))
                {
                    File.Delete(otherConfigurationFile);
                }
            }
        }
        public void RemoveIsReflectedInNextRequestWithoutRefresh()
        {
            string otherConfigurationFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config");

            try
            {
                File.Copy(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath, otherConfigurationFile);

                using (FileConfigurationSource otherSource = new FileConfigurationSource(otherConfigurationFile, false))
                {
                    DummySection otherSection = otherSource.GetSection(localSection) as DummySection;

                    DummySection newSection = new DummySection();
                    newSection.Value = 13;
                    otherSource.Add(localSection, newSection);

                    otherSource.Remove(localSection);

                    otherSection = otherSource.GetSection(localSection) as DummySection;
                    Assert.IsNull(otherSection);
                }
            }
            finally
            {
                if (File.Exists(otherConfigurationFile))
                {
                    File.Delete(otherConfigurationFile);
                }
            }
        }
        public void TryToSaveWithAFileConfigurationSaveParameter()
        {
            FileConfigurationSource source = new FileConfigurationSource(file, false);

            source.Add(TestConfigurationSection.SectionName, CreateTestSection());

            ValidateConfiguration(file);
        }
Ejemplo n.º 5
0
        public void SavingWithEmptyProtectionProviderThrowsArgumentException()
        {
            string configurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
            FileConfigurationSource fileConfigSource = new FileConfigurationSource(configurationFile, false);

            DummySection newSection = new DummySection();

            fileConfigSource.Add(localSection, newSection, string.Empty);
        }
        public void SavingWithEmptyProtectionProviderThrowsArgumentException()
        {
            string configurationFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath;
            FileConfigurationSource fileConfigSource = new FileConfigurationSource(configurationFile, false);

            DummySection newSection = new DummySection();

            fileConfigSource.Add(localSection, newSection, string.Empty);
        }
        public override void Save(IServiceProvider serviceProvider)
        {
            IErrorLogService         errorService            = ServiceHelper.GetErrorService(serviceProvider);
            IEnvironmentMergeService environmentMergeService = serviceProvider.GetService(typeof(IEnvironmentMergeService)) as IEnvironmentMergeService;

            if (environmentMergeService != null)
            {
                if (environmentMergeService.EnvironmentMergeInProgress)
                {
                    return;
                }
            }

            IConfigurationUIHierarchy hierarchy = ServiceHelper.GetCurrentHierarchy(serviceProvider);

            Debug.Assert(hierarchy != null);

            ConfigurationApplicationNode configurationRootNode = hierarchy.FindNodeByType(typeof(ConfigurationApplicationNode)) as ConfigurationApplicationNode;

            Debug.Assert(configurationRootNode != null);

            string configurationFileDirectory = Path.GetDirectoryName(configurationRootNode.ConfigurationFile);

            foreach (EnvironmentNode environmentNode in hierarchy.FindNodesByType(typeof(EnvironmentNode)))
            {
                string environmentDeltaFilePath =
                    Path.Combine(configurationFileDirectory, environmentNode.EnvironmentDeltaFile);

                Dictionary <string, ConfigurationNodeMergeData> mergeDataByPath =
                    environmentNode.EnvironmentMergeData.UnfoldMergeData(hierarchy, false);
                EnvironmentMergeSection environmentMergeSection = new EnvironmentMergeSection();
                environmentMergeSection.EnvironmentName      = environmentNode.Name;
                environmentMergeSection.EnvironmentDeltaFile = environmentNode.EnvironmentConfigurationFile;

                CopyEnvironmentOverrides(environmentMergeSection, mergeDataByPath, hierarchy);
                string protectionProvider = GetProtectionProviderName(environmentNode);

                try
                {
                    FileConfigurationSource fileConfigurationSource =
                        new FileConfigurationSource(environmentDeltaFilePath, false);
                    if (!string.IsNullOrEmpty(protectionProvider))
                    {
                        fileConfigurationSource.Save(EnvironmentMergeSection.EnvironmentMergeData, environmentMergeSection, protectionProvider);
                    }
                    else
                    {
                        fileConfigurationSource.Add(EnvironmentMergeSection.EnvironmentMergeData, environmentMergeSection);
                    }
                }
                catch (ConfigurationErrorsException configurationErrors)
                {
                    errorService.LogErrors(configurationErrors);
                }
            }
        }
Ejemplo n.º 8
0
        protected void ProtectSection(FileConfigurationSource source, string sectionName, string protectionProvider)
        {
            ConfigurationSectionCloner cloner = new ConfigurationSectionCloner();
            var section = source.GetSection(sectionName);

            section = cloner.Clone(section);

            source.Remove(sectionName);
            source.Add(sectionName, section, protectionProvider);
        }
        public void then_file_contains_no_clear_elements()
        {
            source.Remove(ExceptionHandlingSettings.SectionName);
            source.Add(ExceptionHandlingSettings.SectionName, clonedSection);

            string text = File.ReadAllText("temp.config");

            Assert.IsTrue(text.Contains(ExceptionHandlingSettings.SectionName));
            Assert.IsFalse(text.Contains("<clear/>"));
        }
Ejemplo n.º 10
0
        public void TryToSaveWithConfigurationMultipleTimes()
        {
            string tempFile = CreateFile();

            try
            {
                IConfigurationSource source = new FileConfigurationSource(tempFile);
                source.Add(new FileConfigurationParameter(tempFile), InstrumentationConfigurationSection.SectionName, CreateInstrumentationSection());
                ValidateConfiguration(tempFile);
                source.Add(new FileConfigurationParameter(tempFile), InstrumentationConfigurationSection.SectionName, CreateInstrumentationSection());
                ValidateConfiguration(tempFile);
                source.Add(new FileConfigurationParameter(tempFile), InstrumentationConfigurationSection.SectionName, CreateInstrumentationSection());
                ValidateConfiguration(tempFile);
            }
            finally
            {
                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }
            }
        }
Ejemplo n.º 11
0
        public void AddingUnprotectedSectionsWithProtectionProviderWillProtectThem()
        {
            DummySection dummySection = new DummySection();

            string configurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
            FileConfigurationSource fileConfigSource = new FileConfigurationSource(configurationFile, false);

            fileConfigSource.Add(protectedSection, dummySection, ProtectedConfiguration.DefaultProvider);

            ConfigurationSection section = fileConfigSource.GetSection(protectedSection);

            Assert.IsTrue(section.SectionInformation.IsProtected);
            Assert.IsNotNull(section.SectionInformation);
            Assert.AreEqual(ProtectedConfiguration.DefaultProvider, section.SectionInformation.ProtectionProvider.Name);
        }
        public void TryToSaveWithConfigurationMultipleTimes()
        {
            string tempFile = CreateFile();

            try
            {
                using (var source = new FileConfigurationSource(tempFile, false))
                {
                    source.Add(TestConfigurationSection.SectionName, CreateTestSection());
                    ValidateConfiguration(tempFile);
                    source.Add(TestConfigurationSection.SectionName, CreateTestSection());
                    ValidateConfiguration(tempFile);
                    source.Add(TestConfigurationSection.SectionName, CreateTestSection());
                    ValidateConfiguration(tempFile);
                }
            }
            finally
            {
                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }
            }
        }
        public void AddingUnprotectedSectionsWithProtectionProviderWillProtectThem()
        {
            DummySection dummySection = new DummySection();

            string configurationFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath;
            FileConfigurationSource fileConfigSource = new FileConfigurationSource(configurationFile, false);

            fileConfigSource.Add(protectedSection, dummySection, ProtectedConfiguration.DefaultProvider);

            ConfigurationSection section = fileConfigSource.GetSection(protectedSection);

            Assert.IsTrue(section.SectionInformation.IsProtected);
            Assert.IsNotNull(section.SectionInformation);
            Assert.AreEqual(ProtectedConfiguration.DefaultProvider, section.SectionInformation.ProtectionProvider.Name);
        }
        public void AddingUnprotectedSectionsWithProtectionProviderWillProtectThem()
        {
            DummySection dummySection = new DummySection();

            string configurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
            FileConfigurationSource fileConfigSource = new FileConfigurationSource(configurationFile, false);

            fileConfigSource.Add(protectedSection, dummySection, ProtectedConfiguration.DefaultProvider);

            ConfigurationSection section = fileConfigSource.GetSection(protectedSection);

            Assert.IsTrue(section.SectionInformation.IsProtected);
            Assert.IsNotNull(section.SectionInformation);
            Assert.AreEqual(ProtectedConfiguration.DefaultProvider, section.SectionInformation.ProtectionProvider.Name);
        }
        public void SavingWithEmptyProtectionProviderThrowsArgumentException()
        {
            string configurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
            FileConfigurationSource fileConfigSource = new FileConfigurationSource(configurationFile, false);

            DummySection newSection = new DummySection();

            fileConfigSource.Add(localSection, newSection, string.Empty);
        }
        public void RemoveIsReflectedInNextRequestWithoutRefresh()
        {
            string otherConfigurationFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config");
            
            try
            {
                File.Copy(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, otherConfigurationFile);

                using (FileConfigurationSource otherSource = new FileConfigurationSource(otherConfigurationFile, false))
                {
                    DummySection otherSection = otherSource.GetSection(localSection) as DummySection;

                    DummySection newSection = new DummySection();
                    newSection.Value = 13;
                    otherSource.Add(localSection, newSection);

                    otherSource.Remove(localSection);

                    otherSection = otherSource.GetSection(localSection) as DummySection;
                    Assert.IsNull(otherSection);
                }
            }
            finally
            {
                if (File.Exists(otherConfigurationFile))
                {
                    File.Delete(otherConfigurationFile);
                }
            }
        }