Ejemplo n.º 1
0
        private void RunCreationTest(IsoStorageConfigurationSource source)
        {
            string sourceFile = string.Empty;

            try
            {
                source.Add(SectionGenerator.GetSingleSection());
                source.Save();
                sourceFile = source.FullPath;
                // we should now have a file on the hdd with the settings we want.
                string sourceAsXml = XmlConfigurationSource.ToXml(source);

                // Now create a new instance so it can load the data.
                var    newSource      = new IsoStorageConfigurationSource(source.Scope, _fileName);
                string newSourceAsXml = XmlConfigurationSource.ToXml(newSource);
                Assert.Equal(sourceAsXml, newSourceAsXml);
            }
            finally
            {
                if (File.Exists(sourceFile))
                {
                    File.Delete(sourceFile);
                }
            }
        }
        public void CanParseMultipleSections()
        {
            string xml = XmlConfigurationSource.ToXml(SectionGenerator.GetThreeSections());

            var source = new XmlConfigurationSource(xml);

            Assert.Equal(3, source.Sections.Count);
            Assert.NotNull(source.Sections["Default"]);
            Assert.NotNull(source.Sections["Default2"]);
            Assert.NotNull(source.Sections["Default3"]);

            int count = 0;

            foreach (IConfigurationSection configurationSection in source)
            {
                foreach (KeyValuePair <string, string> pair in configurationSection)
                {
                    Assert.Equal(pair.Value,
                                 source.Sections[configurationSection.Name].Get <string>(pair.Key));
                    count++;
                }

                foreach (KeyValuePair <string, string> pair in source.Sections[configurationSection.Name])
                {
                    Assert.Equal(pair.Value, configurationSection.Get <string>(pair.Key));
                    count++;
                }
            }
            Assert.Equal(10, count);
        }
        public void CanParseSingleSection()
        {
            IConfigurationSection section = SectionGenerator.GetSingleSection();

            string xml = XmlConfigurationSource.ToXml(new[] { section });

            var source = new XmlConfigurationSource(xml);

            Assert.Equal(1, source.Sections.Count);
            Assert.NotNull(source.Sections["Default"]);
            int count = 0;

            foreach (IConfigurationSection configurationSection in source)
            {
                foreach (KeyValuePair <string, string> pair in configurationSection)
                {
                    Assert.Equal(pair.Value, section.Get <string>(pair.Key));
                    count++;
                }

                foreach (KeyValuePair <string, string> pair in section)
                {
                    Assert.Equal(pair.Value, configurationSection.Get <string>(pair.Key));
                    count++;
                }
            }
            Assert.Equal(10, count);
        }
        public void CanLoadFromFile()
        {
            string xml = XmlConfigurationSource.ToXml(SectionGenerator.GetThreeSections());

            var source = new XmlConfigurationSource(xml)
            {
                FileName = "CanLoadFromFile.xml"
            };

            source.Save();

            var    sourceFromFile       = XmlConfigurationSource.FromFile("CanLoadFromFile.xml");
            string sourceString         = source.ToString();
            string sourceFromFileString = sourceFromFile.ToString();

            Assert.Equal(sourceString, sourceFromFileString);
        }