Example #1
0
        private List <ConfigSection> GetConfigSections()
        {
            string configFile = GetConfigFile();

            return(!File.Exists(configFile)
                                ? null
                                : new List <ConfigSection>(ConfigFileHelper.GetConfigSections(File.ReadAllText(configFile))));
        }
Example #2
0
        public void LayerExtensions_ShouldHandleMultipleSections()
        {
            var config   = @"
			[s0]
			p1=v1
			# This is a comment...
			paa=paa

			[s1]
			p2=v2
			p3=v3
			[s2]
			p4=v4
			p5=v5
			"            ;
            var sections = new List <ConfigSection>(ConfigFileHelper.GetConfigSections(config));

            Assert.AreEqual(3, sections.Count);
            Assert.AreEqual("s0", sections[0].Name);
            Assert.AreEqual("s1", sections[1].Name);
            Assert.AreEqual("s2", sections[2].Name);
            var p0 = sections[0].Properties;
            var p1 = sections[1].Properties;
            var p2 = sections[2].Properties;

            Assert.IsFalse(p1.ContainsKey("p1"), "s1 should not contain p1");
            Assert.IsTrue(p1.ContainsKey("p2"), "s1 should contain p2");
            Assert.IsTrue(p1.ContainsKey("p3"), "s1 should contain p3");
            Assert.IsFalse(p1.ContainsKey("p4"), "s1 should not contain p4");
            Assert.IsFalse(p1.ContainsKey("p5"), "s1 should not contain p5");
            Assert.AreEqual("paa", p0["paa"]);
            Assert.AreEqual("v1", p0["p1"], "p1");
            Assert.AreEqual("v2", p1["p2"], "p2");
            Assert.AreEqual("v3", p1["p3"], "p3");
            Assert.AreEqual("v4", p2["p4"], "p4");
            Assert.AreEqual("v5", p2["p5"], "p5");
        }