public void Basic(IJsonSerializerAdapter adapter) { var dictionary = adapter.Deserialize <IDictionary <string, object> >("{ \"key\": \"value\" }"); Assert.NotNull(dictionary); Assert.Equal("value", dictionary.GetValueOrDefault("key")); }
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")); }
// 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); }
// 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() ); }
// 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); }
// ReSharper disable once UnusedParameter.Local private void AssertDeserializesTo <T>(T expected, string json, IJsonSerializerAdapter adapter) { Assert.Equal(expected, adapter.Deserialize <T>(json)); }
public static T Deserialize <T>(this IJsonSerializerAdapter adapter, string json) { return((T)adapter.Deserialize(typeof(T), json)); }
public void CastToType(IJsonSerializerAdapter adapter) { var deserialized = adapter.Deserialize <dynamic>("{ \"Value\": \"test\" }"); Assert.Equal("test", ((ClassWithSingleProperty <string>)deserialized).Value); }
public void PropertyAccess(IJsonSerializerAdapter adapter) { var deserialized = adapter.Deserialize <dynamic>("{ \"property\": \"value\" }"); Assert.Equal("value", (string)deserialized.property); }
public void CastToString(IJsonSerializerAdapter adapter) { var deserialized = adapter.Deserialize <dynamic>("\"x\""); Assert.Equal("x", (string)deserialized); }
public void CastToInt32(IJsonSerializerAdapter adapter) { var deserialized = adapter.Deserialize <dynamic>("5"); Assert.Equal(5, (int)deserialized); }