Example #1
0
        public void Write_Dictionary_ShouldThrowJsonException()
        {
            var options   = new JsonSerializerOptions();
            var converter = new ObjectConverter();

            MemoryStream memoryStream;

            using (memoryStream = new MemoryStream())
                using (var writer = new Utf8JsonWriter(memoryStream))
                {
                    Assert.Throws <JsonException>(() => converter.Write(writer, new Dictionary <string, object>(), options));
                }
        }
Example #2
0
        public void Write_Null_ShouldThrowJsonException()
        {
            var options   = new JsonSerializerOptions();
            var converter = new ObjectConverter();

            MemoryStream memoryStream;

            using (memoryStream = new MemoryStream())
                using (var writer = new Utf8JsonWriter(memoryStream))
                {
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
                    Assert.Throws <JsonException>(() => converter.Write(writer, null, options));
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
                }
        }
Example #3
0
        public void Write_Object_ShouldReturnNewObject()
        {
            var options   = new JsonSerializerOptions();
            var converter = new ObjectConverter();

            MemoryStream memoryStream;

            using (memoryStream = new MemoryStream())
                using (var writer = new Utf8JsonWriter(memoryStream))
                {
                    converter.Write(writer, new object(), options);
                }
            var actual = Encoding.UTF8.GetString(memoryStream.ToArray());

            Assert.Equal("{}", actual);
        }