#region Copyright notice and license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc.  All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#endregion

using System;
using Google.Protobuf.TestProtos;
using NUnit.Framework;
using UnitTest.Issues.TestProtos;
using Google.Protobuf.WellKnownTypes;
using Google.Protobuf.Reflection;

using static Google.Protobuf.JsonParserTest; // For WrapInQuotes
using System.IO;
using Google.Protobuf.Collections;
using ProtobufUnittest;

namespace Google.Protobuf
{
    /// <summary>
    /// Tests for the JSON formatter. Note that in these tests, double quotes are replaced with apostrophes
    /// for the sake of readability (embedding \" everywhere is painful). See the AssertJson method for details.
    /// </summary>
    public class JsonFormatterTest
    {
        [Test]
        public void DefaultValues_WhenOmitted()
        {
            var formatter = JsonFormatter.Default;

            AssertJson("{ }", formatter.Format(new ForeignMessage()));
            AssertJson("{ }", formatter.Format(new TestAllTypes()));
            AssertJson("{ }", formatter.Format(new TestMap()));
        }

        [Test]
        public void DefaultValues_WhenIncluded()
        {
            var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithFormatDefaultValues(true));
            AssertJson("{ 'c': 0 }", formatter.Format(new ForeignMessage()));
        }

        [Test]
        public void EnumAllowAlias()
        {
            var message = new TestEnumAllowAlias
            {
                Value = TestEnumWithDupValue.Foo2,
            };
            var actualText = JsonFormatter.Default.Format(message);
            var expectedText = "{ 'value': 'FOO1' }";
            AssertJson(expectedText, actualText);
        }

