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);
            }
        }
Esempio n. 2
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);
            }
        }