コード例 #1
0
        private static void VerifyWriter <T>(JsonSerializationFormat jsonSerializationFormat, T expectedDeserializedValue)
        {
            using (CosmosDBToNewtonsoftWriter writer = new CosmosDBToNewtonsoftWriter(jsonSerializationFormat))
            {
                Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer();
                serializer.Serialize(writer, expectedDeserializedValue);

                ReadOnlyMemory <byte> result = writer.GetResult();
                string actualSerializedValue;
                if (jsonSerializationFormat == JsonSerializationFormat.Binary)
                {
                    actualSerializedValue = JsonTestUtils.ConvertBinaryToText(result);
                }
                else
                {
                    actualSerializedValue = Utf8Span.UnsafeFromUtf8BytesNoValidation(result.Span).ToString();
                }

                actualSerializedValue = NewtonsoftInteropTests.NewtonsoftFormat(actualSerializedValue);
                string expectedSerializedValue = NewtonsoftInteropTests.NewtonsoftFormat(
                    JsonConvert.SerializeObject(
                        expectedDeserializedValue));
                Assert.AreEqual(expectedSerializedValue, actualSerializedValue);
            }
        }
コード例 #2
0
        public void Newtonsoft_Serializer_Binary()
        {
            Newtonsoft.Json.JsonSerializer jsonSerializer = Newtonsoft.Json.JsonSerializer.CreateDefault();
            CosmosDBToNewtonsoftWriter     writer         = new CosmosDBToNewtonsoftWriter(JsonSerializationFormat.Binary);

            jsonSerializer.Serialize(writer, this.people);
        }
コード例 #3
0
        private static void VerifyWriter <T>(JsonSerializationFormat jsonSerializationFormat, T expectedDeserializedValue)
        {
            using (CosmosDBToNewtonsoftWriter writer = new CosmosDBToNewtonsoftWriter(jsonSerializationFormat))
            {
                JsonSerializer serializer = new JsonSerializer();
                serializer.Serialize(writer, expectedDeserializedValue);

                byte[] result = writer.GetResult();
                string actualSerializedValue;
                if (jsonSerializationFormat == JsonSerializationFormat.Binary)
                {
                    actualSerializedValue = JsonTestUtils.ConvertBinaryToText(result);
                }
                else
                {
                    actualSerializedValue = Encoding.UTF8.GetString(result);
                }

                actualSerializedValue = NewtonsoftInteropTests.NewtonsoftFormat(actualSerializedValue);
                string expectedSerializedValue = NewtonsoftInteropTests.NewtonsoftFormat(JsonConvert.SerializeObject(expectedDeserializedValue));
                Assert.AreEqual(expectedSerializedValue, actualSerializedValue);
            }
        }