public void FromJson_CorrectJsonClass()
        {
            //arrange
            var json      = "{}";
            var jsonClass = new OptionalPropertyClass()
            {
                OptionalBool   = true,
                OptionalInt    = 42,
                OptionalArray  = new int[] { 42 },
                OptionalChar   = '4',
                OptionalMyType = new MyType {
                    Name = "Bob"
                },
                OptionalMyType2 = new MyType2 {
                    Name = "Bob"
                },
                OptionalDateTime               = DateTime.MaxValue,
                OptionalDateTimeOffset         = DateTimeOffset.MaxValue,
                OptionalDictionary             = new Dictionary <string, int>(),
                OptionalGuid                   = new Guid(),
                OptionalList                   = new List <int>(),
                OptionalNullableInt            = 42,
                OptionalNullableBoolean        = true,
                OptionalNullableDateTime       = DateTime.MaxValue,
                OptionalNullableDateTimeOffset = DateTimeOffset.MaxValue,
                OptionalNullableGuid           = new Guid(),
                OptionalString                 = "string"
            };

            //act
            _convert.FromJson(jsonClass, json);

            //assert
            Assert.That(jsonClass.OptionalBool, Is.EqualTo(default(bool)));
            Assert.That(jsonClass.OptionalInt, Is.EqualTo(default(int)));
            Assert.That(jsonClass.OptionalArray, Is.Null);
            Assert.That(jsonClass.OptionalChar, Is.EqualTo(default(char)));
            Assert.That(jsonClass.OptionalMyType, Is.EqualTo(default(MyType)));
            Assert.That(jsonClass.OptionalMyType2, Is.EqualTo(default(MyType2)));
            Assert.That(jsonClass.OptionalDateTime, Is.EqualTo(default(DateTime)));
            Assert.That(jsonClass.OptionalDateTimeOffset, Is.EqualTo(default(DateTimeOffset)));
            Assert.That(jsonClass.OptionalDictionary, Is.EqualTo(default(Dictionary <string, int>)));
            Assert.That(jsonClass.OptionalGuid, Is.EqualTo(default(Guid)));
            Assert.That(jsonClass.OptionalList, Is.EqualTo(default(List <int>)));
            Assert.That(jsonClass.OptionalNullableInt, Is.EqualTo(default(int?)));
            Assert.That(jsonClass.OptionalNullableBoolean, Is.EqualTo(default(bool?)));
            Assert.That(jsonClass.OptionalNullableDateTime, Is.EqualTo(default(DateTime?)));
            Assert.That(jsonClass.OptionalNullableDateTimeOffset, Is.EqualTo(default(DateTimeOffset?)));
            Assert.That(jsonClass.OptionalNullableGuid, Is.EqualTo(default(Guid?)));
            Assert.That(jsonClass.OptionalString, Is.EqualTo(default(string)));
        }
Esempio n. 2
0
 protected override ReadOnlySpan <char> FromJson(OptionalPropertyClass value, string json)
 {
     return(Encoding.UTF8.GetString(_convert.FromJson(value, Encoding.UTF8.GetBytes(json))));
 }
Esempio n. 3
0
 protected abstract ReadOnlySpan <char> FromJson(OptionalPropertyClass value, string json);
Esempio n. 4
0
 protected override ReadOnlySpan <char> FromJson(OptionalPropertyClass value, string json)
 {
     return(_convert.FromJson(value, json));
 }