public void FromXmlDoublePass() { var input = new RowsBuilder().Row().Field("f1", "<order><id>1</id><total>7.25</total><lines><line product=\"1\"/><line product=\"2\"/></lines></order>").ToOperation(); var outFields = new FieldsBuilder() .Field("id").Type("int32") .Field("total").Type("decimal") .Field("lines").ReadInnerXml(false) .ToFields(); var fromXml = new FromXmlOperation("f1", string.Empty, outFields); var output = TestOperation(input, fromXml); Assert.AreEqual(1, output[0]["id"]); Assert.AreEqual(7.25M, output[0]["total"]); Assert.AreEqual("<lines><line product=\"1\" /><line product=\"2\" /></lines>", output[0]["lines"]); //second pass to get lines input = new RowsBuilder(output).ToOperation(); outFields = new FieldsBuilder().Field("product").Type("int32").NodeType("attribute").ToFields(); fromXml = new FromXmlOperation("lines", string.Empty, outFields); output = TestOperation(input, fromXml); Assert.AreEqual(1, output[0]["id"]); Assert.AreEqual(7.25M, output[0]["total"]); Assert.AreEqual(1, output[0]["product"]); Assert.AreEqual(1, output[1]["id"]); Assert.AreEqual(7.25M, output[1]["total"]); Assert.AreEqual(2, output[1]["product"]); }
public void FromXmlWithMultipleRecords() { const string xml = @" <order> <detail product-id=""1"" quantity=""2"" color=""red"" /> <detail product-id=""3"" quantity=""1"" color=""pink"" /> </order> "; var input = new RowsBuilder().Row().Field("xml", xml).ToOperation(); var outFields = new FieldsBuilder() .Field("product-id").Type("int32").NodeType("attribute") .Field("quantity").Type("int32").NodeType("attribute") .Field("color").Type("string").NodeType("attribute") .ToFields(); var fromXmlTransform = new FromXmlOperation("xml", string.Empty, outFields); var output = TestOperation(input, fromXmlTransform); Assert.AreEqual(1, output[0]["product-id"]); Assert.AreEqual(2, output[0]["quantity"]); Assert.AreEqual("red", output[0]["color"]); Assert.AreEqual(3, output[1]["product-id"]); Assert.AreEqual(1, output[1]["quantity"]); Assert.AreEqual("pink", output[1]["color"]); }
public void FromXml() { var input = new RowsBuilder().Row().Field("f1", "<order><id>1</id><total>7.25</total><lines><line product=\"1\"/><line product=\"2\"/></lines></order>").ToOperation(); var outFields = new FieldsBuilder() .Field("id").Type("int32") .Field("total").Type("decimal") .Field("lines") .ToFields(); var fromXml = new FromXmlOperation("f1", string.Empty, outFields); var rows = TestOperation(input, fromXml); Assert.AreEqual(1, rows[0]["id"]); Assert.AreEqual(7.25M, rows[0]["total"]); Assert.AreEqual("<line product=\"1\" /><line product=\"2\" />", rows[0]["lines"]); }