public override void SetUp() { base.SetUp(); manager = new XmlDataManager(); XmlFile.DirectoryName = XmlDataManagerTest.testDir; ClearTestDirectory(); FileVersion.Clock = new TestClock(); oids = new SerialOid[SIZE]; data = new ObjectData[SIZE]; INakedObjectSpecification type = system.GetSpecification(typeof(object)); pattern = new ObjectData(type, null, new FileVersion("user", 13)); for (int i = 0; i < SIZE; i++) { oids[i] = SerialOid.CreatePersistent(i, typeof(object).FullName); data[i] = new ObjectData(type, oids[i], new FileVersion("user", 13)); manager.InsertObject(data[i]); } }
private static ObjectData CreateData(Type type, long id, IVersion version) { INakedObjectSpecification specification = NakedObjectsContext.Reflector.LoadSpecification(type.FullName); SerialOid oid = SerialOid.CreatePersistent(id, type.FullName); return(new ObjectData(specification, oid, version)); }
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 LoadServices() { services = new List <ServiceElement>(); FileInfo file = XmlFile.GetFile(SERVICES_FILE_NAME); if (file.Exists) { XDocument doc = XDocument.Load(file.FullName); foreach (XElement element in doc.Element("services").Elements("service")) { string sOid = (from attrib in element.Attributes() where attrib.Name == "oid" select attrib.Value).Single(); long oid = Convert.ToInt64(sOid, 16); string id = (from attrib in element.Attributes() where attrib.Name == "id" select attrib.Value).Single(); string type = (from attrib in element.Attributes() where attrib.Name == "type" select attrib.Value).SingleOrDefault(); type = type ?? id; var service = new ServiceElement(SerialOid.CreatePersistent(oid, type), id); services.Add(service); } } }
public ServiceElement(SerialOid oid, string id) { Assert.AssertNotNull("oid", oid); Assert.AssertNotNull("id", id); this.oid = oid; this.id = id; typeName = oid.Specification.FullName; oid.Specification.MarkAsService(); }
private static IQueryable <IOid> LoadInstances(string type) { FileInfo typeFile = XmlFile.GetFile(type); if (typeFile.Exists) { return((from instance in XDocument.Load(typeFile.FullName).Element("instances").Elements("instance") let sOid = (string)instance.Attribute("id") select SerialOid.CreatePersistent(Convert.ToInt64(sOid, 16), type)).Cast <IOid>().AsQueryable()); } return(new List <IOid>().AsQueryable()); }
public virtual void TestCreateOid() { SerialOid oid = manager.CreateOid(typeof(object).FullName) as SerialOid; long last = oid.SerialNo; for (int i = 0; i < 3; i++) { oid = manager.CreateOid(typeof(object).FullName) as SerialOid; Assert.AreNotEqual(last, oid.SerialNo); last = oid.SerialNo; } }
public virtual void TestSaveObject() { data[2].SetField("Person", SerialOid.CreatePersistent(231, typeof(Person).FullName)); data[2].SetField("Name", "Fred"); manager.Save(data[2]); Assert.IsTrue(Enumerable.Contains(manager.GetInstances(system.GetSpecification(typeof(object))), data[2])); ObjectData read = manager.LoadObjectData(oids[2]); Assert.AreEqual(data[2], read); Assert.AreEqual(data[2].Value("Name"), read.Value("Name")); Assert.AreEqual(data[2].GetField("Person"), read.GetField("Person")); }
public virtual IOid GetOidForService(string name, string typeName) { foreach (ServiceElement element in services) { if (element.Id.Equals(name)) { return(element.Oid); } } SerialOid oid = SerialOid.CreatePersistent(services.Count(), typeName); RegisterService(name, oid); return(oid); }
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 object GetDomainObjectByOid(string oid) { long idAsLong; if (!long.TryParse(oid, out idAsLong)) { // check if it's a service NakedObject service = GetServiceByServiceNameInternal(oid); if (service == null) { throw new BadRequestNOSException(); } return service.getObject(); } var serialOid = new SerialOid(idAsLong); NakedObject adapter = [email protected]().getAdapterFor(serialOid); return adapter.getObject(); }
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")); }
private static IOid GetOid(XElement node, string typeName) { string[] values = node.Attribute("id").Value.Split(':'); if (values.Count() <= 0 || values.Count() > 2) { return(null); } long id = Convert.ToInt64(values[0], 16); IOid oid = SerialOid.CreatePersistent(id, typeName); if (values.Count() == 2) { oid = new AggregateOid(oid, values[1], typeName); } return(oid); }
public object GetDomainObjectByOid(string oid) { long idAsLong; if (!long.TryParse(oid, out idAsLong)) { // check if it's a service NakedObject service = GetServiceByServiceNameInternal(oid); if (service == null) { throw new BadRequestNOSException(); } return(service.getObject()); } var serialOid = new SerialOid(idAsLong); NakedObject adapter = [email protected]().getAdapterFor(serialOid); return(adapter.getObject()); }
// TODO the following methods are being called repeatedly - is there no caching? See the print statements public IOid CreateOid(string typeName) { return(SerialOid.CreatePersistent(NextId(), typeName)); }
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"); } } }
private static string EncodedOid(SerialOid oid) { return(oid.SerialNo.ToString("x").ToUpper()); }