public void TestArrayClone() { // If an array is cloned with a new name, the 1st element in the array needs // to have its name updated as well string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Peach>\n" + " <DataModel name=\"TheDataModel\">"+ " <Blob name=\"Data\" value=\"Hello World\" minOccurs=\"100\"/>"+ " </DataModel>"+ "</Peach>"; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); Dom.Array array = dom.dataModels[0][0] as Dom.Array; Assert.NotNull(array); Assert.AreEqual(100, array.Count); Assert.AreEqual("Data", array.name); Assert.AreEqual("Data", array[0].name); var clone = array.Clone("NewData") as Dom.Array; Assert.NotNull(clone); Assert.AreEqual(100, clone.Count); Assert.AreEqual("NewData", clone.name); Assert.AreEqual("NewData", clone[0].name); }
public void TestArrayRelationClone() { // If an array is cloned wih a new name, and the array element contains a relation, // the relation's Of or From names need to be updated string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Peach>\n" + " <DataModel name=\"TheDataModel\">"+ " <Blob name=\"Data\" value=\"Hello World\"/>"+ " <Number name=\"Length\" size=\"32\" minOccurs=\"100\">"+ " <Relation type=\"size\" of=\"Data\" />"+ " </Number>"+ " </DataModel>"+ "</Peach>"; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); Dom.Array array = dom.dataModels[0][1] as Dom.Array; Assert.NotNull(array); Assert.AreEqual("Length", array.name); Assert.AreEqual(100, array.Count); Assert.AreEqual("Length", array[0].name); Assert.AreEqual(0, array.relations.Count); Assert.AreEqual(1, array[0].relations.Count); Assert.AreEqual(100, array[0].relations[0].Of.relations.Count); Dom.Array clone = array.Clone("NewLength") as Dom.Array; Assert.NotNull(clone); Assert.AreEqual("NewLength", clone.name); Assert.AreEqual(100, clone.Count); Assert.AreEqual("NewLength", clone[0].name); Assert.AreEqual(0, clone.relations.Count); Assert.AreEqual(1, clone[0].relations.Count); Assert.AreEqual("Data", clone[0].relations[0].OfName); Assert.AreEqual("NewLength", clone[0].relations[0].FromName); Assert.AreEqual(200, clone[0].relations[0].Of.relations.Count); Assert.True(clone[0].relations[0].Of.relations.Contains(clone[0].relations[0])); }