示例#1
0
        public void DisallowsDuplicateProperties()
        {
            var sentence = SectionFactory.CreateSection("foo", Grammar.DefaultDelimiters);
            var section  = new IniSection(sentence, new IniFile(sentence, new IniSettings
            {
                DuplicatePropertyHandling = DuplicatePropertyHandling.Disallow
            }));

            section.AddProperty("bar", "baz");
            section.AddProperty("bar", "qux");
        }
示例#2
0
        public void DisallowsDuplicateProperties()
        {
            var sentence = SectionFactory.CreateSection("foo", Grammar.DefaultDelimiters);
            var section = new IniSection(sentence, new IniFile(sentence, new IniSettings
            {
                DuplicatePropertyHandling = DuplicatePropertyHandling.Disallow
            }));

            section.AddProperty("bar", "baz");
            section.AddProperty("bar", "qux");
        }
示例#3
0
        public void KeepsLastDuplicateProperty()
        {
            var sentence = SectionFactory.CreateSection("foo", Grammar.DefaultDelimiters);
            var section  = new IniSection(sentence, new IniFile(sentence, new IniSettings
            {
                DuplicatePropertyHandling = DuplicatePropertyHandling.KeepLast
            }));

            section.AddProperty("bar", "baz");
            section.AddProperty("bar", "qux");

            Assert.IsTrue(section.Properties.Count() == 1);
            Assert.AreEqual("qux", section["bar"].Value);
        }
示例#4
0
        public void AllowsDuplicateProperties()
        {
            var sentence = SectionFactory.CreateSection("foo", Grammar.DefaultDelimiters);
            var section  = new IniSection(sentence, new IniFile(sentence, new IniSettings
            {
                DuplicatePropertyHandling = DuplicatePropertyHandling.Allow
            }));

            section.AddProperty("bar", "baz");
            section.AddProperty("bar", "qux");

            Assert.IsTrue(section.Properties.Count() == 2);
            Assert.IsTrue(section.Properties.Count(x => x.Name.Equals("bar", StringComparison.OrdinalIgnoreCase)) == 2);
        }
示例#5
0
        public void KeepsFirstDuplicateProperty()
        {
            var sentence = SectionFactory.CreateSection("foo", Grammar.DefaultDelimiters);
            var section = new IniSection(sentence, new IniFile(sentence, new IniSettings
            {
                DuplicatePropertyHandling = DuplicatePropertyHandling.KeepFirst
            }));

            section.AddProperty("bar", "baz");
            section.AddProperty("bar", "qux");

            Assert.IsTrue(section.Properties.Count() == 1);
            Assert.AreEqual("baz", section["bar"].Value);
        }
示例#6
0
        public void AllowsDuplicateProperties()
        {
            var sentence = SectionFactory.CreateSection("foo", Grammar.DefaultDelimiters);
            var section = new IniSection(sentence, new IniFile(sentence, new IniSettings
            {
                DuplicatePropertyHandling = DuplicatePropertyHandling.Allow
            }));

            section.AddProperty("bar", "baz");
            section.AddProperty("bar", "qux");

            Assert.IsTrue(section.Properties.Count() == 2);
            Assert.IsTrue(section.Properties.Count(x => x.Name.Equals("bar", StringComparison.OrdinalIgnoreCase)) == 2);
        }
示例#7
0
        public void IniFile_Section_Modify_03()
        {
            var section = new IniSection("Test");

            section.AddProperty("PN", "PV");
            Assert.AreEqual(1, section.Properties.Count);
            Assert.AreEqual("PN", section.Properties[0].Name);
            Assert.AreEqual("PV", section.Properties[0].Value);
        }
        public void WriteToFile()
        {
            IniConfig  config  = new IniConfig();
            IniSection section = config.AddSection("TestSection");

            section.Comments.AddRange(new string[]
            {
                "Test1", "Comment2"
            });

            IniProperty property = section.AddProperty("name", "Test", new string[] { "Property1", "TestProperty" }, new string[] { "Test1", "Test2" });

            string content = IniWriter.WriteToString(config);

            File.WriteAllText(@"D:\ini-config.txt", content);
        }