aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs
diff options
context:
space:
mode:
authorJan Tattermusch <jtattermusch@users.noreply.github.com>2015-04-17 14:15:52 -0700
committerJan Tattermusch <jtattermusch@users.noreply.github.com>2015-04-17 14:15:52 -0700
commit01c8c35ca3d3424a9473dd22ea2456933b3e8d36 (patch)
treede582cb9ef3e449f24015dec09f80e998806b26a /csharp/src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs
parent813d6d652d8091e9365bfbd01efb5f2ee8bdfbce (diff)
parent1eab56aee8dddcb656db67d9fb87a8cc6a2ac112 (diff)
downloadprotobuf-01c8c35ca3d3424a9473dd22ea2456933b3e8d36.tar.gz
protobuf-01c8c35ca3d3424a9473dd22ea2456933b3e8d36.tar.bz2
protobuf-01c8c35ca3d3424a9473dd22ea2456933b3e8d36.zip
Merge pull request #2 from jtattermusch/csharp_protobuf_imported
Pulling protobuf-csharp-port into csharp/ directory
Diffstat (limited to 'csharp/src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs')
-rw-r--r--csharp/src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs46
1 files changed, 46 insertions, 0 deletions
diff --git a/csharp/src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs b/csharp/src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs
new file mode 100644
index 00000000..70614744
--- /dev/null
+++ b/csharp/src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs
@@ -0,0 +1,46 @@
+using System.IO;
+using System.Xml;
+using Google.ProtocolBuffers.Serialization;
+using Google.ProtocolBuffers.TestProtos;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace Google.ProtocolBuffers.Compatibility
+{
+ [TestClass]
+ public class XmlCompatibilityTests : CompatibilityTests
+ {
+ protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
+ {
+ StringWriter text = new StringWriter();
+ XmlFormatWriter writer = XmlFormatWriter.CreateInstance(text);
+ writer.WriteMessage("root", message);
+ return text.ToString();
+ }
+
+ protected override TBuilder DeserializeMessage<TMessage, TBuilder>(object message, TBuilder builder, ExtensionRegistry registry)
+ {
+ XmlFormatReader reader = XmlFormatReader.CreateInstance((string)message);
+ return reader.Merge("root", builder, registry);
+ }
+ }
+
+ [TestClass]
+ public class XmlCompatibilityFormattedTests : CompatibilityTests
+ {
+ protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
+ {
+ StringWriter text = new StringWriter();
+ XmlWriter xwtr = XmlWriter.Create(text, new XmlWriterSettings { Indent = true, IndentChars = " " });
+
+ XmlFormatWriter writer = XmlFormatWriter.CreateInstance(xwtr).SetOptions(XmlWriterOptions.OutputNestedArrays);
+ writer.WriteMessage("root", message);
+ return text.ToString();
+ }
+
+ protected override TBuilder DeserializeMessage<TMessage, TBuilder>(object message, TBuilder builder, ExtensionRegistry registry)
+ {
+ XmlFormatReader reader = XmlFormatReader.CreateInstance((string)message).SetOptions(XmlReaderOptions.ReadNestedArrays);
+ return reader.Merge("root", builder, registry);
+ }
+ }
+} \ No newline at end of file