public void Merge() { StringWriter textWriter = new StringWriter(); XmlTextWriter xmlWriter = NiniWriter(textWriter); WriteSection(xmlWriter, "Pets"); WriteKey(xmlWriter, "cat", "muffy"); WriteKey(xmlWriter, "dog", "rover"); WriteKey(xmlWriter, "bird", "tweety"); xmlWriter.WriteEndDocument(); StringReader reader = new StringReader(textWriter.ToString()); XmlTextReader xmlReader = new XmlTextReader(reader); XmlConfigSource xmlSource = new XmlConfigSource(xmlReader); StringWriter writer = new StringWriter(); writer.WriteLine("[People]"); writer.WriteLine(" woman = Jane"); writer.WriteLine(" man = John"); IniConfigSource iniSource = new IniConfigSource(new StringReader(writer.ToString())); xmlSource.Merge(iniSource); IConfig config = xmlSource.Configs["Pets"]; Assert.AreEqual(3, config.GetKeys().Length); Assert.AreEqual("muffy", config.Get("cat")); Assert.AreEqual("rover", config.Get("dog")); config = xmlSource.Configs["People"]; Assert.AreEqual(2, config.GetKeys().Length); Assert.AreEqual("Jane", config.Get("woman")); Assert.AreEqual("John", config.Get("man")); }
public void MergeExisting() { StringWriter textWriter = new StringWriter(); XmlTextWriter xmlWriter = NiniWriter(textWriter); WriteSection(xmlWriter, "Pets"); WriteKey(xmlWriter, "cat", "muffy"); xmlWriter.WriteEndDocument(); StringReader reader = new StringReader(xmlWriter.ToString()); XmlTextReader xmlReader = new XmlTextReader(reader); XmlConfigSource xmlSource = new XmlConfigSource(xmlReader); StringWriter writer = new StringWriter(); writer.WriteLine("[People]"); writer.WriteLine(" woman = Jane"); IniConfigSource iniSource = new IniConfigSource(new StringReader(writer.ToString())); xmlSource.Merge(iniSource); xmlSource.Merge(iniSource); // exception }
public void Merge() { StringWriter textWriter = new StringWriter(); XmlTextWriter xmlWriter = NiniWriter(textWriter); WriteSection(xmlWriter, "Pets"); WriteKey(xmlWriter, "cat", "muffy"); WriteKey(xmlWriter, "dog", "rover"); WriteKey(xmlWriter, "bird", "tweety"); xmlWriter.WriteEndDocument(); StringReader reader = new StringReader(textWriter.ToString()); XmlTextReader xmlReader = new XmlTextReader(reader); XmlConfigSource xmlSource = new XmlConfigSource(xmlReader); StringWriter writer = new StringWriter(); writer.WriteLine("[People]"); writer.WriteLine(" woman = Jane"); writer.WriteLine(" man = John"); IniConfigSource iniSource = new IniConfigSource(new StringReader(writer.ToString())); xmlSource.Merge(iniSource); IConfig config = xmlSource.Configs["Pets"]; Assert.AreEqual(3, config.GetKeys().Length); Assert.AreEqual("muffy", config.Get("cat")); Assert.AreEqual("rover", config.Get("dog")); config = xmlSource.Configs["People"]; Assert.AreEqual(2, config.GetKeys().Length); Assert.AreEqual("Jane", config.Get("woman")); Assert.AreEqual("John", config.Get("man")); }
public void MergeAndSave() { string xmlFileName = "NiniConfig.xml"; StreamWriter textWriter = new StreamWriter(xmlFileName); XmlTextWriter xmlWriter = NiniWriter(textWriter); WriteSection(xmlWriter, "Pets"); WriteKey(xmlWriter, "cat", "Muffy"); WriteKey(xmlWriter, "dog", "Rover"); WriteKey(xmlWriter, "bird", "Tweety"); xmlWriter.WriteEndDocument(); xmlWriter.Close(); StringWriter writer = new StringWriter(); writer.WriteLine("[Pets]"); writer.WriteLine("cat = Becky"); // overwrite writer.WriteLine("lizard = Saurus"); // new writer.WriteLine("[People]"); writer.WriteLine(" woman = Jane"); writer.WriteLine(" man = John"); IniConfigSource iniSource = new IniConfigSource (new StringReader(writer.ToString())); XmlConfigSource xmlSource = new XmlConfigSource(xmlFileName); xmlSource.Merge(iniSource); IConfig config = xmlSource.Configs["Pets"]; Assert.AreEqual(4, config.GetKeys().Length); Assert.AreEqual("Becky", config.Get("cat")); Assert.AreEqual("Rover", config.Get("dog")); Assert.AreEqual("Saurus", config.Get("lizard")); config = xmlSource.Configs["People"]; Assert.AreEqual(2, config.GetKeys().Length); Assert.AreEqual("Jane", config.Get("woman")); Assert.AreEqual("John", config.Get("man")); config.Set("woman", "Tara"); config.Set("man", "Quentin"); xmlSource.Save(); xmlSource = new XmlConfigSource(xmlFileName); config = xmlSource.Configs["Pets"]; Assert.AreEqual(4, config.GetKeys().Length); Assert.AreEqual("Becky", config.Get("cat")); Assert.AreEqual("Rover", config.Get("dog")); Assert.AreEqual("Saurus", config.Get("lizard")); config = xmlSource.Configs["People"]; Assert.AreEqual(2, config.GetKeys().Length); Assert.AreEqual("Tara", config.Get("woman")); Assert.AreEqual("Quentin", config.Get("man")); File.Delete(xmlFileName); }
public void MergeExisting() { StringWriter textWriter = new StringWriter(); XmlTextWriter xmlWriter = NiniWriter(textWriter); WriteSection(xmlWriter, "Pets"); WriteKey(xmlWriter, "cat", "muffy"); xmlWriter.WriteEndDocument(); StringReader reader = new StringReader(xmlWriter.ToString()); XmlTextReader xmlReader = new XmlTextReader(reader); XmlConfigSource xmlSource = new XmlConfigSource(xmlReader); StringWriter writer = new StringWriter(); writer.WriteLine("[People]"); writer.WriteLine(" woman = Jane"); IniConfigSource iniSource = new IniConfigSource(new StringReader(writer.ToString())); xmlSource.Merge(iniSource); xmlSource.Merge(iniSource); // exception }
public void MergeAndSave() { string xmlFileName = "NiniConfig.xml"; StreamWriter textWriter = new StreamWriter(xmlFileName); XmlTextWriter xmlWriter = NiniWriter(textWriter); WriteSection(xmlWriter, "Pets"); WriteKey(xmlWriter, "cat", "Muffy"); WriteKey(xmlWriter, "dog", "Rover"); WriteKey(xmlWriter, "bird", "Tweety"); xmlWriter.WriteEndDocument(); xmlWriter.Close(); StringWriter writer = new StringWriter(); writer.WriteLine("[Pets]"); writer.WriteLine("cat = Becky"); // overwrite writer.WriteLine("lizard = Saurus"); // new writer.WriteLine("[People]"); writer.WriteLine(" woman = Jane"); writer.WriteLine(" man = John"); IniConfigSource iniSource = new IniConfigSource (new StringReader(writer.ToString())); XmlConfigSource xmlSource = new XmlConfigSource(xmlFileName); xmlSource.Merge(iniSource); IConfig config = xmlSource.Configs["Pets"]; Assert.AreEqual(4, config.GetKeys().Length); Assert.AreEqual("Becky", config.Get("cat")); Assert.AreEqual("Rover", config.Get("dog")); Assert.AreEqual("Saurus", config.Get("lizard")); config = xmlSource.Configs["People"]; Assert.AreEqual(2, config.GetKeys().Length); Assert.AreEqual("Jane", config.Get("woman")); Assert.AreEqual("John", config.Get("man")); config.Set("woman", "Tara"); config.Set("man", "Quentin"); xmlSource.Save(); xmlSource = new XmlConfigSource(xmlFileName); config = xmlSource.Configs["Pets"]; Assert.AreEqual(4, config.GetKeys().Length); Assert.AreEqual("Becky", config.Get("cat")); Assert.AreEqual("Rover", config.Get("dog")); Assert.AreEqual("Saurus", config.Get("lizard")); config = xmlSource.Configs["People"]; Assert.AreEqual(2, config.GetKeys().Length); Assert.AreEqual("Tara", config.Get("woman")); Assert.AreEqual("Quentin", config.Get("man")); File.Delete(xmlFileName); }