Skip to content

Commit

Permalink
[XML] Added unit test for multiple XMLElement attributes on arrays & …
Browse files Browse the repository at this point in the history
…ArrayLists
  • Loading branch information
alexischr committed Apr 8, 2014
1 parent 159c0b0 commit 94b5232
Showing 1 changed file with 63 additions and 0 deletions.
Expand Up @@ -2898,6 +2898,69 @@ public void XmlRootOverridesSchemaProviderQName ()
xs.Serialize (xw, obj);
Assert.IsTrue (sw.ToString ().IndexOf ("foo") > 0, "#1");
}

public class AnotherArrayListType
{
[XmlAttribute]
public string one = "aaa";
[XmlAttribute]
public string another = "bbb";
}

public class DerivedArrayListType : AnotherArrayListType
{

}

public class ClassWithArrayList
{
[XmlElement (Type = typeof(int), ElementName = "int_elem")]
[XmlElement (Type = typeof(string), ElementName = "string_elem")]
[XmlElement (Type = typeof(AnotherArrayListType), ElementName = "another_elem")]
[XmlElement (Type = typeof(DerivedArrayListType), ElementName = "derived_elem")]
public ArrayList list;
}

public class ClassWithArray
{
[XmlElement (Type = typeof(int), ElementName = "int_elem")]
[XmlElement (Type = typeof(string), ElementName = "string_elem")]
[XmlElement (Type = typeof(AnotherArrayListType), ElementName = "another_elem")]
[XmlElement (Type = typeof(DerivedArrayListType), ElementName = "derived_elem")]
public object[] list;

}

[Test]
public void MultipleXmlElementAttributesOnArrayList()
{
var test = new ClassWithArrayList();

test.list = new ArrayList();
test.list.Add(3);
test.list.Add("apepe");
test.list.Add(new AnotherArrayListType());
test.list.Add(new DerivedArrayListType());

Serialize(test);
var expected_text = "<:ClassWithArrayList http://www.w3.org/2000/xmlns/:xsd='http://www.w3.org/2001/XMLSchema' http://www.w3.org/2000/xmlns/:xsi='http://www.w3.org/2001/XMLSchema-instance'><:int_elem>3</><:string_elem>apepe</><:another_elem :another='bbb' :one='aaa'></><:derived_elem :another='bbb' :one='aaa'></></>";

Assert.AreEqual(WriterText, expected_text, WriterText);
}

[Test]
public void MultipleXmlElementAttributesOnArray()
{
var test = new ClassWithArray();

test.list = new object[] { 3, "apepe", new AnotherArrayListType(), new DerivedArrayListType() };

Serialize(test);
var expected_text = "<:ClassWithArray http://www.w3.org/2000/xmlns/:xsd='http://www.w3.org/2001/XMLSchema' http://www.w3.org/2000/xmlns/:xsi='http://www.w3.org/2001/XMLSchema-instance'><:int_elem>3</><:string_elem>apepe</><:another_elem :another='bbb' :one='aaa'></><:derived_elem :another='bbb' :one='aaa'></></>";

Assert.AreEqual(WriterText, expected_text, WriterText);
}

#endif

#endregion //GenericsSeralizationTests
Expand Down

0 comments on commit 94b5232

Please sign in to comment.