        [Test]
        public void EnumAsInt()
        {
            var message = new TestAllTypes
            {
                SingleForeignEnum = ForeignEnum.ForeignBar,
                RepeatedForeignEnum = { ForeignEnum.ForeignBaz, (ForeignEnum) 100, ForeignEnum.ForeignFoo }
            };
            var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithFormatEnumsAsIntegers(true));
            var actualText = formatter.Format(message);
            var expectedText = "{ " +
                               "'singleForeignEnum': 5, " +
                               "'repeatedForeignEnum': [ 6, 100, 4 ]" +
                               " }";
            AssertJson(expectedText, actualText);
        }

        [Test]
        public void AllSingleFields()
        {
            var message = new TestAllTypes
            {
                SingleBool = true,
                SingleBytes = ByteString.CopyFrom(1, 2, 3, 4),
                SingleDouble = 23.5,
                SingleFixed32 = 23,
                SingleFixed64 = 1234567890123,
                SingleFloat = 12.25f,
                SingleForeignEnum = ForeignEnum.ForeignBar,
                SingleForeignMessage = new ForeignMessage { C = 10 },
                SingleImportEnum = ImportEnum.ImportBaz,
                SingleImportMessage = new ImportMessage { D = 20 },
                SingleInt32 = 100,
                SingleInt64 = 3210987654321,
                SingleNestedEnum = TestAllTypes.Types.NestedEnum.Foo,
                SingleNestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 35 },
                SinglePublicImportMessage = new PublicImportMessage { E = 54 },
                SingleSfixed32 = -123,
                SingleSfixed64 = -12345678901234,
                SingleSint32 = -456,
                SingleSint64 = -12345678901235,
                SingleString = "test\twith\ttabs",
                SingleUint32 = uint.MaxValue,
                SingleUint64 = ulong.MaxValue,
            };
            var actualText = JsonFormatter.Default.Format(message);

            // Fields in numeric order
            var expectedText = "{ " +
                "'singleInt32': 100, " +
                "'singleInt64': '3210987654321', " +
                "'singleUint32': 4294967295, " +
                "'singleUint64': '18446744073709551615', " +
                "'singleSint32': -456, " +
                "'singleSint64': '-12345678901235', " +
                "'singleFixed32': 23, " +
                "'singleFixed64': '1234567890123', " +
                "'singleSfixed32': -123, " +
                "'singleSfixed64': '-12345678901234', " +
                "'singleFloat': 12.25, " +
                "'singleDouble': 23.5, " +
                "'singleBool': true, " +
                "'singleString': 'test\\twith\\ttabs', " +
                "'singleBytes': 'AQIDBA==', " +
                "'singleNestedMessage': { 'bb': 35 }, " +
                "'singleForeignMessage': { 'c': 10 }, " +
                "'singleImportMessage': { 'd': 20 }, " +
                "'singleNestedEnum': 'FOO', " +
                "'singleForeignEnum': 'FOREIGN_BAR', " +
                "'singleImportEnum': 'IMPORT_BAZ', " +
                "'singlePublicImportMessage': { 'e': 54 }" +
                " }";
            AssertJson(expectedText, actualText);
        }

        [Test]
        public void WithFormatDefaultValues_DoesNotAffectMessageFields()
        {
            var message = new TestAllTypes();
            var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithFormatDefaultValues(true));
            var json = formatter.Format(message);
            Assert.IsFalse(json.Contains("\"singleNestedMessage\""));
            Assert.IsFalse(json.Contains("\"singleForeignMessage\""));
            Assert.IsFalse(json.Contains("\"singleImportMessage\""));
        }

        [Test]
        public void WithFormatDefaultValues_DoesNotAffectProto3OptionalFields()
        {
            var message = new TestProto3Optional { OptionalInt32 = 0 };
            var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithFormatDefaultValues(true));
            var json = formatter.Format(message);
            // The non-optional proto3 fields are formatted, as is the optional-but-specified field.
            AssertJson("{ 'optionalInt32': 0, 'singularInt32': 0, 'singularInt64': '0' }", json);
        }

        [Test]
        public void WithFormatDefaultValues_DoesNotAffectProto2Fields()
        {
            var message = new TestProtos.Proto2.ForeignMessage { C = 0 };
            var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithFormatDefaultValues(true));
            var json = formatter.Format(message);
            // The specified field is formatted, but the non-specified field (d) is not.
            AssertJson("{ 'c': 0 }", json);
        }

        [Test]
        public void WithFormatDefaultValues_DoesNotAffectOneofFields()
        {
            var message = new TestOneof();
            var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithFormatDefaultValues(true));
            var json = formatter.Format(message);
            AssertJson("{ }", json);
        }

        [Test]
        public void RepeatedField()
        {
            AssertJson("{ 'repeatedInt32': [ 1, 2, 3, 4, 5 ] }",
                JsonFormatter.Default.Format(new TestAllTypes { RepeatedInt32 = { 1, 2, 3, 4, 5 } }));
        }

        [Test]
        public void MapField_StringString()
        {
            AssertJson("{ 'mapStringString': { 'with spaces': 'bar', 'a': 'b' } }",
                JsonFormatter.Default.Format(new TestMap { MapStringString = { { "with spaces", "bar" }, { "a", "b" } } }));
        }

        [Test]
        public void MapField_Int32Int32()
        {
            // The keys are quoted, but the values aren't.
            AssertJson("{ 'mapInt32Int32': { '0': 1, '2': 3 } }",
                JsonFormatter.Default.Format(new TestMap { MapInt32Int32 = { { 0, 1 }, { 2, 3 } } }));
        }

        [Test]
        public void MapField_BoolBool()
        {
            // The keys are quoted, but the values aren't.
            AssertJson("{ 'mapBoolBool': { 'false': true, 'true': false } }",
                JsonFormatter.Default.Format(new TestMap { MapBoolBool = { { false, true }, { true, false } } }));
        }

        [Test]
        public void NullValueOutsideStruct()
        {
            var message = new NullValueOutsideStruct { NullValue = NullValue.NullValue };
            AssertJson("{ 'nullValue': null }", JsonFormatter.Default.Format(message));
        }

        [Test]
        public void NullValueNotInOneof()
        {
            var message = new NullValueNotInOneof();
            AssertJson("{ }", JsonFormatter.Default.Format(message));
        }

        [Test]
        public void NullValueNotInOneof_FormatDefaults()
        {
            var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithFormatDefaultValues(true));
            var message = new NullValueNotInOneof();
            AssertJson("{ 'nullValue': null }", formatter.Format(message));
        }

        [TestCase(1.0, "1")]
        [TestCase(double.NaN, "'NaN'")]
        [TestCase(double.PositiveInfinity, "'Infinity'")]
        [TestCase(double.NegativeInfinity, "'-Infinity'")]
        public void DoubleRepresentations(double value, string expectedValueText)
        {
            var message = new TestAllTypes { SingleDouble = value };
            string actualText = JsonFormatter.Default.Format(message);
            string expectedText = "{ 'singleDouble': " + expectedValueText + " }";
            AssertJson(expectedText, actualText);
        }

        [Test]
        public void UnknownEnumValueNumeric_SingleField()
        {
            var message = new TestAllTypes { SingleForeignEnum = (ForeignEnum) 100 };
            AssertJson("{ 'singleForeignEnum': 100 }", JsonFormatter.Default.Format(message));
        }

        [Test]
        public void UnknownEnumValueNumeric_RepeatedField()
        {
            var message = new TestAllTypes { RepeatedForeignEnum = { ForeignEnum.ForeignBaz, (ForeignEnum) 100, ForeignEnum.ForeignFoo } };
            AssertJson("{ 'repeatedForeignEnum': [ 'FOREIGN_BAZ', 100, 'FOREIGN_FOO' ] }", JsonFormatter.Default.Format(message));
        }

        [Test]
        public void UnknownEnumValueNumeric_MapField()
        {
            var message = new TestMap { MapInt32Enum = { { 1, MapEnum.Foo }, { 2, (MapEnum) 100 }, { 3, MapEnum.Bar } } };
            AssertJson("{ 'mapInt32Enum': { '1': 'MAP_ENUM_FOO', '2': 100, '3': 'MAP_ENUM_BAR' } }", JsonFormatter.Default.Format(message));
        }

        [Test]
        public void UnknownEnumValue_RepeatedField_AllEntriesUnknown()
        {
            var message = new TestAllTypes { RepeatedForeignEnum = { (ForeignEnum) 200, (ForeignEnum) 100 } };
            AssertJson("{ 'repeatedForeignEnum': [ 200, 100 ] }", JsonFormatter.Default.Format(message));
        }

        [Test]
        [TestCase("a\u17b4b", "a\\u17b4b")] // Explicit
        [TestCase("a\u0601b", "a\\u0601b")] // Ranged
        [TestCase("a\u0605b", "a\u0605b")] // Passthrough (note lack of double backslash...)
        public void SimpleNonAscii(string text, string encoded)
        {
            var message = new TestAllTypes { SingleString = text };
            AssertJson("{ 'singleString': '" + encoded + "' }", JsonFormatter.Default.Format(message));
        }

        [Test]
        public void SurrogatePairEscaping()
        {
            var message = new TestAllTypes { SingleString = "a\uD801\uDC01b" };
            AssertJson("{ 'singleString': 'a\\ud801\\udc01b' }", JsonFormatter.Default.Format(message));
        }

        [Test]
        public void InvalidSurrogatePairsFail()
        {
            // Note: don't use TestCase for these, as the strings can't be reliably represented
            // See http://codeblog.jonskeet.uk/2014/11/07/when-is-a-string-not-a-string/

            // Lone low surrogate
            var message = new TestAllTypes { SingleString = "a\uDC01b" };
            Assert.Throws<ArgumentException>(() => JsonFormatter.Default.Format(message));

            // Lone high surrogate
            message = new TestAllTypes { SingleString = "a\uD801b" };
            Assert.Throws<ArgumentException>(() => JsonFormatter.Default.Format(message));
        }

        [Test]
        [TestCase("foo_bar", "fooBar")]
        [TestCase("bananaBanana", "bananaBanana")]
        [TestCase("BANANABanana", "BANANABanana")]
        [TestCase("simple", "simple")]
        [TestCase("ACTION_AND_ADVENTURE", "ACTIONANDADVENTURE")]
        [TestCase("action_and_adventure", "actionAndAdventure")]
        [TestCase("kFoo", "kFoo")]
        [TestCase("HTTPServer", "HTTPServer")]
        [TestCase("CLIENT", "CLIENT")]
        public void ToJsonName(string original, string expected)
        {
            Assert.AreEqual(expected, JsonFormatter.ToJsonName(original));
        }

        [Test]
        [TestCase(null, "{ }")]
        [TestCase("x", "{ 'fooString': 'x' }")]
        [TestCase("", "{ 'fooString': '' }")]
        public void Oneof(string fooStringValue, string expectedJson)
        {
            var message = new TestOneof();
            if (fooStringValue != null)
            {
                message.FooString = fooStringValue;
            }

            // We should get the same result both with and without "format default values".
            var formatter = JsonFormatter.Default;
            AssertJson(expectedJson, formatter.Format(message));
            formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithFormatDefaultValues(true));
            AssertJson(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' }";
            AssertJson(expectedJson, JsonFormatter.Default.Format(message));
        }

        [Test]
        public void WrapperFormatting_Message()
        {
            Assert.AreEqual("\"\"", JsonFormatter.Default.Format(new StringValue()));
            Assert.AreEqual("0", JsonFormatter.Default.Format(new Int32Value()));
        }

        [Test]
        public void WrapperFormatting_FormatDefaultValuesDoesNotFormatNull()
        {
            // 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(JsonFormatter.Settings.Default.WithFormatDefaultValues(true));
            var actualJson = formatter.Format(message);
            // This *used* to include "int64Field": null, but that was a bug.
            // WithDefaultValues should not affect message fields, including wrapper types.
            Assert.IsFalse(actualJson.Contains("\"int64Field\": null"));
            Assert.IsTrue(actualJson.Contains("\"int32Field\": 10"));
        }

        [Test]
        public void OutputIsInNumericFieldOrder_NoDefaults()
        {
            var formatter = JsonFormatter.Default;
            var message = new TestJsonFieldOrdering { PlainString = "p1", PlainInt32 = 2 };
            AssertJson("{ 'plainString': 'p1', 'plainInt32': 2 }", formatter.Format(message));
            message = new TestJsonFieldOrdering { O1Int32 = 5, O2String = "o2", PlainInt32 = 10, PlainString = "plain" };
            AssertJson("{ 'plainString': 'plain', 'o2String': 'o2', 'plainInt32': 10, 'o1Int32': 5 }", formatter.Format(message));
            message = new TestJsonFieldOrdering { O1String = "", O2Int32 = 0, PlainInt32 = 10, PlainString = "plain" };
            AssertJson("{ 'plainString': 'plain', 'o1String': '', 'plainInt32': 10, 'o2Int32': 0 }", formatter.Format(message));
        }

        [Test]
        public void OutputIsInNumericFieldOrder_WithDefaults()
        {
            var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithFormatDefaultValues(true));
            var message = new TestJsonFieldOrdering();
            AssertJson("{ 'plainString': '', 'plainInt32': 0 }", formatter.Format(message));
            message = new TestJsonFieldOrdering { O1Int32 = 5, O2String = "o2", PlainInt32 = 10, PlainString = "plain" };
            AssertJson("{ 'plainString': 'plain', 'o2String': 'o2', 'plainInt32': 10, 'o1Int32': 5 }", formatter.Format(message));
            message = new TestJsonFieldOrdering { O1String = "", O2Int32 = 0, PlainInt32 = 10, PlainString = "plain" };
            AssertJson("{ 'plainString': 'plain', 'o1String': '', 'plainInt32': 10, 'o2Int32': 0 }", formatter.Format(message));
        }

        [Test]
        [TestCase("1970-01-01T00:00:00Z", 0)]
        [TestCase("1970-01-01T00:00:00.000000001Z", 1)]
        [TestCase("1970-01-01T00:00:00.000000010Z", 10)]
        [TestCase("1970-01-01T00:00:00.000000100Z", 100)]
        [TestCase("1970-01-01T00:00:00.000001Z", 1000)]
        [TestCase("1970-01-01T00:00:00.000010Z", 10000)]
        [TestCase("1970-01-01T00:00:00.000100Z", 100000)]
        [TestCase("1970-01-01T00:00:00.001Z", 1000000)]
        [TestCase("1970-01-01T00:00:00.010Z", 10000000)]
        [TestCase("1970-01-01T00:00:00.100Z", 100000000)]
        [TestCase("1970-01-01T00:00:00.120Z", 120000000)]
        [TestCase("1970-01-01T00:00:00.123Z", 123000000)]
        [TestCase("1970-01-01T00:00:00.123400Z", 123400000)]
        [TestCase("1970-01-01T00:00:00.123450Z", 123450000)]
        [TestCase("1970-01-01T00:00:00.123456Z", 123456000)]
        [TestCase("1970-01-01T00:00:00.123456700Z", 123456700)]
        [TestCase("1970-01-01T00:00:00.123456780Z", 123456780)]
        [TestCase("1970-01-01T00:00:00.123456789Z", 123456789)]
        public void TimestampStandalone(string expected, int nanos)
        {
            Assert.AreEqual(WrapInQuotes(expected), new Timestamp { Nanos = nanos }.ToString());
        }

        [Test]
        public void TimestampStandalone_FromDateTime()
        {
            // One before and one after the Unix epoch, more easily represented via DateTime.
            Assert.AreEqual("\"1673-06-19T12:34:56Z\"",
                new DateTime(1673, 6, 19, 12, 34, 56, DateTimeKind.Utc).ToTimestamp().ToString());
            Assert.AreEqual("\"2015-07-31T10:29:34Z\"",
                new DateTime(2015, 7, 31, 10, 29, 34, DateTimeKind.Utc).ToTimestamp().ToString());
        }

        [Test]
        [TestCase(-1, -1)] // Would be valid as duration
        [TestCase(1, Timestamp.MaxNanos + 1)]
        [TestCase(Timestamp.UnixSecondsAtBclMaxValue + 1, 0)]
        [TestCase(Timestamp.UnixSecondsAtBclMinValue - 1, 0)]
        public void TimestampStandalone_NonNormalized(long seconds, int nanoseconds)
        {
            var timestamp = new Timestamp { Seconds = seconds, Nanos = nanoseconds };
            Assert.Throws<InvalidOperationException>(() => JsonFormatter.Default.Format(timestamp));
        }

        [Test]
        public void TimestampField()
        {
            var message = new TestWellKnownTypes { TimestampField = new Timestamp() };
            AssertJson("{ 'timestampField': '1970-01-01T00:00:00Z' }", JsonFormatter.Default.Format(message));
        }

        [Test]
        [TestCase(0, 0, "0s")]
        [TestCase(1, 0, "1s")]
        [TestCase(-1, 0, "-1s")]
        [TestCase(0, 1, "0.000000001s")]
        [TestCase(0, 10, "0.000000010s")]
        [TestCase(0, 100, "0.000000100s")]
        [TestCase(0, 1000, "0.000001s")]
        [TestCase(0, 10000, "0.000010s")]
        [TestCase(0, 100000, "0.000100s")]
        [TestCase(0, 1000000, "0.001s")]
        [TestCase(0, 10000000, "0.010s")]
        [TestCase(0, 100000000, "0.100s")]
        [TestCase(0, 120000000, "0.120s")]
        [TestCase(0, 123000000, "0.123s")]
        [TestCase(0, 123400000, "0.123400s")]
        [TestCase(0, 123450000, "0.123450s")]
        [TestCase(0, 123456000, "0.123456s")]
        [TestCase(0, 123456700, "0.123456700s")]
        [TestCase(0, 123456780, "0.123456780s")]
        [TestCase(0, 123456789, "0.123456789s")]
        [TestCase(0, -100000000, "-0.100s")]
        [TestCase(1, 100000000, "1.100s")]
        [TestCase(-1, -100000000, "-1.100s")]
        public void DurationStandalone(long seconds, int nanoseconds, string expected)
        {
            var json = JsonFormatter.Default.Format(new Duration { Seconds = seconds, Nanos = nanoseconds });
            Assert.AreEqual(WrapInQuotes(expected), json);
        }

        [Test]
        [TestCase(1, 2123456789)]
        [TestCase(1, -100000000)]
        public void DurationStandalone_NonNormalized(long seconds, int nanoseconds)
        {
            var duration = new Duration { Seconds = seconds, Nanos = nanoseconds };
            Assert.Throws<InvalidOperationException>(() => JsonFormatter.Default.Format(duration));
        }

        [Test]
        public void DurationField()
        {
            var message = new TestWellKnownTypes { DurationField = new Duration() };
            AssertJson("{ 'durationField': '0s' }", JsonFormatter.Default.Format(message));
        }

        [Test]
        public void StructSample()
        {
            var message = new Struct
            {
                Fields =
                {
                    { "a", Value.ForNull() },
                    { "b", Value.ForBool(false) },
                    { "c", Value.ForNumber(10.5) },
                    { "d", Value.ForString("text") },
                    { "e", Value.ForList(Value.ForString("t1"), Value.ForNumber(5)) },
                    { "f", Value.ForStruct(new Struct { Fields = { { "nested", Value.ForString("value") } } }) }
                }
            };
            AssertJson("{ 'a': null, 'b': false, 'c': 10.5, 'd': 'text', 'e': [ 't1', 5 ], 'f': { 'nested': 'value' } }", message.ToString());
        }

        [Test]
        [TestCase("foo__bar")]
        [TestCase("foo_3_ar")]
        [TestCase("fooBar")]
        public void FieldMaskInvalid(string input)
        {
            var mask = new FieldMask { Paths = { input } };
            Assert.Throws<InvalidOperationException>(() => JsonFormatter.Default.Format(mask));
        }

        [Test]
        public void FieldMaskStandalone()
        {
            var fieldMask = new FieldMask { Paths = { "", "single", "with_underscore", "nested.field.name", "nested..double_dot" } };
            Assert.AreEqual("\",single,withUnderscore,nested.field.name,nested..doubleDot\"", fieldMask.ToString());

            // Invalid, but we shouldn't create broken JSON...
            fieldMask = new FieldMask { Paths = { "x\\y" } };
            Assert.AreEqual(@"""x\\y""", fieldMask.ToString());
        }

        [Test]
        public void FieldMaskField()
        {
            var message = new TestWellKnownTypes { FieldMaskField = new FieldMask { Paths = { "user.display_name", "photo" } } };
            AssertJson("{ 'fieldMaskField': 'user.displayName,photo' }", JsonFormatter.Default.Format(message));
        }

        // SourceContext is an example of a well-known type with no special JSON handling
        [Test]
        public void SourceContextStandalone()
        {
            var message = new SourceContext { FileName = "foo.proto" };
            AssertJson("{ 'fileName': 'foo.proto' }", JsonFormatter.Default.Format(message));
        }

        [Test]
        public void AnyWellKnownType()
        {
            var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithTypeRegistry(TypeRegistry.FromMessages(Timestamp.Descriptor)));
            var timestamp = new DateTime(1673, 6, 19, 12, 34, 56, DateTimeKind.Utc).ToTimestamp();
            var any = Any.Pack(timestamp);
            AssertJson("{ '@type': 'type.googleapis.com/google.protobuf.Timestamp', 'value': '1673-06-19T12:34:56Z' }", formatter.Format(any));
        }

        [Test]
        public void AnyMessageType()
        {
            var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithTypeRegistry(TypeRegistry.FromMessages(TestAllTypes.Descriptor)));
            var message = new TestAllTypes { SingleInt32 = 10, SingleNestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 20 } };
            var any = Any.Pack(message);
            AssertJson("{ '@type': 'type.googleapis.com/protobuf_unittest3.TestAllTypes', 'singleInt32': 10, 'singleNestedMessage': { 'bb': 20 } }", formatter.Format(any));
        }

        [Test]
        public void AnyMessageType_CustomPrefix()
        {
            var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithTypeRegistry(TypeRegistry.FromMessages(TestAllTypes.Descriptor)));
            var message = new TestAllTypes { SingleInt32 = 10 };
            var any = Any.Pack(message, "foo.bar/baz");
            AssertJson("{ '@type': 'foo.bar/baz/protobuf_unittest3.TestAllTypes', 'singleInt32': 10 }", formatter.Format(any));
        }

        [Test]
        public void AnyNested()
        {
            var registry = TypeRegistry.FromMessages(TestWellKnownTypes.Descriptor, TestAllTypes.Descriptor);
            var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithTypeRegistry(registry));

            // Nest an Any as the value of an Any.
            var doubleNestedMessage = new TestAllTypes { SingleInt32 = 20 };
            var nestedMessage = Any.Pack(doubleNestedMessage);
            var message = new TestWellKnownTypes { AnyField = Any.Pack(nestedMessage) };
            AssertJson("{ 'anyField': { '@type': 'type.googleapis.com/google.protobuf.Any', 'value': { '@type': 'type.googleapis.com/protobuf_unittest3.TestAllTypes', 'singleInt32': 20 } } }",
                formatter.Format(message));
        }

        [Test]
        public void AnyUnknownType()
        {
            // The default type registry doesn't have any types in it.
            var message = new TestAllTypes();
            var any = Any.Pack(message);
            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));
        }

        // See See https://github.com/protocolbuffers/protobuf/issues/11987
        [Test]
        public void JsonNamePriority()
        {
            // This tests both the formatter and the parser, but the issue was when parsing.
            var original = new Issue11987Message { A = 10, B = 20, C = 30 };
            var json = JsonFormatter.Default.Format(original);
            AssertJson("{ 'b': 10, 'a': 20, 'd': 30 }", json);
            var parsed = Issue11987Message.Parser.ParseJson(json);
            Assert.AreEqual(original, parsed);
        }

        // Sanity tests for WriteValue. Not particularly comprehensive, as it's all covered above already,
        // as FormatMessage uses WriteValue.

        [TestCase(null, "null")]
        [TestCase(1, "1")]
        [TestCase(1L, "'1'")]
        [TestCase(0.5f, "0.5")]
        [TestCase(0.5d, "0.5")]
        [TestCase("text", "'text'")]
        [TestCase("x\ny", @"'x\ny'")]
        [TestCase(ForeignEnum.ForeignBar, "'FOREIGN_BAR'")]
        public void WriteValue_Constant(object value, string expectedJson)
        {
            AssertWriteValue(value, expectedJson);
        }

        [Test]
        public void WriteValue_Timestamp()
        {
            var value = new DateTime(1673, 6, 19, 12, 34, 56, DateTimeKind.Utc).ToTimestamp();
            AssertWriteValue(value, "'1673-06-19T12:34:56Z'");
        }

        [Test]
        public void WriteValue_Message()
        {
            var value = new TestAllTypes { SingleInt32 = 100, SingleInt64 = 3210987654321L };
            AssertWriteValue(value, "{ 'singleInt32': 100, 'singleInt64': '3210987654321' }");
        }

        [Test]
        public void WriteValue_Message_PreserveNames()
        {
            var value = new TestAllTypes { SingleInt32 = 100, SingleInt64 = 3210987654321L };
            AssertWriteValue(value, "{ 'single_int32': 100, 'single_int64': '3210987654321' }", JsonFormatter.Settings.Default.WithPreserveProtoFieldNames(true));
        }

        [Test]
        public void WriteValue_List()
        {
            var value = new RepeatedField<int> { 1, 2, 3 };
            AssertWriteValue(value, "[ 1, 2, 3 ]");
        }

        [Test]
        public void WriteValueWithIndentation_EmptyMessage()
        {
            var value = new TestEmptyMessage();

            AssertWriteValue(value, "{}", JsonFormatter.Settings.Default.WithIndentation());
        }

        [Test]
        public void WriteValueWithIndentation_NestedTestAllTypes()
        {
            var value = new NestedTestAllTypes
            {
                Payload = new TestAllTypes
                {
                    SingleBool = true,
                    SingleInt32 = 100,
                    SingleString = "multiple fields",
                    RepeatedString = { "string1", "string2" },
                },
                Child = new NestedTestAllTypes
                {
                    Payload = new TestAllTypes
                    {
                        SingleString = "single field",
                    },
                },
                RepeatedChild =
                {
                    new NestedTestAllTypes { Payload = new TestAllTypes { SingleString = "child 1", RepeatedString = { "string" } } },
                    new NestedTestAllTypes { Payload = new TestAllTypes { SingleString = "child 2" } },
                },
            };

            const string expectedJson = @"
{
  'child': {
    'payload': {
      'singleString': 'single field'
    }
  },
  'payload': {
    'singleInt32': 100,
    'singleBool': true,
    'singleString': 'multiple fields',
    'repeatedString': [
      'string1',
      'string2'
    ]
  },
  'repeatedChild': [
    {
      'payload': {
        'singleString': 'child 1',
        'repeatedString': [
          'string'
        ]
      }
    },
    {
      'payload': {
        'singleString': 'child 2'
      }
    }
  ]
}";
            AssertWriteValue(value, expectedJson, JsonFormatter.Settings.Default.WithIndentation());
        }

        [Test]
        public void WriteValueWithIndentation_WellKnownTypes()
        {
            var value = new TestWellKnownTypes
            {
                StructField = new Struct
                {
                    Fields =
                    {
                        { "string", Value.ForString("foo") },
                        { "numbers", Value.ForList(Value.ForNumber(1), Value.ForNumber(2), Value.ForNumber(3)) },
                        { "emptyList", Value.ForList() },
                        { "emptyStruct", Value.ForStruct(new Struct()) },
                    },
                },
            };

            const string expectedJson = @"
{
  'structField': {
    'string': 'foo',
    'numbers': [
      1,
      2,
      3
    ],
    'emptyList': [],
    'emptyStruct': {}
  }
}";
            AssertWriteValue(value, expectedJson, JsonFormatter.Settings.Default.WithIndentation());
        }

        [Test]
        public void WriteValueWithIndentation_StructSingleField()
        {
            var value = new Struct { Fields = { { "structField1", Value.ForString("structFieldValue1") } } };

            const string expectedJson = @"
{
  'structField1': 'structFieldValue1'
}";
            AssertWriteValue(value, expectedJson, JsonFormatter.Settings.Default.WithIndentation());
        }

        [Test]
        public void WriteValueWithIndentation_StructMultipleFields()
        {
            var value = new Struct
            {
                Fields =
                {
                    { "structField1", Value.ForString("structFieldValue1") },
                    { "structField2", Value.ForString("structFieldValue2") },
                    { "structField3", Value.ForString("structFieldValue3") },
                },
            };

            const string expectedJson = @"
{
  'structField1': 'structFieldValue1',
  'structField2': 'structFieldValue2',
  'structField3': 'structFieldValue3'
}";
            AssertWriteValue(value, expectedJson, JsonFormatter.Settings.Default.WithIndentation());
        }

        [Test]
        public void FormatWithIndentation_EmbeddedMessage()
        {
            var value = new TestAllTypes { SingleInt32 = 100, SingleInt64 = 3210987654321L };
            var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithIndentation());
            var valueJson = formatter.Format(value, indentationLevel: 1);

            var actualJson = $@"
{{
  ""data"": {valueJson}
}}";
            const string expectedJson = @"
{
  'data': {
    'singleInt32': 100,
    'singleInt64': '3210987654321'
  }
}";
            AssertJson(expectedJson, actualJson.Trim());
        }

        [Test]
        public void WriteValueWithIndentation_Map()
        {
            var value = new TestMap
            {
                MapStringString =
                {
                    { "key1", "value1" },
                    { "key2", "value2" },
                },
            };

            const string expectedJson = @"
{
  'mapStringString': {
    'key1': 'value1',
    'key2': 'value2'
  }
}";

            AssertWriteValue(value, expectedJson, JsonFormatter.Settings.Default.WithIndentation());
        }

        [Test]
        public void WriteValueWithIndentation_MapWithNested()
        {
            var value = new TestMap
            {
                MapInt32ForeignMessage =
                {
                    { 1, new ForeignMessage { C = 1 } },
                    { 2, new ForeignMessage { C = 2 } },
                },
            };

            const string expectedJson = @"
{
  'mapInt32ForeignMessage': {
    '1': {
      'c': 1
    },
    '2': {
      'c': 2
    }
  }
}";

            AssertWriteValue(value, expectedJson, JsonFormatter.Settings.Default.WithIndentation());
        }

        [Test]
        public void WriteValueWithIndentation_MapWithEmptyNested()
        {
            var value = new TestMap
            {
                MapInt32ForeignMessage =
                {
                    { 1, new ForeignMessage() },
                    { 2, new ForeignMessage() },
                },
            };

            const string expectedJson = @"
{
  'mapInt32ForeignMessage': {
    '1': {},
    '2': {}
  }
}";

            AssertWriteValue(value, expectedJson, JsonFormatter.Settings.Default.WithIndentation());
        }

        [Test]
        public void WriteValueWithIndentation_List()
        {
            var value = new RepeatedField<int> { 1, 2, 3 };
            AssertWriteValue(value, "[\n  1,\n  2,\n  3\n]", JsonFormatter.Settings.Default.WithIndentation());
        }

        [Test]
        public void WriteValueWithIndentation_Any()
        {
            var registry = TypeRegistry.FromMessages(ForeignMessage.Descriptor);
            var formatter = JsonFormatter.Settings.Default.WithIndentation().WithTypeRegistry(registry);

            var nestedMessage = new ForeignMessage { C = 1 };
            var value = Any.Pack(nestedMessage);
            const string expectedJson = @"
{
  '@type': 'type.googleapis.com/protobuf_unittest3.ForeignMessage',
  'c': 1
}";

            AssertWriteValue(value, expectedJson, formatter);
        }

        [Test]
        public void WriteValueWithIndentation_NestedAny()
        {
            var registry = TypeRegistry.FromMessages(ForeignMessage.Descriptor);
            var formatter = JsonFormatter.Settings.Default.WithIndentation().WithTypeRegistry(registry);

            var nestedMessage = new ForeignMessage { C = 1 };
            var value = new TestWellKnownTypes { AnyField = Any.Pack(nestedMessage) };
            const string expectedJson = @"
{
  'anyField': {
    '@type': 'type.googleapis.com/protobuf_unittest3.ForeignMessage',
    'c': 1
  }
}";

            AssertWriteValue(value, expectedJson, formatter);
        }

        [Test]
        public void WriteValueWithIndentation_CustomIndentation()
        {
            var value = new RepeatedField<int> { 1, 2, 3 };
            AssertWriteValue(value, "[\n\t1,\n\t2,\n\t3\n]", JsonFormatter.Settings.Default.WithIndentation("\t"));
        }

        [Test]
        public void Proto2_DefaultValuesWritten()
        {
            var value = new ProtobufTestMessages.Proto2.TestAllTypesProto2() { FieldName13 = 0 };
            AssertWriteValue(value, "{ 'FieldName13': 0 }");
        }

        private static void AssertWriteValue(object value, string expectedJson, JsonFormatter.Settings settings = null)
        {
            var writer = new StringWriter { NewLine = "\n" };
            new JsonFormatter(settings ?? JsonFormatter.Settings.Default).WriteValue(writer, value);
            string actual = writer.ToString();
            AssertJson(expectedJson, actual);
        }

        /// <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, trimming leading whitespace and normalizing new lines.
        /// This basically makes the tests easier to read.
        /// </summary>
        /// <remarks>
        /// Line endings are normalized because indented JSON strings are generated with system-specific line endings,
        /// while line endings in the test cases are hard-coded, but may be converted during source checkout, depending
        /// on git settings, causing unpredictability in the test results otherwise.</remarks>
        private static void AssertJson(string expectedJsonWithApostrophes, string actualJson)
        {
            var expectedJson = expectedJsonWithApostrophes.Replace("'", "\"").Replace("\r\n", "\n").TrimStart();
            Assert.AreEqual(expectedJson, actualJson.Replace("\r\n", "\n"));
        }
    }
}
