Beispiel #1
0
        public void AggrTestCreateObjectsWithTransaction()
        {
            var pm = PmFactory.NewPersistenceManager();
            var tm = pm.TransactionMode;

            try
            {
                // See Issue #1145
                // The test would fail, if we didn't alter the update rank
                // according to the actual situation, that e has a valid database id.
                // The test would fail, because the update rank would cause e to be saved first
                // at the 2nd Save() call.
                pm.TransactionMode = TransactionMode.Optimistic;
                pm.MakePersistent(e);
                pm.Save(true);
                pm.MakePersistent(z0);
                e.Schlüssel = z0;
                pm.Save();
                pm.UnloadCache();
                pm.TransactionMode = TransactionMode.None;
                var email = pm.Objects <Email>().Single();
                Assert.NotNull(email.Schlüssel);
                Assert.AreEqual(42, email.Schlüssel.Key);
                pm.UnloadCache();
                var zertifikat = pm.Objects <Zertifikat>().Single();
                Assert.NotNull(zertifikat.Adresse);
            }
            finally
            {
                pm.TransactionMode = tm;
            }
        }
Beispiel #2
0
        public void AggrTestReplaceChildSave()
        {
            var pm = PmFactory.NewPersistenceManager();

            pm.MakePersistent(z0);
            pm.MakePersistent(e);
            e.Schlüssel = z0;
            pm.Save();
            Assert.NotNull(e.Schlüssel, "1. Zertifikat not found");
            Zertifikat z2 = new Zertifikat();

            z2.Key = 0815;
            pm.MakePersistent(z2);
            e.Schlüssel = z2;
            Assert.AreEqual(NDOObjectState.PersistentDirty, z0.NDOObjectState, "1. Wrong state");
            Assert.AreEqual(NDOObjectState.Created, z2.NDOObjectState, "2. Wrong state");
            Assert.Null(z0.Adresse, "3. No relation to Email");
            Assert.AreSame(z2.Adresse, e, "4. Email should be same");
            Assert.AreSame(e.Schlüssel, z2, "5. Zertifikat should be same");
            pm.Save();
            Assert.AreEqual(NDOObjectState.Persistent, z0.NDOObjectState, "6. Wrong state");
            Assert.AreEqual(NDOObjectState.Persistent, z2.NDOObjectState, "7. Wrong state");
            Assert.Null(z0.Adresse, "8. No relation to Email");
            Assert.AreSame(z2.Adresse, e, "9. Email should be same");
            Assert.AreSame(e.Schlüssel, z2, "10. Zertifikat should be same");
        }
Beispiel #3
0
        public void AggrSimpleObjectSave()
        {
            var pm = PmFactory.NewPersistenceManager();

            pm.MakePersistent(z0);
            pm.Save();
        }
Beispiel #4
0
        public void CompTestExtentRelatedObjects()
        {
            var pm = PmFactory.NewPersistenceManager();

            m.SVN = svn;
            pm.MakePersistent(m);
            pm.Save();
            IList liste = pm.GetClassExtent(typeof(Mitarbeiter));

            m = (Mitarbeiter)liste[0];
            Assert.AreEqual(NDOObjectState.Persistent, m.NDOObjectState, "1: Mitarbeiter should be persistent");
            Assert.NotNull(m.SVN, "2. Relation is missing");
            Assert.AreEqual(NDOObjectState.Persistent, m.SVN.NDOObjectState, "2.: SVN should be hollow");
            Assert.AreSame(m, svn.Angestellter, "2. Backlink wrong");

            pm.UnloadCache();
            liste = pm.GetClassExtent(typeof(Mitarbeiter));
            m     = (Mitarbeiter)liste[0];
            Assert.AreEqual(NDOObjectState.Hollow, m.NDOObjectState, "5: Mitarbeiter should be hollow");
            Assert.NotNull(m.SVN, "6. Relation is missing");
            Assert.AreEqual(NDOObjectState.Hollow, m.SVN.NDOObjectState, "8.: SVN should be hollow");
            Assert.That(m != svn.Angestellter, "8a. Should be different objects");
            Assert.AreSame(m, m.SVN.Angestellter, "8b. Mitarbeiter should match");

            pm.UnloadCache();
            liste = pm.GetClassExtent(typeof(Mitarbeiter), false);
            m     = (Mitarbeiter)liste[0];
            Assert.AreEqual(NDOObjectState.Persistent, m.NDOObjectState, "9: Mitarbeiter should be persistent");
            Assert.NotNull(m.SVN, "10. Relation is missing");
            Assert.AreEqual(NDOObjectState.Hollow, m.SVN.NDOObjectState, "12.: SVN should be hollow");
            Assert.That(m != svn.Angestellter, "12a. Should be different objects");
            Assert.AreSame(m, m.SVN.Angestellter, "12b. Mitarbeiter should match");
        }
