Beispiel #1
0
        public void TestReadDefault()
        {
            const string actual = @"{""UrisAreNullable"":null}";

            JsonSerializerOptions options       = new JsonSerializerOptions();
            ClassWithUri          objectWithUri = JsonSerializer.Deserialize <ClassWithUri>(actual, options);

            Assert.NotNull(objectWithUri);
            Assert.Null(objectWithUri.UrisAreNullable);
        }
Beispiel #2
0
        public void TestWriteDefault()
        {
            ClassWithUri objectWithUri = new ClassWithUri
            {
                UrisAreNullable = null,
            };

            const string expectedJson = @"{""UrisAreNullable"":null}";

            JsonSerializerOptions options = new JsonSerializerOptions();
            string actualJson             = JsonSerializer.Serialize(objectWithUri, options);

            Assert.Equal(expectedJson, actualJson);
        }
Beispiel #3
0
        public void When_uri_is_absolute_then_it_is_serialized_and_deserialized_correctly()
        {
            //// Arrange
            var obj = new ClassWithUri {
                MyUri = new Uri("https://abc/def", UriKind.Absolute)
            };

            //// Act
            var json = JsonConvert.SerializeObject(obj);
            var obj2 = JsonConvert.DeserializeObject <ClassWithUri>(json);

            //// Assert
            Assert.Equal("{\"MyUri\":\"https://abc/def\"}", json);
            Assert.Equal(obj.MyUri, obj2.MyUri);
        }