public void GivenXmlWithDictionary_String_Object_ItDeserializesCorrectly() { var result = X2OReader.ReadFromFile <Dictionary <string, object> >("ContentData\\EndToEndTests\\Dictionary_String_Object.xml"); Assert.IsNotNull(result); Assert.IsNotNull(result["Item1"]); Assert.IsInstanceOfType(result["Item1"], typeof(SimpleClass)); Assert.AreEqual(10, (result["Item1"] as SimpleClass).X); Assert.IsNotNull(result["Item2"]); Assert.IsInstanceOfType(result["Item2"], typeof(ClassWithEnumerationOfInts)); var item2 = result["Item2"] as ClassWithEnumerationOfInts; Assert.AreEqual("Test text", item2.G); Assert.IsNotNull(item2.H); var enumerator = item2.H.GetEnumerator(); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual(20, enumerator.Current); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual(21, enumerator.Current); Assert.IsFalse(enumerator.MoveNext()); Assert.IsNotNull(result["Item3"]); Assert.IsInstanceOfType(result["Item3"], typeof(int)); Assert.AreEqual(30, result["Item3"]); }
public void GivenXmlWithSimpleClassWithoutTypeSpecification_ItDeserializesCorrectly() { var simple_class = X2OReader.ReadFromFile("ContentData\\EndToEndTests\\SimpleClassWithoutClassDefinition.xml") as SimpleClass; Assert.IsNotNull(simple_class, "SimpleClass has not desrialized"); Assert.AreEqual(5, simple_class.X, "SimpleClass.X should be 5"); }
public void GivenXmlWithClassWithAnotherClassAsMember_ItDeserializesCorrectly() { var simple_class = X2OReader.ReadFromFile("ContentData\\EndToEndTests\\SimpleClassWithMemberClass.xml") as SimpleClassWithMemberClass; Assert.IsNotNull(simple_class, "SimpleClassWithMemberClass has not desrialized"); Assert.AreEqual(10, simple_class.A, "SimpleClassWithMemberClass.A should be 10"); Assert.IsNotNull(simple_class.B, "SimpleClassWithMemberClass.B must not be null"); Assert.AreEqual(5, simple_class.B.X, "SimpleClassWithMemberClass.B.X should be 5"); }
public void GivenXmlWithDictionary_String_SimpleClass_ItDeserializesCorrectly() { var result = X2OReader.ReadFromFile <Dictionary <string, SimpleClass> >("ContentData\\EndToEndTests\\Dictionary_String_SimpleClass.xml"); Assert.IsNotNull(result); Assert.IsNotNull(result["ItemA"]); Assert.AreEqual(10, result["ItemA"].X); Assert.IsNotNull(result["ItemB"]); Assert.AreEqual(20, result["ItemB"].X); }
public void GivenXmlWithPartiallyExternalConfig_ItDeserializesCorrectly() { var result = X2OReader.ReadFromFile("ContentData\\EndToEndTests\\ClassWithPartiallyExternalConfig.xml") as SimpleClassWithMemberInterface; Assert.IsNotNull(result); Assert.AreEqual(7, result.C); Assert.IsNotNull(result.I); Assert.IsInstanceOfType(result.I, typeof(SimpleInterfaceImpl2)); Assert.AreEqual("Test text!", (result.I as SimpleInterfaceImpl2).D); Assert.AreEqual('x', (result.I as SimpleInterfaceImpl2).F); }
public void GivenXmlWithClassWithInterfaceAsMember_ItDeserializesCorrectly() { var simple_class = X2OReader.ReadFromFile("ContentData\\EndToEndTests\\SimpleClassWithInterfaceMember.xml") as SimpleClassWithMemberInterface; Assert.IsNotNull(simple_class, "SimpleClassWithMemberInterface has not desrialized"); Assert.AreEqual(7, simple_class.C, "SimpleClassWithMemberInterface.C should be 7"); Assert.IsNotNull(simple_class.I, "SimpleClassWithMemberInterface.I must not be null"); Assert.IsInstanceOfType(simple_class.I, typeof(SimpleInterfaceImpl2), "Suppossed the deserialized value to be of SimpleInterfaceImpl2 type"); Assert.AreEqual("Test text!", simple_class.I.D, "SimpleClassWithMemberInterface.I.D should be \"Test text!\""); Assert.AreEqual('x', (simple_class.I as SimpleInterfaceImpl2).F, "SimpleClassWithMemberInterface.I.F should be 'x'"); }
public void GivenXmlWithEnumerableOfObjects_UsingSimpleTypeNames_ItDeserializesCorrectly() { var result = X2OReader.ReadFromFile("ContentData\\EndToEndTests\\EnumerableOfObjects_UsingSimpleTypeNames.xml") as IEnumerable <object>; Assert.IsNotNull(result); var enumerator = result.GetEnumerator(); Assert.IsTrue(enumerator.MoveNext()); Assert.IsInstanceOfType(enumerator.Current, typeof(int)); var val1 = (int)enumerator.Current; Assert.AreEqual(15, val1); Assert.IsFalse(enumerator.MoveNext()); }
public void GivenXmlOfClassWithEnumerationOfInts_ItDesrializesCorrectly() { var result = X2OReader.ReadFromFile("ContentData\\EndToEndTests\\ClassWithEnumerationOfInts.xml") as ClassWithEnumerationOfInts; Assert.IsNotNull(result, "ClassWithEnumerationOfInts has not deserialized"); Assert.AreEqual("Test text!", result.G); Assert.IsNotNull(result.H, "ClassWithEnumerationOfInts.H should not be null"); var enumerator = result.H.GetEnumerator(); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual(10, enumerator.Current); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual(11, enumerator.Current); Assert.IsFalse(enumerator.MoveNext()); }
public void GivenXmlOfEnumerableOfInterface_ItDeserializesCorrectly() { var result = X2OReader.ReadFromFile <IEnumerable <SimpleInterface> >("ContentData\\EndToEndTests\\EnumerableOfInterfaces.xml"); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(IEnumerable <SimpleInterface>)); var enumerator = result.GetEnumerator(); Assert.IsTrue(enumerator.MoveNext()); Assert.IsInstanceOfType(enumerator.Current, typeof(SimpleInterfaceImpl1)); Assert.AreEqual("Test text 1", (enumerator.Current as SimpleInterfaceImpl1).D); Assert.AreEqual(15, (enumerator.Current as SimpleInterfaceImpl1).E); Assert.IsTrue(enumerator.MoveNext()); Assert.IsInstanceOfType(enumerator.Current, typeof(SimpleInterfaceImpl2)); Assert.AreEqual("Test text 2", (enumerator.Current as SimpleInterfaceImpl2).D); Assert.AreEqual('x', (enumerator.Current as SimpleInterfaceImpl2).F); Assert.IsFalse(enumerator.MoveNext()); }
/// <inheritdoc /> /// <remarks> /// The function looks for the fromFile attribute, and if found, and there are no children it uses the X2OReader to /// read this file and desrialize its content, which is then returned as the value of this element. /// </remarks> public object ProcessElements(XmlElement _parent_element, Type _target_type, X2OConfig _config) { var external_config_attr = _parent_element.Attributes["fromFile"]; if (external_config_attr != null && !_parent_element.HasChildNodes) { foreach (var possible_file in FindExistingFiles(external_config_attr.Value, _config)) { try { var result = X2OReader.ReadFromFile(possible_file, _config); if (result != null) { return(result); } } catch { } } } return(null); }
public void GivenXmlWithIntOnly_ItDeserializesCorrectly() { var i = (int)X2OReader.ReadFromFile("ContentData\\EndToEndTests\\OnlyInt.xml"); Assert.AreEqual(2, i); }