public void CustomConstructorWithNull() { CustomConstructorTestClass a = new CustomConstructorTestClass(null, NanoState.Serialize, 666); XmlDocument target = new XmlDocument(); Serializer.Serialize((SystemXmlAdapter)target, a); Assert.AreEqual(1, target.DocumentElement.ChildNodes.Count); Assert.AreEqual("666", GetXmlValue(target, "A")); Assert.AreEqual("Serialize", target.DocumentElement.GetAttribute("C")); CustomConstructorTestClass b = Deserializer.Deserialize <CustomConstructorTestClass>((SystemXmlAdapter)target); Assert.AreEqual(a.A, b.A); Assert.AreEqual(a.B, b.B); Assert.AreEqual(a.C, b.C); }
public void CrossReference() { CustomConstructorTestClass obj = new CustomConstructorTestClass("testString", NanoState.Serialize, 333); PolymorphismTestClass a = new PolymorphismTestClass { A = obj, B = obj, }; XmlDocument target = new XmlDocument(); Serializer.Serialize((SystemXmlAdapter)target, a); Assert.AreEqual(3, target.DocumentElement.ChildNodes.Count); XmlElement aEl = GetElement(target, "A"); Assert.NotNull(aEl); Assert.AreEqual(1, aEl.ChildNodes.Count); Assert.AreEqual(3, aEl.Attributes.Count); Assert.AreEqual("333", GetXmlValue(aEl, "A")); Assert.AreEqual("testString", aEl.GetAttribute("B")); Assert.AreEqual("Serialize", aEl.GetAttribute("C")); XmlElement bEl = GetElement(target, "B"); Assert.NotNull(bEl); Assert.AreEqual(0, bEl.ChildNodes.Count); Assert.AreEqual(1, bEl.Attributes.Count); Assert.AreEqual("2", bEl.GetAttribute(SerializationBase.ATTRIBUTE_OBJID)); PolymorphismTestClass b = Deserializer.Deserialize <PolymorphismTestClass>((SystemXmlAdapter)target); Assert.AreEqual(((CustomConstructorTestClass)a.A).A, ((CustomConstructorTestClass)b.A).A); Assert.AreEqual(((CustomConstructorTestClass)a.A).B, ((CustomConstructorTestClass)b.A).B); Assert.AreEqual(((CustomConstructorTestClass)a.A).C, ((CustomConstructorTestClass)b.A).C); Assert.AreEqual(b.A, b.B); }
public void CrossReference() { CustomConstructorTestClass obj = new CustomConstructorTestClass("testString", NanoState.Serialize, 333); PolymorphismTestClass a = new PolymorphismTestClass { A = obj, B = obj, }; JObject target = new JObject(); Serializer.Serialize((NewtonsoftJsonAdapter)target, a); AssertChildren(3, target); JObject aEl = (JObject)target["A"]; Assert.NotNull(aEl); AssertChildren(4, aEl); AssertChild("333", "A", aEl); AssertAttribute("testString", "B", aEl); AssertAttribute("Serialize", "C", aEl); JObject bEl = (JObject)target["B"]; Assert.NotNull(bEl); AssertChildren(1, aEl); AssertAttribute("2", SerializationBase.ATTRIBUTE_OBJID, bEl); PolymorphismTestClass b = Deserializer.Deserialize <PolymorphismTestClass>((NewtonsoftJsonAdapter)target); Assert.AreEqual(((CustomConstructorTestClass)a.A).A, ((CustomConstructorTestClass)b.A).A); Assert.AreEqual(((CustomConstructorTestClass)a.A).B, ((CustomConstructorTestClass)b.A).B); Assert.AreEqual(((CustomConstructorTestClass)a.A).C, ((CustomConstructorTestClass)b.A).C); Assert.AreEqual(b.A, b.B); }