public void MandatoryMultipleOptionalZero() { const string xml = "" + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + "<root>\r\n" + " <first value=\"80\"/>\r\n" + " <second>10</second>\r\n" + " <second>20</second>\r\n" + "</root>\r\n"; var factory = new OxbinderFactory(); var binder = factory.Of <MandatoryMultipleOptionalRoot>(); var reader = new StringReader(xml); var root = binder.NewInstance(reader); _ = root.First ?? throw new NullReferenceException(); Assert.AreEqual("80", root.First.Value); Assert.AreEqual(2, root.SecondCombo.Count()); var array = root.SecondCombo.Select(e => e.Value) .ToArray(); var expect = new[] { "10", "20" }; Assert.AreEqual(expect[0], array[0]); Assert.AreEqual(expect[1], array[1]); Assert.IsNull(root.Third); }
/// <summary> /// Checks the <see cref="BindException"/> that /// <see cref="Oxbinder{T}.NewInstance(TextReader)"/> /// with the specified XML document throws. /// </summary> /// <typeparam name="T"> /// The class associated with the root element. /// </typeparam> /// <param name="xml"> /// The XML document. /// </param> /// <param name="message"> /// The expected message that the <see cref="BindException"/> contains. /// </param> public static void ThrowBindException <T>(string xml, string message) where T : class { var factory = new OxbinderFactory(); var binder = factory.Of <T>(); ThrowBindException(binder, xml, message); }
public void CaseIgnoreWarnings() { var f = new OxbinderFactory(true); var b = f.Of <Content>(); var m = "2:4: unexpected node type: Element of the element 'page' " + "(it is expected that the element 'content' ends)"; Checks.ThrowBindException(b, Xml, m); }
public void EmptyElement() { const string xml = "" + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + "<root/>\r\n"; var factory = new OxbinderFactory(); var binder = factory.Of <Root>(); var reader = new StringReader(xml); var root = binder.NewInstance(reader); Assert.IsNull(root.First); Assert.AreEqual(0, root.SecondCombo.Count()); }
public void RootTest() { const string xml = "" + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + "<root>\r\n" + " <first fake=\"70\" value=\"80\" dummy=\"90\"/>\r\n" + "</root>\r\n"; var factory = new OxbinderFactory(); var binder = factory.Of <Root>(); var reader = new StringReader(xml); var root = binder.NewInstance(reader); _ = root.First ?? throw new NullReferenceException(); Assert.AreEqual("80", root.First.Value); }
public void RootTest() { const string xml = "" + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + "<root>\r\n" + " <first value=\"80\"/>\r\n" + " <second>10</second>\r\n" + " <second>20</second>\r\n" + "</root>\r\n"; var factory = new OxbinderFactory(); var binder = factory.Of <AttributeRoot>(); var reader = new StringReader(xml); var root = binder.NewInstance(reader); root.Test(); }
public void EmptyTextElement() { const string xml = "" + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + "<root>\r\n" + " <first/>\r\n" + "</root>\r\n"; var factory = new OxbinderFactory(); var binder = factory.Of <Root>(); var reader = new StringReader(xml); var root = binder.NewInstance(reader); _ = root.First ?? throw new NullReferenceException(); Assert.AreEqual("", root.First.Value); Assert.AreEqual(0, root.SecondCombo.Count()); }
private static ConfigPod NewRootConfig( string path, string source) { try { var reader = new StringReader(source); var factory = new OxbinderFactory(); var decoder = factory.Of <RootConfig>(); var rootConfig = decoder.NewInstance(reader); return(new ConfigPod(rootConfig, null, path)); } catch (Exception e) { return(new ConfigPod(DefaultRootConfig, e, path)); } }
public void DefaultNamespace() { var xml = "" + $"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + $"<root xmlns=\"{AlphaNamespace}\"\r\n" + $" xmlns:b=\"{BetaNamespace}\">\r\n" + $" <first b:value=\"10\" value=\"30\">20</first>\r\n" + $"</root>\r\n"; var factory = new OxbinderFactory(); var binder = factory.Of <Root>(); var reader = new StringReader(xml); var root = binder.NewInstance(reader); _ = root.First ?? throw new NullReferenceException(); Assert.AreEqual("20", root.First.Text); Assert.AreEqual("10", root.First.BetaValue); Assert.AreEqual("30", root.First.Value); }