Esempio n. 1
0
        public void CanSetObjectsToHollow()
        {
            var formatter             = new NdoJsonFormatter();
            var serializationIterator = new NDO.SerializationIterator(r => r.ReferencedType == typeof(Reise), pc => pc.NDOObjectState = NDOObjectState.Hollow);

            var m = CreateMitarbeiter();

            pm.MakePersistent(m);
            Reise reise;

            m.Hinzufuegen(reise = new Reise()
            {
                Zweck = "NDO"
            });
            pm.Save();

            var oc = pm.GetObjectContainer();

            oc.SerialisationIterator = serializationIterator;

            bool found = false;

            foreach (object o in oc.RootObjects)
            {
                if (Object.ReferenceEquals(m, o))
                {
                    found = true;
                }
            }
            Assert.That(found);

            Assert.AreEqual(NDOObjectState.Persistent, m.NDOObjectState);

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

            Assert.AreEqual(2, oc.RootObjects.Count);
            Assert.AreEqual(NDOObjectState.Hollow, m.NDOObjectState);
            Assert.AreEqual(NDOObjectState.Hollow, reise.NDOObjectState);
        }
Esempio n. 2
0
        public void ObjectContainerSerializesRelations()
        {
            var binaryFormatter       = new BinaryFormatter();
            var serializationIterator = new NDO.SerializationIterator(r => r.ReferencedType == typeof(Reise));

            pm.MakePersistent(m);
            m.Hinzufuegen(new Reise()
            {
                Zweck = "ADC"
            });
            pm.Save();

            var oc = pm.GetObjectContainer();

            bool found = false;

            foreach (object o in oc.RootObjects)
            {
                if (Object.ReferenceEquals(m, o))
                {
                    found = true;
                }
            }
            Assert.That(found);

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

            Assert.AreEqual(2, oc.RootObjects.Count);

            pm.UnloadCache();

            var oc2 = pm.GetObjectContainer();

            Assert.AreEqual(0, oc2.RootObjects.Count);

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

            oc2 = pm.GetObjectContainer();
            Assert.AreEqual(2, oc2.RootObjects.Count);

            Reise       r2 = null;
            Mitarbeiter m2 = null;

            foreach (object o in oc2.RootObjects)
            {
                if (o is Reise)
                {
                    r2 = (Reise)o;
                }
                if (o is Mitarbeiter)
                {
                    m2 = (Mitarbeiter)o;
                }
            }

            Assert.NotNull(r2);
            Assert.NotNull(m2);

            Assert.AreEqual("Mirko", m2.Vorname);
            Assert.AreEqual(NDOObjectState.Persistent, m2.NDOObjectState);

            Assert.AreEqual("ADC", r2.Zweck);
            Assert.AreEqual(NDOObjectState.Persistent, r2.NDOObjectState);
        }