public void AbstractAndInterfaceProps_Successful() { var serializer = new JsonSerializer(); var obj = new ObjectWithAbstractAndInterfaceProps { AbstractProp = new DerivedClass { SomeProp = 42 }, InterfaceProp = new ImplementationClass { RequiredProp = "test comparable" } }; JsonValue expected = new JsonObject { { "AbstractProp", new JsonObject { { "#Type", typeof(DerivedClass).AssemblyQualifiedName }, { "SomeProp", 42 } } }, { "InterfaceProp", new JsonObject { { "#Type", typeof(ImplementationClass).AssemblyQualifiedName }, { "RequiredProp", "test comparable" } } } }; var actual = serializer.Serialize(obj); Assert.AreEqual(expected, actual); }
public void AbstractAndInterfacePropsWithMap_Successful() { var serializer = new JsonSerializer(); var json = new JsonObject { { "AbstractProp", new JsonObject { { "SomeProp", 42 } } }, { "InterfaceProp", new JsonObject { { "RequiredProp", "test" } } } }; var expected = new ObjectWithAbstractAndInterfaceProps { AbstractProp = new DerivedClass { SomeProp = 42 }, InterfaceProp = new ImplementationClass { RequiredProp = "test" } }; serializer.AbstractionMap.Map <AbstractClass, DerivedClass>(); serializer.AbstractionMap.Map <IInterface, ImplementationClass>(); var actual = serializer.Deserialize <ObjectWithAbstractAndInterfaceProps>(json); Assert.AreEqual(expected, actual); }
public void AbstractAndInterfacePropsWithoutMap_Successful() { var serializer = new JsonSerializer(); var json = new JsonObject { { "AbstractProp", new JsonObject { { "$type", typeof(DerivedClass).AssemblyQualifiedName }, { "SomeProp", 42 } } }, { "InterfaceProp", new JsonObject { { "$type", typeof(ImplementationClass).AssemblyQualifiedName }, { "RequiredProp", "test" } } } }; var expected = new ObjectWithAbstractAndInterfaceProps { AbstractProp = new DerivedClass { SomeProp = 42 }, InterfaceProp = new ImplementationClass { RequiredProp = "test" } }; var actual = serializer.Deserialize <ObjectWithAbstractAndInterfaceProps>(json); Assert.AreEqual(expected, actual); }
public bool Equals(ObjectWithAbstractAndInterfaceProps other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Equals(other.InterfaceProp, InterfaceProp) && Equals(other.AbstractProp, AbstractProp)); }