Example #1
0
        public virtual void TestInsertObjectWithFields()
        {
            ObjectData data = CreateData(typeof(Role), 99, new FileVersion("user", 13));

            data.SetField("Person", SerialOid.CreatePersistent(101, typeof(Person).FullName));
            Assert.IsNotNull(data.GetField("Person"));
            data.SetField("Name", "Harry");
            Assert.IsNotNull(data.Value("Name"));

            manager.InsertObject(data);

            ObjectData read = manager.LoadObjectData(data.Oid);

            Assert.AreEqual(data.Oid, read.Oid);
            Assert.AreEqual(data.ClassName, read.ClassName);

            Assert.AreEqual(data.GetField("Person"), read.GetField("Person"));
            Assert.AreEqual(data.Value("Name"), read.Value("Name"));
        }
        public virtual void TestValueField() {
            FileVersion.Clock = new TestClock();

            TestProxySpecification type = new TestProxySpecification(typeof (string));
            ObjectData objectData = new ObjectData(type, SerialOid.CreatePersistent(13, typeof(string).FullName), new FileVersion(""));

            Assert.AreEqual(null, objectData.Value("name"));
            objectData.SetField("name", "value");
            Assert.AreEqual("value", objectData.Value("name"));

            IEnumerator<string> e = objectData.Fields();
            Assert.IsTrue(e.MoveNext());
            Assert.IsNotNull(e.Current);
            Assert.IsFalse(e.MoveNext());
        }
        public virtual void TestValueField()
        {
            FileVersion.Clock = new TestClock();

            TestProxySpecification type       = new TestProxySpecification(typeof(string));
            ObjectData             objectData = new ObjectData(type, SerialOid.CreatePersistent(13, typeof(string).FullName), new FileVersion(""));

            Assert.AreEqual(null, objectData.Value("name"));
            objectData.SetField("name", "value");
            Assert.AreEqual("value", objectData.Value("name"));

            IEnumerator <string> e = objectData.Fields();

            Assert.IsTrue(e.MoveNext());
            Assert.IsNotNull(e.Current);
            Assert.IsFalse(e.MoveNext());
        }
        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");
                }
            }
        }
        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");
                }
            }
        }