public void LoadReader() { StringWriter textWriter = new StringWriter(); XmlTextWriter writer = NiniWriter(textWriter); WriteSection(writer, "Pets"); WriteKey(writer, "cat", "muffy"); WriteKey(writer, "dog", "rover"); WriteKey(writer, "bird", "tweety"); writer.WriteEndDocument(); StringReader reader = new StringReader(textWriter.ToString()); XmlTextReader xmlReader = new XmlTextReader(reader); XmlConfigSource source = new XmlConfigSource(xmlReader); IConfig config = source.Configs["Pets"]; Assert.AreEqual(3, config.GetKeys().Length); Assert.AreEqual("rover", config.Get("dog")); config.Set("dog", "new name"); config.Remove("bird"); reader = new StringReader(textWriter.ToString()); xmlReader = new XmlTextReader(reader); source.Load(xmlReader); config = source.Configs["Pets"]; Assert.AreEqual(3, config.GetKeys().Length); Assert.AreEqual("rover", config.Get("dog")); }
public void NotKnownTypesTest() { XmlDocument doc = new XmlDocument(); doc.LoadXml(SAMPLE_XML); string complexXml = @"<NotKnownTypeSample><Basic>%s</Basic><Basics>%s%s%s</Basics></NotKnownTypeSample>" .Replace("%s", doc.DocumentElement.OuterXml) .Replace("%z", doc.DocumentElement.InnerXml); var src = new XmlConfigSource<NotKnownTypeSample>(); var cfg = src.Load(complexXml).Get(); var src2 = new XmlConfigSource<BasicTypesSampleWithoutAttr>(); TestCreatedSimpleSample(src2.Load(cfg.Basic).Get()); cfg.Basics.Length.Should().Be(3); foreach (var simple in cfg.Basics) { TestCreatedSimpleSample(src2.Load(cfg.Basic).Get()); } }
public void UsingTransformationEarlyInsert() { string mySample = @"<BasicTypesSampleWithoutAttr> <AString>whatever</AString> </BasicTypesSampleWithoutAttr>"; ; var src = new XmlConfigSource<BasicTypesSampleWithoutAttr>(); src.AddTransform(x => x.AString = "42"); src.Get().Should().Be.Null(); src.Load(mySample); src.Get().Should().Not.Be.Null(); src.Get().AString.Should().Be("42"); }
public void MissingAStringTest() { string brokenXml = @"<BasicTypesSampleWithoutAttr> <AnIntegral>42</AnIntegral> <AFloat>42.42</AFloat> </BasicTypesSampleWithoutAttr>"; var src = new XmlConfigSource<BasicTypesSampleWithoutAttr>(); var cfg = src.Load(brokenXml).Get(); cfg.AString.Should().Be.Null(); }
public void MoreInformationThanCanHandle() { string mySample = @"<BasicTypesSampleWithoutAttr> <AString>whatever</AString> <NotKnown>asd</NotKnown> </BasicTypesSampleWithoutAttr>"; ; IXPathConfigSource<BasicTypesSampleWithoutAttr, string> src = new XmlConfigSource<BasicTypesSampleWithoutAttr>(); src.Load(mySample).Get().AString.Should().Be("whatever"); }
public void BasicXmlReaderTestBase(string xml, string xpath) { StringReader reader = new StringReader(xml); XmlTextReader reader2 = new XmlTextReader(reader); IXPathConfigSource<BasicTypesSampleWithoutAttr, XmlReader> src = new XmlConfigSource<BasicTypesSampleWithoutAttr>(); TestCreatedSimpleSample(src.Load(new XPathParameter<XmlReader>(reader2, xpath)).Get()); }
public void BasicXmlElementTestBase(string xml, string xpath) { XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); IXPathConfigSource<BasicTypesSampleWithoutAttr, XmlElement> src = new XmlConfigSource<BasicTypesSampleWithoutAttr>(); TestCreatedSimpleSample(src.Load(new XPathParameter<XmlElement>( doc.DocumentElement, xpath)).Get()); }
public void BasicXmlContentHolderTestBase(string xml, string xpath) { IXPathConfigSource<XmlContainerSample, string> src = new XmlConfigSource<XmlContainerSample>(); XmlContainerSample samp = src.Load(new XPathParameter<string>(xml, xpath)).Get(); IXPathConfigSource<BasicTypesSampleWithoutAttr, XmlElement> src2 = new XmlConfigSource<BasicTypesSampleWithoutAttr>(); TestCreatedSimpleSample(src2.Load(samp.Element).Get()); }
public void BasicStringTestBase(string xml, string xpath) { IXPathConfigSource<BasicTypesSampleWithoutAttr, string> src = new XmlConfigSource<BasicTypesSampleWithoutAttr>(); TestCreatedSimpleSample(src.Load(new XPathParameter<string>(xml, xpath)).Get()); }
public void BasicStreamTestBase(string xml, string xpath) { using (MemoryStream mem = new MemoryStream(Encoding.UTF8.GetBytes(xml))) { IXPathConfigSource<BasicTypesSampleWithoutAttr, Stream> src = new XmlConfigSource<BasicTypesSampleWithoutAttr>(); TestCreatedSimpleSample(src.Load(new XPathParameter<Stream>(mem, xpath)).Get()); } }