Beispiel #5
0
        public void AggrTestCreateObjectsSave()
        {
            var pm = PmFactory.NewPersistenceManager();

            pm.MakePersistent(z0);
            e.Schlüssel = z0;
            pm.MakePersistent(e);
            pm.Save();
            Assert.That(!e.NDOObjectId.Equals(e.Schlüssel.NDOObjectId), "Ids should be different");
            e  = (Email)pm.FindObject(e.NDOObjectId);
            z0 = (Zertifikat)pm.FindObject(e.Schlüssel.NDOObjectId);
            Assert.NotNull(e, "1. Email not found");
            Assert.NotNull(z0, "1. Zertifikat not found");
            ObjectId moid = e.NDOObjectId;
            ObjectId soid = z0.NDOObjectId;

            e  = null;
            z0 = null;

            pm.UnloadCache();
            e = (Email)pm.FindObject(moid);
            var z1 = pm.Objects <Zertifikat>().Where(z => z.Oid() == soid.Id.Value).SingleOrDefault();

            Assert.NotNull(z1);
            Zertifikat z2 = e.Schlüssel;

            Assert.AreSame(z1, z2);
            z0 = (Zertifikat)pm.FindObject(soid);
            Assert.NotNull(e, "2. Email not found");
            Assert.NotNull(z0, "2. Zertifikat not found");
            Assert.AreSame(z0, z2, "Zertifikat should match");
            Assert.AreSame(e, z0.Adresse, "Email should match");
        }
Beispiel #6
0
        private void SetupEmail()
        {
            var pm = PmFactory.NewPersistenceManager();

            pm.MakePersistent(e);
            pm.Save();
        }
Beispiel #7
0
        public void CompTestHollow()
        {
            var pm = PmFactory.NewPersistenceManager();

            m.SVN = svn;
            pm.MakePersistent(m);
            pm.Save();
            pm.MakeHollow(m);               // setzt m.svn auf null

            Assert.AreEqual(NDOObjectState.Hollow, m.NDOObjectState, "1: Mitarbeiter should be hollow");
            Assert.AreEqual(NDOObjectState.Persistent, svn.NDOObjectState, "1: SVN should be persistent");

            svn = m.SVN;             // ruft LoadData för m auf. m.svm liegt auf dem Cache und ist Persistent
            Assert.AreEqual(NDOObjectState.Persistent, m.NDOObjectState, "1: Mitarbeiter should be persistent");
            Assert.AreEqual(NDOObjectState.Persistent, svn.NDOObjectState, "2: SVN should be persistent");
            ObjectId id = m.NDOObjectId;

            pm.Close();
            pm = PmFactory.NewPersistenceManager();
            m  = (Mitarbeiter)pm.FindObject(id);
            Assert.NotNull(m, "Mitarbeiter not found");
            Assert.AreEqual(NDOObjectState.Hollow, m.NDOObjectState, "2: Mitarbeiter should be hollow");
            svn = m.SVN;
            Assert.AreEqual(NDOObjectState.Persistent, m.NDOObjectState, "2: Mitarbeiter should be persistent");
            Assert.NotNull(svn, "SVN not found");
            Assert.AreEqual(NDOObjectState.Hollow, svn.NDOObjectState, "1: SVN should be hollow");
            Assert.AreSame(m, svn.Angestellter, "2. Backlink wrong");
        }
