public virtual void TestInsertObjectWithOneToManyAssociations() { ObjectData data = CreateData(typeof(Team), 99, new FileVersion("user", 13)); data.InitCollection("Members"); SerialOid[] oid = new SerialOid[3]; for (int i = 0; i < oid.Length; i++) { oid[i] = SerialOid.CreatePersistent(104 + i, typeof(Team).FullName); data.AddElement("Members", oid[i]); } manager.InsertObject(data); ObjectData read = manager.LoadObjectData(data.Oid); Assert.AreEqual(data.Oid, read.Oid); Assert.AreEqual(data.ClassName, read.ClassName); IList <IOid> c = read.Elements("Members"); for (int i = 0; i < oid.Length; i++) { Assert.AreEqual(oid[i], c[i]); } }
public virtual void TestInsertObjectWithEmptyOneToManyAssociations() { ObjectData data = CreateData(typeof(Team), 99, new FileVersion("user", 13)); data.InitCollection("Members"); manager.InsertObject(data); ObjectData read = manager.LoadObjectData(data.Oid); Assert.AreEqual(data.Oid, read.Oid); Assert.AreEqual(data.ClassName, read.ClassName); IList <IOid> c = read.Elements("Members"); Assert.IsNull(c); }
public void LoadNode(XElement Node, ref CollectionData collection, ref ObjectData objectData, ref string fieldName) { string tag = Node.Name.LocalName; if (objectData != null) { if (tag.Equals("value")) { fieldName = Node.Attribute("field").Value; objectData.SetField(fieldName, Node.Value); } else if (tag.Equals("inline")) { CollectionData sinkCollection = null; ObjectData inlineObjectData = null; string sinkName = ""; fieldName = Node.Attribute("field").Value; LoadNode(Node.Element("naked-object"), ref sinkCollection, ref inlineObjectData, ref sinkName); objectData.SetField(fieldName, inlineObjectData); } else if (tag.Equals("association")) { fieldName = Node.Attribute("field").Value; long id = Convert.ToInt64(Node.Attribute("ref").Value, 16); objectData.SetField(fieldName, SerialOid.CreatePersistent(id, Node.Attribute("Type").Value)); } else if (tag.Equals("element")) { long id = Convert.ToInt64(Node.Attribute("ref").Value, 16); objectData.AddElement(fieldName, SerialOid.CreatePersistent(id, Node.Attribute("Type").Value)); } else if (tag.Equals("multiple-association")) { fieldName = Node.Attribute("field").Value; objectData.InitCollection(fieldName); } } else if (collection != null) { if (tag.Equals("element")) { long id = Convert.ToInt64(Node.Attribute("ref").Value, 16); collection.AddElement(SerialOid.CreatePersistent(id, Node.Attribute("Type").Value)); } } else { if (tag.Equals("naked-object")) { string type = Node.Attribute("Type").Value; string user = Node.Attribute("user").Value; IVersion version = GetVersion(Node, user); IOid oid = GetOid(Node, type); INakedObjectSpecification spec = NakedObjectsContext.Reflector.LoadSpecification(type); objectData = new ObjectData(spec, oid, version); } else if (tag.Equals("collection")) { string type = Node.Attribute("Type").Value; long version = Convert.ToInt64(Node.Attribute("ver").Value, 16); string user = Node.Attribute("user").Value; long id = Convert.ToInt64(Node.Attribute("id").Value, 16); INakedObjectSpecification spec = NakedObjectsContext.Reflector.LoadSpecification(type); IOid oid = SerialOid.CreatePersistent(id, type); collection = new CollectionData(spec, oid, new FileVersion(user, version)); } else { throw new XmlException("Invalid data"); } } }