diff options
Diffstat (limited to 'csharp')
-rw-r--r-- | csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs | 16 | ||||
-rw-r--r-- | csharp/src/Google.Protobuf.Test/JsonParserTest.cs | 3 | ||||
-rw-r--r-- | csharp/src/Google.Protobuf/JsonParser.cs | 3 |
3 files changed, 21 insertions, 1 deletions
diff --git a/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs b/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs index 827a7595..77f9c434 100644 --- a/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs @@ -512,6 +512,22 @@ namespace Google.Protobuf Assert.Throws<InvalidOperationException>(() => JsonFormatter.Default.Format(any)); } + [Test] + [TestCase(typeof(BoolValue), true, "true")] + [TestCase(typeof(Int32Value), 32, "32")] + [TestCase(typeof(Int64Value), 32L, "\"32\"")] + [TestCase(typeof(UInt32Value), 32U, "32")] + [TestCase(typeof(UInt64Value), 32UL, "\"32\"")] + [TestCase(typeof(StringValue), "foo", "\"foo\"")] + [TestCase(typeof(FloatValue), 1.5f, "1.5")] + [TestCase(typeof(DoubleValue), 1.5d, "1.5")] + public void Wrappers_Standalone(System.Type wrapperType, object value, string expectedJson) + { + IMessage populated = (IMessage)Activator.CreateInstance(wrapperType); + populated.Descriptor.Fields[WrappersReflection.WrapperValueFieldNumber].Accessor.SetValue(populated, value); + Assert.AreEqual(expectedJson, JsonFormatter.Default.Format(populated)); + } + /// <summary> /// Checks that the actual JSON is the same as the expected JSON - but after replacing /// all apostrophes in the expected JSON with double quotes. This basically makes the tests easier diff --git a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs index c3ad851b..f595455a 100644 --- a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs @@ -133,9 +133,12 @@ namespace Google.Protobuf } [Test] + [TestCase(typeof(BoolValue), "true", true)] [TestCase(typeof(Int32Value), "32", 32)] [TestCase(typeof(Int64Value), "32", 32L)] + [TestCase(typeof(Int64Value), "\"32\"", 32L)] [TestCase(typeof(UInt32Value), "32", 32U)] + [TestCase(typeof(UInt64Value), "\"32\"", 32UL)] [TestCase(typeof(UInt64Value), "32", 32UL)] [TestCase(typeof(StringValue), "\"foo\"", "foo")] [TestCase(typeof(FloatValue), "1.5", 1.5f)] diff --git a/csharp/src/Google.Protobuf/JsonParser.cs b/csharp/src/Google.Protobuf/JsonParser.cs index d738ebb0..6b6f2d9a 100644 --- a/csharp/src/Google.Protobuf/JsonParser.cs +++ b/csharp/src/Google.Protobuf/JsonParser.cs @@ -86,7 +86,8 @@ namespace Google.Protobuf { FloatValue.Descriptor.FullName, MergeWrapperField }, { DoubleValue.Descriptor.FullName, MergeWrapperField }, { BytesValue.Descriptor.FullName, MergeWrapperField }, - { StringValue.Descriptor.FullName, MergeWrapperField } + { StringValue.Descriptor.FullName, MergeWrapperField }, + { BoolValue.Descriptor.FullName, MergeWrapperField } }; // Convenience method to avoid having to repeat the same code multiple times in the above |