From 7cc9cb407b52565b49c9d813188d144de5f7843e Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Wed, 11 May 2016 18:07:03 +0100 Subject: [PATCH] Move test for standalone BoolValue to JsonParserTest Also added a standalone formatter test, for confidence. Have validated that undoing the change in 835fb947 breaks the tests (i.e. we are still testing that the change is required). --- .../Google.Protobuf.Test/JsonFormatterTest.cs | 16 ++++++++++++++++ .../src/Google.Protobuf.Test/JsonParserTest.cs | 3 +++ .../WellKnownTypes/WrappersTest.cs | 7 ------- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs b/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs index 827a75956f..77f9c434d9 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(() => 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)); + } + /// /// 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 c3ad851b8a..f595455aa1 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.Test/WellKnownTypes/WrappersTest.cs b/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs index 18d18be382..5b7185dcd2 100644 --- a/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs +++ b/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs @@ -417,12 +417,5 @@ namespace Google.Protobuf.WellKnownTypes TestWellKnownTypes.Descriptor.Fields[TestWellKnownTypes.StringFieldFieldNumber].Accessor.Clear(message); Assert.IsNull(message.StringField); } - - [Test] - public void GivenBoolValueWhenPerformingRoundTripEncodingViaJsonThenShouldNotExpectObjectAtTopLevel() - { - var value = new BoolValue { Value = true }; - Assert.AreEqual(value, JsonParser.Default.Parse(JsonFormatter.Default.Format(value))); - } } }