Beispiel #8
0
        public void AggrTestHollow()
        {
            var pm = PmFactory.NewPersistenceManager();

            pm.MakePersistent(z0);
            e.Schlüssel = z0;
            pm.MakePersistent(e);
            pm.Save();
            pm.MakeHollow(e);               // setzt e.z auf null

            Assert.AreEqual(NDOObjectState.Hollow, e.NDOObjectState, "1: Email should be hollow");
            Assert.AreEqual(NDOObjectState.Persistent, z0.NDOObjectState, "1: Zertifikat should be persistent");

            z0 = e.Schlüssel;             // ruft LoadData för e auf. e.svm liegt auf dem Cache und ist Persistent
            Assert.AreEqual(NDOObjectState.Persistent, e.NDOObjectState, "1: Email should be persistent");
            Assert.AreEqual(NDOObjectState.Persistent, z0.NDOObjectState, "2: Zertifikat should be persistent");
            ObjectId id = e.NDOObjectId;

            pm.Close();
            pm = PmFactory.NewPersistenceManager();
            e  = (Email)pm.FindObject(id);
            Assert.NotNull(e, "Email not found");
            Assert.AreEqual(NDOObjectState.Hollow, e.NDOObjectState, "2: Email should be hollow");
            z0 = e.Schlüssel;
            Assert.AreEqual(NDOObjectState.Persistent, e.NDOObjectState, "2: Email should be persistent");
            Assert.NotNull(z0, "Zertifikat not found");
            Assert.AreEqual(NDOObjectState.Hollow, z0.NDOObjectState, "1: Zertifikat should be hollow");
            Assert.AreSame(e, z0.Adresse, "2. Backlink wrong");
        }
Beispiel #9
0
        public void AggrTestExtentRelatedObjects()
        {
            var pm = PmFactory.NewPersistenceManager();

            pm.MakePersistent(z0);
            e.Schlüssel = z0;
            pm.MakePersistent(e);
            pm.Save();
            IList liste = pm.GetClassExtent(typeof(Email));

            e = (Email)liste[0];
            Assert.AreEqual(NDOObjectState.Persistent, e.NDOObjectState, "1: Email should be persistent");
            Assert.NotNull(e.Schlüssel, "2. Relation is missing");
            Assert.AreEqual(NDOObjectState.Persistent, e.Schlüssel.NDOObjectState, "2.: Zertifikat should be hollow");
            Assert.AreSame(e, z0.Adresse, "2. Backlink wrong");

            pm.UnloadCache();
            liste = pm.GetClassExtent(typeof(Email));
            e     = (Email)liste[0];
            Assert.AreEqual(NDOObjectState.Hollow, e.NDOObjectState, "5: Email should be hollow");
            Assert.NotNull(e.Schlüssel, "6. Relation is missing");
            Assert.AreEqual(NDOObjectState.Hollow, e.Schlüssel.NDOObjectState, "8.: Zertifikat should be hollow");
            Assert.That(e != z0.Adresse, "8a. Should be different objects");
            Assert.AreSame(e, e.Schlüssel.Adresse, "8b. Email should match");

            pm.UnloadCache();
            liste = pm.GetClassExtent(typeof(Email), false);
            e     = (Email)liste[0];
            Assert.AreEqual(NDOObjectState.Persistent, e.NDOObjectState, "9: Email should be persistent");
            Assert.NotNull(e.Schlüssel, "10. Relation is missing");
            Assert.AreEqual(NDOObjectState.Hollow, e.Schlüssel.NDOObjectState, "12.: Zertifikat should be hollow");
            Assert.That(e != z0.Adresse, "12a. Should be different objects");
            Assert.AreSame(e, e.Schlüssel.Adresse, "12b. Email should match");
        }
Beispiel #10
0
        public void CompTestCreateObjectsSave()
        {
            var pm = PmFactory.NewPersistenceManager();

            m.SVN = svn;
            pm.MakePersistent(m);
            pm.Save();
            Assert.That(!m.NDOObjectId.Equals(m.SVN.NDOObjectId), "Ids should be different");
            m   = (Mitarbeiter)pm.FindObject(m.NDOObjectId);
            svn = (Sozialversicherungsnummer)pm.FindObject(m.SVN.NDOObjectId);
            Assert.NotNull(m, "1. Mitarbeiter not found");
            Assert.NotNull(svn, "1. SVN not found");
            ObjectId moid = m.NDOObjectId;
            ObjectId soid = svn.NDOObjectId;

            m   = null;
            svn = null;

            pm.UnloadCache();
            m = (Mitarbeiter)pm.FindObject(moid);
            Sozialversicherungsnummer s2 = m.SVN;

            svn = (Sozialversicherungsnummer)pm.FindObject(soid);
            Assert.NotNull(m, "2. Mitarbeiter not found");
            Assert.NotNull(svn, "2. SVN not found");
            Assert.AreSame(svn, s2, "SVN should match");
            Assert.AreSame(m, svn.Angestellter, "Mitarbeiter should match");
        }
