diff options
author | Jan Tattermusch <jtattermusch@users.noreply.github.com> | 2015-07-20 09:36:54 -0700 |
---|---|---|
committer | Jan Tattermusch <jtattermusch@users.noreply.github.com> | 2015-07-20 09:36:54 -0700 |
commit | bd3367c8b4c22687fde6c78088242b60f88e5c17 (patch) | |
tree | 410dee597653917b53ff1d7646b92deb5b15ffda /csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs | |
parent | 3f5df7a74b9d6989d0ea0cb0664f0105d80767eb (diff) | |
parent | c9fd53a3b742f2a34c527cbe0833c5bc081e6ec3 (diff) | |
download | protobuf-bd3367c8b4c22687fde6c78088242b60f88e5c17.tar.gz protobuf-bd3367c8b4c22687fde6c78088242b60f88e5c17.tar.bz2 protobuf-bd3367c8b4c22687fde6c78088242b60f88e5c17.zip |
Merge pull request #624 from jskeet/wkt-json
First part of JSON formatting for well-known types.
Diffstat (limited to 'csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs')
-rw-r--r-- | csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs b/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs index 5441bf47..a6715698 100644 --- a/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs @@ -257,5 +257,32 @@ namespace Google.Protobuf formatter = new JsonFormatter(new JsonFormatter.Settings(true)); Assert.AreEqual(expectedJson, formatter.Format(message)); } + + [Test] + public void WrapperFormatting_Single() + { + // Just a few examples, handling both classes and value types, and + // default vs non-default values + var message = new TestWellKnownTypes + { + Int64Field = 10, + Int32Field = 0, + BytesField = ByteString.FromBase64("ABCD"), + StringField = "" + }; + var expectedJson = "{ \"int64Field\": \"10\", \"int32Field\": 0, \"stringField\": \"\", \"bytesField\": \"ABCD\" }"; + Assert.AreEqual(expectedJson, JsonFormatter.Default.Format(message)); + } + + [Test] + public void WrapperFormatting_IncludeNull() + { + // The actual JSON here is very large because there are lots of fields. Just test a couple of them. + var message = new TestWellKnownTypes { Int32Field = 10 }; + var formatter = new JsonFormatter(new JsonFormatter.Settings(true)); + var actualJson = formatter.Format(message); + Assert.IsTrue(actualJson.Contains("\"int64Field\": null")); + Assert.IsFalse(actualJson.Contains("\"int32Field\": null")); + } } } |