示例#1
0
 public void TestInvalidUnit()
 {
     using (var reader = new StringReader("invalid"))
         using (var parser = new Parser.Parser(reader, IniOptions.Default))
             using (var doc = new ParsedSectionCollection(parser, IniOptions.Default))
             {
                 Assert.Throws <InvalidUnitException>(() => doc.GetDefaultSection());
             }
 }
示例#2
0
 public void TestDontParseDefaultSection()
 {
     using (var reader = new StringReader($"[{Section.DefaultSectionName}]"))
         using (var parser = new Parser.Parser(reader, IniOptions.Default))
             using (var doc = new ParsedSectionCollection(parser, IniOptions.Default))
             {
                 Assert.Throws <InvalidTokenException>(() => doc.GetDefaultSection());
             }
 }
示例#3
0
 public void TestGetNonexistentSection()
 {
     using (var reader = new StringReader("[section]"))
         using (var parser = new Parser.Parser(reader, IniOptions.Default))
             using (var doc = new ParsedSectionCollection(parser, IniOptions.Default))
             {
                 Assert.Throws <ArgumentException>(() => doc.GetSection("nonexistent"));
             }
 }
示例#4
0
        public void GetSectionCaseInsensitiveParsing()
        {
            var options = new IniOptions(caseSensitive: false);

            using (var reader = new StringReader("[SECTION]"))
                using (var parser = new Parser.Parser(reader, options))
                    using (var doc = new ParsedSectionCollection(parser, options))
                    {
                        Assert.NotNull(doc.GetSection("section"));
                    }
        }
示例#5
0
        public void GetSectionCaseSensitiveParsing()
        {
            var options = new IniOptions(caseSensitive: true);

            using (var reader = new StringReader("[SECTION]"))
                using (var parser = new Parser.Parser(reader, options))
                    using (var doc = new ParsedSectionCollection(parser, options))
                    {
                        Assert.Throws <ArgumentException>(() => doc.GetSection("section"));
                    }
        }
示例#6
0
 public void TestGetSection()
 {
     using (var reader = new StringReader("[section1]\n[section2]\n[section3]"))
         using (var parser = new Parser.Parser(reader, IniOptions.Default))
             using (var doc = new ParsedSectionCollection(parser, IniOptions.Default))
             {
                 for (var i = 0; i < 3; i++)
                 {
                     var name    = $"section{i + 1}";
                     var section = doc.GetSection(name);
                     Assert.AreEqual(name, section.Name);
                 }
             }
 }
示例#7
0
 public void TestGetSectionsWithProperties()
 {
     using (var reader = new StringReader("[section1]\nvalue=10\n[section2]\nvalue=10\n[section3]\nvalue=10"))
         using (var parser = new Parser.Parser(reader, IniOptions.Default))
             using (var doc = new ParsedSectionCollection(parser, IniOptions.Default))
             {
                 for (var i = 0; i < 3; i++)
                 {
                     var name    = $"section{i + 1}";
                     var section = doc.GetSection(name);
                     Assert.AreEqual(name, section.Name);
                     Assert.AreEqual(1, section.GetProperties().Count());
                     Assert.AreEqual(true, section.HasProperty("value"));
                     Assert.AreEqual(10L, section.GetProperty("value").GetValueAs <long>());
                 }
             }
 }
示例#8
0
 /// <summary>
 /// Creates a new configuration file reader
 /// </summary>
 /// <param name="filename">Path to a configuration file</param>
 /// <param name="options">Options to use when reading</param>
 public IniReader(string filename, IniOptions options)
 {
     sections = new ParsedSectionCollection(Parser.Parser.FromFile(filename, options), options);
 }