Exemplo n.º 1
0
        public void CompleteTurnaroundWithAddedObject(Type formatterType)
        {
            // Create object and serialize it
            IFormatter formatter = (IFormatter)Activator.CreateInstance(formatterType);

            var m = CreateMitarbeiter();

            pm.MakePersistent(m);
            pm.Save();
            var oc = pm.GetObjectContainer();

            oc.Formatter = formatter;
            string serialized = oc.MarshalingString;

            pm.UnloadCache();

            // Merge object into an OfflinePersistenceManager and change it
            OfflinePersistenceManager opm = new OfflinePersistenceManager(pm.NDOMapping.FileName);

            oc = new ObjectContainer();
            oc.Deserialize(serialized, formatter);

            opm.MergeObjectContainer(oc);

            var m2 = new Mitarbeiter()
            {
                Vorname = "Hans", Nachname = "Müller"
            };

            opm.MakePersistent(m2);

            // Create a ChangeSetContainer and serialize it
            var csc = opm.GetChangeSet();

            csc.Formatter = formatter;
            string serializedChanges = csc.MarshalingString;

            // Merge the changes back to pm
            csc = new ChangeSetContainer();
            csc.Deserialize(serializedChanges, formatter);

            Assert.That(csc.AddedObjects.Count == 1);

            pm = new PersistenceManager();              // we need a new pm here which get's us id's beginning from -1
            pm.MergeObjectContainer(csc);
            // Now we should have a created object in the cache
            Assert.AreEqual(true, pm.HasChanges);
            m = (Mitarbeiter)pm.FindObject(typeof(Mitarbeiter), -1);
            Assert.That(m.NDOObjectState == NDOObjectState.Created);

            // Save and Reload
            pm.Save();
            Assert.That(m.NDOObjectState == NDOObjectState.Persistent);
            pm.UnloadCache();
            var l = pm.Objects <Mitarbeiter>().ResultTable;

            Assert.AreEqual(2, l.Count);
            Assert.That(l.Any(m1 => m1.Vorname == "Mirko" && m1.Nachname == "Matytschak"));
            Assert.That(l.Any(m1 => m1.Vorname == "Hans" && m1.Nachname == "Müller"));
        }
Exemplo n.º 2
0
        public void ChangeRelationWithExistingObject(Type formatterType)
        {
            // Create object and serialize it
            IFormatter formatter = (IFormatter)Activator.CreateInstance(formatterType);

            var r = new Reise {
                Zweck = "NDO"
            };

            pm.MakePersistent(r);
            var l = new Land("Germany");

            pm.MakePersistent(l);
            pm.Save();
            var oc = pm.GetObjectContainer();

            oc.Formatter = formatter;
            string serialized = oc.MarshalingString;

            pm.UnloadCache();

            // Merge object in to an OfflinePersistenceManager and change it
            OfflinePersistenceManager opm = new OfflinePersistenceManager(pm.NDOMapping.FileName);

            oc = new ObjectContainer();
            oc.Deserialize(serialized, formatter);

            opm.MergeObjectContainer(oc);

            var newOc = oc.RootObjects.Cast <IPersistenceCapable>();
            var r2    = (Reise)newOc.FirstOrDefault(pc => pc is Reise);
            var l2    = (Land)newOc.FirstOrDefault(pc => pc is Land);;

            Assert.AreEqual(NDOObjectState.Persistent, r2.NDOObjectState);
            Assert.AreEqual(NDOObjectState.Persistent, l2.NDOObjectState);
            r2.LandHinzufügen(l2);
            Assert.AreEqual(NDOObjectState.PersistentDirty, r2.NDOObjectState);

            // Create a ChangeSetContainer and serialize it
            var csc = opm.GetChangeSet();

            csc.Formatter = formatter;
            string serializedChanges = csc.MarshalingString;

            // Merge the changes back to pm
            csc = new ChangeSetContainer();
            csc.Deserialize(serializedChanges, formatter);
            r = (Reise)csc.ChangedObjects.Cast <IPersistenceCapable>().FirstOrDefault(pc => pc is Reise);
            pm.MergeObjectContainer(csc);
            r2 = (Reise)pm.FindObject(r.NDOObjectId);
            Assert.AreEqual(NDOObjectState.PersistentDirty, r2.NDOObjectState);
            Assert.AreEqual(1, r2.Länder.Count);

            // Save and Reload
            pm.Save();
            pm.UnloadCache();
            r = pm.Objects <Reise>().Single();
            Assert.AreEqual(1, r2.Länder.Count);
        }
