コード例 #1
0
        public void Basic(IJsonSerializerAdapter adapter)
        {
            var dictionary = adapter.Deserialize <IDictionary <string, object> >("{ \"key\": \"value\" }");

            Assert.NotNull(dictionary);
            Assert.Equal("value", dictionary.GetValueOrDefault("key"));
        }
コード例 #2
0
        public void Nested(IJsonSerializerAdapter adapter)
        {
            var dictionary = adapter.Deserialize <IDictionary <string, object> >("{ \"key\": { \"nested\": \"value\" } }");

            Assert.NotNull(dictionary);
            var nested = Assert.IsAssignableFrom <IDictionary <string, object> >(dictionary.GetValueOrDefault("key"));

            Assert.Equal("value", nested.GetValueOrDefault("nested"));
        }
コード例 #3
0
        // ReSharper disable once UnusedParameter.Local
        private void AssertCanBeRoundtripped <TPropertyType, TActualType>(IJsonSerializerAdapter adapter, TActualType value)
            where TActualType : TPropertyType, new()
        {
            var serialized = adapter.Serialize(new RootClassWithSingleReadOnlyProperty <TPropertyType, TActualType>(value));

            Debug.WriteLine("Serialized:\r\n" + serialized);
            var deserialized = adapter.Deserialize <RootClassWithSingleReadOnlyProperty <TPropertyType, TActualType> >(serialized);

            Assert.Equal(value, deserialized.Value);
        }
コード例 #4
0
        // ReSharper disable once UnusedParameter.Local
        private void AssertDeserializesTo <TCollection>(TCollection expected, string json, IJsonSerializerAdapter adapter)
            where TCollection : IEnumerable
        {
            var deserialized = adapter.Deserialize <TCollection>(json);

            Assert.Equal(
                expected.Cast <object>().ToArray(),
                deserialized.Cast <object>().ToArray()
                );
        }
コード例 #5
0
        // ReSharper disable once UnusedParameter.Local
        private void AssertCanBeRoundtripped <T>(IJsonSerializerAdapter adapter, T instance, Action <T> assertExtra = null)
        {
            var serialized = adapter.Serialize(instance);

            Debug.WriteLine("Serialized: " + serialized);
            var deserialized = adapter.Deserialize <T>(serialized);

            Assert.Equal(instance, deserialized);
            assertExtra?.Invoke(deserialized);
        }
コード例 #6
0
 // ReSharper disable once UnusedParameter.Local
 private void AssertDeserializesTo <T>(T expected, string json, IJsonSerializerAdapter adapter)
 {
     Assert.Equal(expected, adapter.Deserialize <T>(json));
 }
コード例 #7
0
 public static T Deserialize <T>(this IJsonSerializerAdapter adapter, string json)
 {
     return((T)adapter.Deserialize(typeof(T), json));
 }
コード例 #8
0
        public void CastToType(IJsonSerializerAdapter adapter)
        {
            var deserialized = adapter.Deserialize <dynamic>("{ \"Value\": \"test\" }");

            Assert.Equal("test", ((ClassWithSingleProperty <string>)deserialized).Value);
        }
コード例 #9
0
        public void PropertyAccess(IJsonSerializerAdapter adapter)
        {
            var deserialized = adapter.Deserialize <dynamic>("{ \"property\": \"value\" }");

            Assert.Equal("value", (string)deserialized.property);
        }
コード例 #10
0
        public void CastToString(IJsonSerializerAdapter adapter)
        {
            var deserialized = adapter.Deserialize <dynamic>("\"x\"");

            Assert.Equal("x", (string)deserialized);
        }
コード例 #11
0
        public void CastToInt32(IJsonSerializerAdapter adapter)
        {
            var deserialized = adapter.Deserialize <dynamic>("5");

            Assert.Equal(5, (int)deserialized);
        }