예제 #1
0
        public void ReplaceText()
        {
            StringWriter  textWriter = new StringWriter();
            XmlTextWriter xmlWriter  = NiniWriter(textWriter);

            WriteSection(xmlWriter, "Test");
            WriteKey(xmlWriter, "author", "Brent");
            WriteKey(xmlWriter, "domain", "${protocol}://nini.sf.net/");
            WriteKey(xmlWriter, "apache", "Apache implements ${protocol}");
            WriteKey(xmlWriter, "developer", "author of Nini: ${author} !");
            WriteKey(xmlWriter, "love", "We love the ${protocol} protocol");
            WriteKey(xmlWriter, "combination", "${author} likes ${protocol}");
            WriteKey(xmlWriter, "fact", "fact: ${apache}");
            WriteKey(xmlWriter, "protocol", "http");
            xmlWriter.WriteEndDocument();

            StringReader    reader    = new StringReader(textWriter.ToString());
            XmlTextReader   xmlReader = new XmlTextReader(reader);
            XmlConfigSource source    = new XmlConfigSource(xmlReader);

            source.ReplaceKeyValues();

            IConfig config = source.Configs["Test"];

            Assert.AreEqual("http", config.Get("protocol"));
            Assert.AreEqual("fact: Apache implements http", config.Get("fact"));
            Assert.AreEqual("http://nini.sf.net/", config.Get("domain"));
            Assert.AreEqual("Apache implements http", config.Get("apache"));
            Assert.AreEqual("We love the http protocol", config.Get("love"));
            Assert.AreEqual("author of Nini: Brent !", config.Get("developer"));
            Assert.AreEqual("Brent likes http", config.Get("combination"));
        }