public void CanDeserializeSerializedConfiguration()
        {
            string sourceName1 = "source1";
            string sourceName2 = "source2";
            string sourceFile1 = "file 1";
            ConfigurationSourceSection settings = new ConfigurationSourceSection();

            FileConfigurationSource.ResetImplementation(sourceFile1, false);
            ConfigurationSourceElement data1 = new FileConfigurationSourceElement(sourceName1, sourceFile1);
            ConfigurationSourceElement data2 = new SystemConfigurationSourceElement(sourceName2);

            settings.Sources.Add(data1);
            settings.Sources.Add(data2);
            settings.SelectedSource = sourceName1;
            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>();

            sections[ConfigurationSourceSection.SectionName] = settings;
            IConfigurationSource configurationSource
                = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);
            ConfigurationSourceSection roSettigs = (ConfigurationSourceSection)configurationSource.GetSection(ConfigurationSourceSection.SectionName);

            Assert.IsNotNull(roSettigs);
            Assert.AreEqual(2, roSettigs.Sources.Count);
            Assert.AreEqual(sourceName1, roSettigs.SelectedSource);
            Assert.IsNotNull(roSettigs.Sources.Get(sourceName1));
            Assert.AreSame(typeof(FileConfigurationSourceElement), roSettigs.Sources.Get(sourceName1).GetType());
            Assert.AreEqual(sourceFile1, ((FileConfigurationSourceElement)roSettigs.Sources.Get(sourceName1)).FilePath);
            Assert.IsNotNull(roSettigs.Sources.Get(sourceName2));
            Assert.AreSame(typeof(SystemConfigurationSourceElement), roSettigs.Sources.Get(sourceName2).GetType());
        }
        public void CanDeserializeSerializedConfiguration()
        {
            string sourceName1 = "source1";
            string sourceName2 = "source2";

            string sourceFile1 = "file 1";

            ConfigurationSourceSection settings = new ConfigurationSourceSection();

            ConfigurationSourceElement data1 = new FileConfigurationSourceElement(sourceName1, sourceFile1);
            ConfigurationSourceElement data2 = new SystemConfigurationSourceElement(sourceName2);

            settings.Sources.Add(data1);
            settings.Sources.Add(data2);
            settings.SelectedSource = sourceName1;

            IDictionary<string, ConfigurationSection> sections = new Dictionary<string, ConfigurationSection>();
            sections[ConfigurationSourceSection.SectionName] = settings;
            using (var configurationSource = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections))
            {
                ConfigurationSourceSection roSettigs =
                    (ConfigurationSourceSection)configurationSource.GetSection(ConfigurationSourceSection.SectionName);

                Assert.IsNotNull(roSettigs);
                Assert.AreEqual(2, roSettigs.Sources.Count);
                Assert.AreEqual(sourceName1, roSettigs.SelectedSource);

                Assert.IsNotNull(roSettigs.Sources.Get(sourceName1));
                Assert.AreSame(typeof(FileConfigurationSourceElement), roSettigs.Sources.Get(sourceName1).GetType());
                Assert.AreEqual(sourceFile1, ((FileConfigurationSourceElement)roSettigs.Sources.Get(sourceName1)).FilePath);

                Assert.IsNotNull(roSettigs.Sources.Get(sourceName2));
                Assert.AreSame(typeof(SystemConfigurationSourceElement), roSettigs.Sources.Get(sourceName2).GetType());
            }
        }
Exemple #3
0
 /// <summary>
 /// Initialize a new instance of the <see cref="SystemConfigurationSourceElement"/> class with a <see cref="SystemConfigurationSourceElement"/>.
 /// </summary>
 /// <param name="element">The <see cref="SystemConfigurationSourceElement"/> to initialize.</param>
 public SystemConfigurationSourceElementNode(SystemConfigurationSourceElement element) : base(null == element ? string.Empty : element.Name)
 {
 }