Beispiel #11
0
        public void TestDfr()
        {
            var pm = PmFactory.NewPersistenceManager();

            DfrContact contact = new DfrContact();

            contact.Name = "Hans Möller";
            pm.MakePersistent(contact as IPersistenceCapable);

            DfrAddress address = new DfrAddress();

            pm.MakePersistent(address as IPersistenceCapable);
            address.Ort           = "Wahnweil";
            address.OriginContact = contact;

            DfrAddressDescriptor descriptor = address.NewAddressDescriptor(contact);

            descriptor.IsAdopted = true;

            Assert.AreEqual(1, contact.Addresses.Count, "Count falsch");
            Assert.That((contact.Addresses[0] as DfrAddressDescriptor) == descriptor, "Descriptor falsch");
            pm.Save();

            pm.MakeHollow(contact as IPersistenceCapable);

            address.RemoveAddressDescriptor(descriptor);
            Assert.AreEqual(NDOObjectState.Deleted, descriptor.NDOObjectState, "Status falsch");
        }
Beispiel #12
0
        public void ListConnection()
        {
            PersistenceManager pm   = PmFactory.NewPersistenceManager();
            Connection         conn = (Connection)pm.NDOMapping.Connections[0];

            Console.WriteLine(String.Format("\r\nConnection '{0}', Type {1}\r\n", conn.Name, conn.Type));
        }
Beispiel #13
0
        public void ChangeSetDetectsObjectDeletion1_to_1()
        {
            var pm = PmFactory.NewPersistenceManager();

            m = pm.Objects <Mitarbeiter>().Single();
            Adresse a = new Adresse()
            {
                Ort = "München", Straße = "Teststr", Plz = "80133"
            };

            m.Adresse = a;
            pm.Save();
            pm.UnloadCache();
            m         = pm.Objects <Mitarbeiter>().Single();
            m.Adresse = null;
            var changeObject = pm.GetChangeSet(m);
            var original     = changeObject.original;
            var current      = changeObject.current;

            Assert.AreEqual(1, original.Count);
            Assert.AreEqual(1, current.Count);
            Assert.That(original.ContainsKey("adresse"));
            Assert.That(current.ContainsKey("adresse"));
            Assert.AreEqual(1, ((List <ObjectId>)original["adresse"]).Count);
            Assert.AreEqual(0, ((List <ObjectId>)current["adresse"]).Count);
        }
Beispiel #14
0
        public void ChangeSetDetectsObjectAddition1_to_1()
        {
            var pm = PmFactory.NewPersistenceManager();

            m = pm.Objects <Mitarbeiter>().Single();
            Adresse a = new Adresse()
            {
                Ort = "München", Straße = "Teststr", Plz = "80133"
            };

            m.Adresse = a;
            var changeObject = pm.GetChangeSet(m);
            var original     = changeObject.original;
            var current      = changeObject.current;

            Assert.AreEqual(1, original.Count);
            Assert.AreEqual(1, current.Count);
            Assert.That(original.ContainsKey("adresse"));
            Assert.That(current.ContainsKey("adresse"));
            Assert.AreEqual(a.NDOObjectId, ((List <ObjectId>)current["adresse"])[0]);
            // At this point it doesn't make any sense to serialize the changeObject,
            // since the id of a is not yet determined.
            Assert.That((int)a.NDOObjectId.Id[0] < 0);
            pm.Save();
            var newChangeObject = changeObject.SerializableClone();

            // Now the id of r is determined. Let's assert, that the list in current reflects the change.
            Assert.That((int)a.NDOObjectId.Id[0] > 0);
            Assert.AreEqual(a.NDOObjectId.ToShortId(), ((List <string>)newChangeObject.current["adresse"])[0]);
        }
Beispiel #15
0
        public void AggrChildAddFail()
        {
            var pm = PmFactory.NewPersistenceManager();

            pm.MakePersistent(z0);
            pm.MakePersistent(e);
            z0.Adresse = e;
        }