Added convenience methods for to/from xml and json
diff --git a/src/ProtocolBuffers.Test/TestWriterFormatXml.cs b/src/ProtocolBuffers.Test/TestWriterFormatXml.cs
index 2ddf39e..b5eb60b 100644
--- a/src/ProtocolBuffers.Test/TestWriterFormatXml.cs
+++ b/src/ProtocolBuffers.Test/TestWriterFormatXml.cs
@@ -13,6 +13,28 @@
public class TestWriterFormatXml
{
[Test]
+ public void TestToXmlParseFromXml()
+ {
+ TestAllTypes msg = new TestAllTypes.Builder().SetDefaultBool(true).Build();
+ string xml = msg.ToXml();
+ Assert.AreEqual("<root><default_bool>true</default_bool></root>", xml);
+ TestAllTypes copy = TestAllTypes.ParseFromXml(XmlReader.Create(new StringReader(xml)));
+ Assert.IsTrue(copy.HasDefaultBool && copy.DefaultBool);
+ Assert.AreEqual(msg, copy);
+ }
+
+ [Test]
+ public void TestToXmlParseFromXmlWithRootName()
+ {
+ TestAllTypes msg = new TestAllTypes.Builder().SetDefaultBool(true).Build();
+ string xml = msg.ToXml("message");
+ Assert.AreEqual("<message><default_bool>true</default_bool></message>", xml);
+ TestAllTypes copy = TestAllTypes.ParseFromXml("message", XmlReader.Create(new StringReader(xml)));
+ Assert.IsTrue(copy.HasDefaultBool && copy.DefaultBool);
+ Assert.AreEqual(msg, copy);
+ }
+
+ [Test]
public void TestEmptyMessage()
{
TestXmlChild message = TestXmlChild.CreateBuilder()