Exemplo n.º 3
0
        public void ChangeRelationWithNewObject(Type formatterType)
        {
            // Create object and serialize it
            IFormatter formatter = (IFormatter)Activator.CreateInstance(formatterType);

            var m = CreateMitarbeiter();

            pm.MakePersistent(m);
            pm.Save();
            var oc = pm.GetObjectContainer();

            oc.Formatter = formatter;
            string serialized = oc.MarshalingString;

            pm.UnloadCache();

            // Merge object in to an OfflinePersistenceManager and change it
            OfflinePersistenceManager opm = new OfflinePersistenceManager(pm.NDOMapping.FileName);

            oc = new ObjectContainer();
            oc.Deserialize(serialized, formatter);

            opm.MergeObjectContainer(oc);

            var m2 = (Mitarbeiter)oc.RootObjects[0];

            Assert.AreEqual(NDOObjectState.Persistent, m2.NDOObjectState);
            m2.Hinzufuegen(new Reise()
            {
                Zweck = "NDO"
            });
            Assert.AreEqual(NDOObjectState.PersistentDirty, m2.NDOObjectState);

            // Create a ChangeSetContainer and serialize it
            var csc = opm.GetChangeSet();

            csc.Formatter = formatter;
            string serializedChanges = csc.MarshalingString;

            // Merge the changes back to pm
            csc = new ChangeSetContainer();
            csc.Deserialize(serializedChanges, formatter);
            m = (Mitarbeiter)csc.ChangedObjects[0];
            pm.MergeObjectContainer(csc);
            m2 = (Mitarbeiter)pm.FindObject(m.NDOObjectId);
            Assert.AreEqual(NDOObjectState.PersistentDirty, m2.NDOObjectState);
            Assert.AreEqual(1, m2.Reisen.Count);

            // Save and Reload
            pm.Save();
            pm.UnloadCache();
            m = pm.Objects <Mitarbeiter>().Single();
            Assert.AreEqual(1, m2.Reisen.Count);
        }
Exemplo n.º 4
0
        public void CompleteTurnaroundWithChangeSetContainer()
        {
            // Create object and serialize it
            var binaryFormatter = new BinaryFormatter();

            pm.MakePersistent(m);
            pm.Save();
            var oc = pm.GetObjectContainer();

            oc.Formatter = binaryFormatter;
            string serialized = oc.MarshalingString;

            pm.UnloadCache();

            // Merge object in to an OfflinePersistenceManager and change it
            OfflinePersistenceManager opm = new OfflinePersistenceManager(pm.NDOMapping.FileName);

            oc = new ObjectContainer();
            oc.Deserialize(serialized, binaryFormatter);

            opm.MergeObjectContainer(oc);

            var m2 = (Mitarbeiter)oc.RootObjects[0];

            Assert.AreEqual(NDOObjectState.Persistent, m2.NDOObjectState);
            m2.Vorname = "Hans";
            Assert.AreEqual(NDOObjectState.PersistentDirty, m2.NDOObjectState);

            // Create a ChangeSetContainer and serialize it
            var csc = opm.GetChangeSet();

            csc.Formatter = binaryFormatter;
            string serializedChanges = csc.MarshalingString;

            // Merge the changes back to pm
            csc = new ChangeSetContainer();
            csc.Deserialize(serializedChanges, binaryFormatter);
            m = (Mitarbeiter)csc.ChangedObjects[0];
            pm.MergeObjectContainer(csc);
            m2 = (Mitarbeiter)pm.FindObject(m.NDOObjectId);
            Assert.AreEqual(NDOObjectState.PersistentDirty, m2.NDOObjectState);
            Assert.AreEqual("Hans", m.Vorname);

            // Save and Reload
            pm.Save();
            pm.UnloadCache();
            m = pm.Objects <Mitarbeiter>().Single();
            Assert.AreEqual("Hans", m.Vorname);
        }