Ejemplo n.º 1
0
        public void Should_Convert_To_PascalCase_Json_With_Altered_Serialization_Settings()
        {
            var transcoder = new LegacyTranscoder(
                new DefaultSerializer(
                    new JsonSerializerSettings(),
                    new JsonSerializerSettings
            {
                ContractResolver = new DefaultContractResolver()
            }));

            var data = new Pascal
            {
                SomeProperty    = "SOME",
                SomeIntProperty = 12345,
                HasPascalCase   = true
            };
            var expectedJsonBytes = Encoding.UTF8.GetBytes("{\"SomeProperty\":\"SOME\",\"SomeIntProperty\":12345,\"HasPascalCase\":true}");

            using (var jsonBytes = new MemoryStream())
                using (var jsonEncoded = new MemoryStream())
                {
                    transcoder.SerializeAsJson(jsonBytes, data);
                    transcoder.Encode(jsonEncoded, data, TypeCode.Object, OpCode.Get);

                    Assert.Equal(expectedJsonBytes, jsonBytes.ToArray());
                    Assert.Equal(expectedJsonBytes, jsonEncoded.ToArray());
                }
        }
Ejemplo n.º 2
0
        public void Should_Convert_To_CamelCase_Json_With_Default_Serialization_Settings()
        {
            var transcoder = new DefaultTranscoder(new DefaultConverter());
            var data       = new Pascal
            {
                SomeProperty    = "SOME",
                SomeIntProperty = 12345,
                HasPascalCase   = true
            };
            var expectedJsonBytes = Encoding.UTF8.GetBytes("{\"someProperty\":\"SOME\",\"someIntProperty\":12345,\"hasPascalCase\":true}");
            var actualJsonBytes   = transcoder.SerializeAsJson(data);
            var actualJsonEncoded = transcoder.Encode(data, new Flags {
                DataFormat = DataFormat.Json
            }, OpCode.Get);

            Assert.Equal(expectedJsonBytes, actualJsonBytes);
            Assert.Equal(expectedJsonBytes, actualJsonEncoded);
        }
Ejemplo n.º 3
0
        public void Should_Convert_To_CamelCase_Json_With_Default_Serialization_Settings()
        {
            var transcoder = new LegacyTranscoder();
            var data       = new Pascal
            {
                SomeProperty    = "SOME",
                SomeIntProperty = 12345,
                HasPascalCase   = true
            };
            var expectedJsonBytes = Encoding.UTF8.GetBytes("{\"someProperty\":\"SOME\",\"someIntProperty\":12345,\"hasPascalCase\":true}");

            using (var jsonBytes = new MemoryStream())
                using (var jsonEncoded = new MemoryStream())
                {
                    transcoder.SerializeAsJson(jsonBytes, data);
                    transcoder.Encode(jsonEncoded, data, new Flags {
                        DataFormat = DataFormat.Json
                    }, OpCode.Get);
                    Assert.Equal(expectedJsonBytes, jsonBytes.ToArray());
                    Assert.Equal(expectedJsonBytes, jsonEncoded.ToArray());
                }
        }
Ejemplo n.º 4
0
        public void Should_Convert_To_PascalCase_Json_With_Altered_Serialization_Settings()
        {
            var transcoder = new DefaultTranscoder(
                new DefaultConverter(),
                new DefaultSerializer(
                    new JsonSerializerSettings(),
                    new JsonSerializerSettings
            {
                ContractResolver = new DefaultContractResolver()
            }));

            var data = new Pascal
            {
                SomeProperty    = "SOME",
                SomeIntProperty = 12345,
                HasPascalCase   = true
            };
            var expectedJsonBytes = Encoding.UTF8.GetBytes("{\"SomeProperty\":\"SOME\",\"SomeIntProperty\":12345,\"HasPascalCase\":true}");
            var actualJsonBytes   = transcoder.SerializeAsJson(data);
            var actualJsonEncoded = transcoder.Encode(data, TypeCode.Object, OpCode.Get);

            Assert.Equal(expectedJsonBytes, actualJsonBytes);
            Assert.Equal(expectedJsonBytes, actualJsonEncoded);
        }