Exemplo n.º 1
0
        public void HintTest()
        {
            ClassWithHint testobj = new ClassWithHint();

            testobj.Text = "Test";
            pm.MakePersistent(testobj);
            pm.Save();
            pm.UnloadCache();
            IQuery q = new NDOQuery <ClassWithHint>(pm);

            testobj = null;
            testobj = (ClassWithHint)q.ExecuteSingle(true);
            Assert.AreEqual(guid, testobj.NDOObjectId.Id[0], "Wrong guid #1");
            Assert.AreEqual("Test", testobj.Text, "Wrong text #1");

            testobj.Text = "Neuer Text";
            pm.Save();
            testobj = null;
            testobj = (ClassWithHint)q.ExecuteSingle(true);
            Assert.AreEqual(guid, testobj.NDOObjectId.Id[0], "Wrong guid #2");
            Assert.AreEqual("Neuer Text", testobj.Text, "Wrong text #2");

            pm.Delete(testobj);
            pm.Save();
        }
Exemplo n.º 2
0
        public void OidTest()
        {
            NDOoidAndHandler testobj = new NDOoidAndHandler();

            testobj.MyId = guid;
            testobj.Text = "Test";
            pm.MakePersistent(testobj);
            pm.Save();
            pm.UnloadCache();
            IQuery q = new NDOQuery <NDOoidAndHandler>(pm);

            testobj = null;
            testobj = (NDOoidAndHandler)q.ExecuteSingle(true);
            Assert.AreEqual(guid, testobj.MyId, "Wrong guid");
            Assert.AreEqual("Test", testobj.Text, "Wrong text");

            testobj.Text = "Neuer Text";
            pm.Save();
            testobj = null;
            testobj = (NDOoidAndHandler)q.ExecuteSingle(true);
            Assert.AreEqual(guid, testobj.MyId, "Wrong guid");
            Assert.AreEqual("Neuer Text", testobj.Text, "Wrong text");

            pm.Delete(testobj);
            pm.Save();
        }
Exemplo n.º 3
0
        public void PrefetchOccurs()
        {
            Reise r = new Reise()
            {
                Zweck = "NDO"
            };
            Mitarbeiter m = new Mitarbeiter()
            {
                Vorname = "Mirko", Nachname = "Matytschak"
            };

            pm.MakePersistent(m);
            m.Hinzufuegen(r);
            pm.Save();

            NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm);

            q.AddPrefetch(nameof(Mitarbeiter.Reisen));

            var m2 = q.ExecuteSingle();

            var oc = pm.GetObjectContainer();

            Assert.AreEqual(2, oc.RootObjects.Count);
        }
Exemplo n.º 4
0
        public void TestAddNewReise()
        {
            m.Hinzufuegen(r);
            pm.MakePersistent(m);
            pm.Save();
            pm.UnloadCache();
            NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm);

            m = q.ExecuteSingle(true);
            Reise r2 = CreateReise("Schnulli");

            m.Hinzufuegen(r2);
            pm.Save();
            m = q.ExecuteSingle(true);
            Assert.AreEqual(2, m.Reisen.Count, "Count wrong");
        }
Exemplo n.º 5
0
        private void SaveAndReload()
        {
            pm.Save();
            pm.UnloadCache();
            NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm);

            m = (Mitarbeiter)q.ExecuteSingle(true);
        }
Exemplo n.º 6
0
        public void TestAddRange()
        {
            AddRange();
            NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm);

            m = q.ExecuteSingle(true);
            Assert.AreEqual(2, m.Reisen.Count, "Count of Reisen wrong");
        }
Exemplo n.º 7
0
        public void TestTopicHierarchieWorkaround()
        {
            Topic t = new  Topic("Main Topic");

            pm.MakePersistent(t);
            pm.Save();

            Topic t2 = t.NewSubTopic("Middle Topic");

            Assert.AreEqual(NDOObjectState.Created, t2.NDOObjectState, "t2 müsste Created sein");
            Assert.AreEqual(t, t2.Owner, "Owner stimmt nicht");
            Assert.AreEqual(1, t.Subtopics.Count, "t müsste einen Untergebenen in der Liste haben");

            Topic t3 = t2.NewSubTopic("End Topic");

            Assert.AreEqual(NDOObjectState.Created, t3.NDOObjectState, "t3 müsste Created sein");
            Assert.NotNull(t3.Owner, "t3 müsste einen Owner haben");

            pm.Save();

            pm.UnloadCache();

            IQuery q = new NDOQuery <Topic>(pm, "oid = {0}");

            q.Parameters.Add(t.NDOObjectId.Id[0]);
            t = (Topic)q.ExecuteSingle(true);
            Assert.AreEqual(1, t.Subtopics.Count, "t müsste einen Untergebenen in der Liste haben");

            t2 = (Topic)t.Subtopics[0];
            ObjectId oid2 = t2.NDOObjectId;

            Assert.NotNull(t2.Owner, "t2 müsste einen Owner haben");
            Assert.AreEqual(1, t2.Subtopics.Count, "t2 müsste einen Untergebenen in der Liste haben");

            t3 = (Topic)t2.Subtopics[0];
            ObjectId oid3 = t3.NDOObjectId;

            t2.RemoveSubTopic(t3);
            t.RemoveSubTopic(t2);
            Assert.Null(t2.Owner, "Owner muss null sein");
            Assert.AreEqual(NDOObjectState.Deleted, t2.NDOObjectState, "t2 muss gelöscht sein");
            Assert.AreEqual(NDOObjectState.Deleted, t3.NDOObjectState, "t3 muss gelöscht sein");
            pm.Delete(t);
            pm.Save();
            pm.UnloadCache();
            IList l = q.Execute();

            Assert.AreEqual(0, l.Count, "Liste muss leer sein 1");
            q = new NDOQuery <Topic>(pm, "oid = {0}");
            q.Parameters.Add(oid2.Id[0]);
            l = q.Execute();
            Assert.AreEqual(0, l.Count, "Liste muss leer sein 2");
            q = new NDOQuery <Topic>(pm, "oid = {0}");
            q.Parameters.Add(oid3.Id[0]);
            l = q.Execute();
            Assert.AreEqual(0, l.Count, "Liste muss leer sein 3");
        }
Exemplo n.º 8
0
        public void TestListCount()
        {
            m.Hinzufuegen(r);
            pm.MakePersistent(m);
            pm.Save();
            pm.UnloadCache();
            NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm, null);

            m = (Mitarbeiter)q.ExecuteSingle(true);
            Assert.AreEqual(1, m.Reisen.Count, "Count should be 1");
        }
Exemplo n.º 9
0
        public void TestListCount()
        {
            pm.MakePersistent(l);
            pm.MakePersistent(f);
            l.AddFlughafen(f);
            pm.Save();
            pm.UnloadCache();
            IQuery q = new NDOQuery <Land>(pm, null);

            l = (Land)q.ExecuteSingle(true);
            Assert.AreEqual(1, l.Flughäfen.Count, "Count should be 1");
        }
Exemplo n.º 10
0
        public void TestRemoveObjectSaveReloadNonHollow()
        {
            pm.MakePersistent(l);
            pm.MakePersistent(f);
            l.AddFlughafen(f);
            pm.Save();
            pm.UnloadCache();
            IQuery q = new NDOQuery <Land>(pm, null, false);

            l = (Land)q.ExecuteSingle(true);
            Assert.AreEqual(NDOObjectState.Persistent, l.NDOObjectState, "1. Wrong state");
            Assert.AreEqual(1, l.Flughäfen.Count, "1. Wrong number of objects");
            f = (Flughafen)l.Flughäfen[0];
            l.RemoveFlughafen(f);
            // f keeps the foreign key - so it get's dirty
            Assert.AreEqual(NDOObjectState.PersistentDirty, f.NDOObjectState, "2. Wrong state");
            Assert.AreEqual(0, l.Flughäfen.Count, "2. Wrong number of objects");
            pm.Save();
            l = (Land)q.ExecuteSingle(true);
            pm.UnloadCache();
            Assert.AreEqual(0, l.Flughäfen.Count, "3. Wrong number of objects");
        }
Exemplo n.º 11
0
//		[Ignore("Erzeugt Exception in TearDown")]
        public void AbortedTransaction()
        {
            m.Hinzufuegen(r);
            pm.MakePersistent(m);
            pm.Save();
            pm.UnloadCache();

            pm.TransactionMode = TransactionMode.Optimistic;

            NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm, null);

            m         = (Mitarbeiter)q.ExecuteSingle(true);
            m.Vorname = "Hans";
            ((Reise)m.Reisen[0]).Zweck = "Neuer Zweck";

            FieldInfo fi = pm.NDOMapping.GetType().GetField("persistenceHandler", BindingFlags.Instance | BindingFlags.NonPublic);

            Dictionary <Type, IPersistenceHandler> ht = (Dictionary <Type, IPersistenceHandler>)fi.GetValue(pm.NDOMapping);

            ht.Clear();
            pm.NDOMapping.FindClass(typeof(Reise)).FindField("zweck").Column.Name = "nix";

            try
            {
                pm.Save();
            }
            catch
            {
                ht.Clear();
                pm.NDOMapping.FindClass(typeof(Reise)).FindField("zweck").Column.Name = "Zweck";
                pm.Abort();
            }

            pm.UnloadCache();
            m = (Mitarbeiter)q.ExecuteSingle(true);
            Assert.AreEqual("Hartmut", m.Vorname, "Vorname falsch");
            Assert.AreEqual("ADC", ((Reise)m.Reisen[0]).Zweck, "Vorname falsch");
        }
Exemplo n.º 12
0
        public void TestDeleteHollow()
        {
            IQuery q = new NDOQuery <TimeStampContainer>(pm1, null, true);

            tsc = (TimeStampContainer)q.ExecuteSingle(true);
            Assert.AreEqual(NDOObjectState.Hollow, tsc.NDOObjectState, "Object should be hollow");
            Assert.That(((IPersistenceCapable)tsc).NDOTimeStamp != Guid.Empty, "Time Stamp should be there");
            pm1.Delete(tsc);
            pm1.Save();
            pm1.UnloadCache();
            IList l = pm1.GetClassExtent(typeof(TimeStampContainer));

            Assert.AreEqual(0, l.Count, "No object should be there");
        }
Exemplo n.º 13
0
        public void TestAddFlughafen()
        {
            pm.MakePersistent(l);
            pm.MakePersistent(f);
            l.AddFlughafen(f);
            pm.Save();
            pm.UnloadCache();
            IQuery q = new NDOQuery <Land>(pm, null);

            l = (Land)q.ExecuteSingle(true);
            Assert.NotNull(l, "Land not found");
            Assert.AreEqual(1, l.Flughäfen.Count, "Count wrong");
            Flughafen f2 = CreateFlughafen("FRA");

            pm.MakePersistent(f2);
            l.AddFlughafen(f2);
            pm.VerboseMode = true;
            pm.Save();
            pm.VerboseMode = false;
            pm.UnloadCache();
            l = (Land)q.ExecuteSingle(true);
            Assert.AreEqual(2, l.Flughäfen.Count, "Count wrong");
        }
Exemplo n.º 14
0
        public void TestPolymorphicCondition()
        {
            r.AddKostenpunkt(kp);
            pm.MakePersistent(r);
            pm.Save();

            pm.UnloadCache();
            NDOQuery <Reise> q = new NDOQuery <Reise>(pm, "belege.datum" + " = " + "{0}");

            q.Parameters.Add(DateTime.Now.Date);
            r = (Reise)q.ExecuteSingle(true);
            Assert.NotNull(r, "Reise not found");
            Assert.That(r.Kostenpunkte.Count > 0, "No Beleg");
            Assert.NotNull(r.Kostenpunkte[0], "Beleg not found");
        }
Exemplo n.º 15
0
        public void TestListEnumerator()
        {
            m.Hinzufuegen(r);
            pm.MakePersistent(m);
            pm.Save();
            pm.UnloadCache();
            NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm, null);

            m = (Mitarbeiter)q.ExecuteSingle(true);
            IEnumerator ie     = m.Reisen.GetEnumerator();
            bool        result = ie.MoveNext();

            Assert.That(result, "Enumerator should give a result");
            Assert.NotNull(ie.Current);
        }
Exemplo n.º 16
0
        public void TestObjektbaum()
        {
            Mitarbeiter m = new Mitarbeiter();

            m.Vorname  = "Test";
            m.Nachname = "Objektbaum";
            Reise r = new Reise();

            r.Zweck = "Reisezweck";
            Beleg b = new Beleg("Taxi", 30.4);

            r.AddKostenpunkt(b);
            m.Hinzufuegen(r);

            Assert.AreEqual(NDOObjectState.Transient, m.NDOObjectState, "Mitarbeiter muss Transient sein");
            Assert.AreEqual(NDOObjectState.Transient, r.NDOObjectState, "Reise muss Transient sein");
            Assert.AreEqual(NDOObjectState.Transient, b.NDOObjectState, "Beleg muss Transient sein");


            pm.MakePersistent(m);

            Assert.AreEqual(NDOObjectState.Created, m.NDOObjectState, "Mitarbeiter muss Created sein");
            Assert.AreEqual(NDOObjectState.Created, r.NDOObjectState, "Reise muss Created sein");
            Assert.AreEqual(NDOObjectState.Created, b.NDOObjectState, "Beleg muss Created sein");

            pm.Save();

            Assert.AreEqual(NDOObjectState.Persistent, m.NDOObjectState, "1 Mitarbeiter muss Persistent sein");
            Assert.AreEqual(NDOObjectState.Persistent, r.NDOObjectState, "1 Reise muss Persistent sein");
            Assert.AreEqual(NDOObjectState.Persistent, b.NDOObjectState, "1 Beleg muss Persistent sein");

            pm.UnloadCache();

            NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm, null);

            m = (Mitarbeiter)q.ExecuteSingle(true);
            Assert.AreEqual(1, m.Reisen.Count, "Reise nicht gefunden");
            r = (Reise)m.Reisen[0];
            Assert.AreEqual(1, r.Kostenpunkte.Count, "Kostenpunkt nicht gefunden");
            b = (Beleg)r.Kostenpunkte[0];
            double k = b.Kosten;

            Assert.AreEqual(NDOObjectState.Persistent, m.NDOObjectState, "2 Mitarbeiter muss Persistent sein");
            Assert.AreEqual(NDOObjectState.Persistent, r.NDOObjectState, "2 Reise muss Persistent sein");
            Assert.AreEqual(NDOObjectState.Persistent, b.NDOObjectState, "2 Beleg muss Persistent sein");
        }
Exemplo n.º 17
0
        public void TestForeignKey()
        {
            ObjectOwner owner = new ObjectOwner();

            pm.MakePersistent(owner);
            owner.Element      = new NDOoidAndHandler();
            owner.Element.Text = "Text";
            pm.Save();
            owner = null;
            pm.UnloadCache();
            IQuery q = new NDOQuery <ObjectOwner>(pm);

            owner = (ObjectOwner)q.ExecuteSingle(true);
            Assert.NotNull(owner.Element, "No element");
            Assert.AreEqual(guid, owner.Element.MyId, "Wrong guid");
            Assert.AreEqual("Text", owner.Element.Text, "Wrong text");
        }
Exemplo n.º 18
0
        public void TestHintForeignKey()
        {
            HintOwner owner = new HintOwner();

            pm.MakePersistent(owner);
            owner.Element      = new ClassWithHint();
            owner.Element.Text = "Text";
            pm.Save();
            owner = null;
            pm.UnloadCache();
            IQuery q = new NDOQuery <HintOwner>(pm);

            owner = (HintOwner)q.ExecuteSingle(true);
            Assert.NotNull(owner.Element, "No element");
            Assert.AreEqual(guid, owner.Element.NDOObjectId.Id[0], "Wrong guid");
            Assert.AreEqual("Text", owner.Element.Text, "Wrong text");
        }
Exemplo n.º 19
0
        public void TestStringLen()
        {
            string s = string.Empty;

            for (int i = 0; i < 255; i++)
            {
                s += "A";
            }
            m.Vorname = s;
            pm.MakePersistent(m);
            pm.Save();
            pm.UnloadCache();
            NDOQuery <Mitarbeiter> q  = new NDOQuery <Mitarbeiter>(pm);
            Mitarbeiter            m2 = (Mitarbeiter)q.ExecuteSingle(true);

            Assert.AreEqual(255, m2.Vorname.Length, "Lönge des Vornamens falsch");
        }
Exemplo n.º 20
0
        public void DeleteParent()
        {
            var pm = PmFactory.NewPersistenceManager();

            CreateSave(pm);
            pm.UnloadCache();
            IQuery q = new NDOQuery <Order>(pm);

            order = (Order)q.ExecuteSingle(true);
            pm.Delete(order);
            pm.Save();
            pm.UnloadCache();
            IList l = pm.GetClassExtent(typeof(OrderDetail));

            Assert.AreEqual(0, l.Count, "Wrong count #1");
            l = pm.GetClassExtent(typeof(Order));
            Assert.AreEqual(0, l.Count, "Wrong count #2");
        }
Exemplo n.º 21
0
        public void Delete()
        {
            var pm = PmFactory.NewPersistenceManager();

            CreateSave(pm);
            pm.UnloadCache();
            var q     = new NDOQuery <Order>(pm);
            var order = q.ExecuteSingle(true);

            order.RemoveOrderDetail(order.OrderDetails.First());
            pm.Save();
            pm.UnloadCache();
            var count = pm.Objects <OrderDetail>().Count;

            Assert.AreEqual(0, count);

            order = pm.Objects <Order>().Single();            // Throws, if count != 1
            Assert.AreEqual(0, order.OrderDetails.Count());
        }
Exemplo n.º 22
0
        public void DerivedGuidTest()
        {
            PersistenceManager pm = PmFactory.NewPersistenceManager();
            DerivedGuid        dg = new DerivedGuid();

            dg.Guid    = new Guid(5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5);
            dg.Myfield = "Test";
            pm.MakePersistent(dg);
            pm.Save();
            dg = null;
            pm.UnloadCache();
            IQuery q = new NDOQuery <DerivedGuid>(pm);

            dg = (DerivedGuid)q.ExecuteSingle(true);
            Assert.AreEqual(new Guid(5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5), dg.Guid, "Guid wrong");
            Assert.AreEqual(new Guid(5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5), dg.NDOObjectId.Id[0], "Oid wrong");
            Assert.AreEqual("Test", dg.Myfield, "Text wrong");
            pm.Delete(dg);
            pm.Save();
        }
Exemplo n.º 23
0
        public void Insert()
        {
            var pm = PmFactory.NewPersistenceManager();

            CreateSave(pm);
            Product p2 = new Product();

            p2.Name = "Trouser";
            pm.MakePersistent(p2);
            OrderDetail od = order.NewOrderDetail(p2);

            Assert.AreEqual(NDOObjectState.Created, od.NDOObjectState, "Wrong state");
            od.Price = 55;
            pm.Save();
            pm.UnloadCache();
            IQuery q = new NDOQuery <Order>(pm);

            order = (Order)q.ExecuteSingle(true);
            Assert.AreEqual(2, order.OrderDetails.Count(), "Wrong count");
        }
Exemplo n.º 24
0
        public void TestReiseChangeReload()
        {
            m.Hinzufuegen(r);
            pm.MakePersistent(m);
            pm.Save();
            pm.UnloadCache();
            var provider       = pm.NDOMapping.FindClass(typeof(Reise)).Provider;
            NDOQuery <Reise> q = new NDOQuery <Reise>(pm, $"zweck LIKE 'A{provider.Wildcard}'");

            r              = (Reise)q.ExecuteSingle(true);
            r.Zweck        = "NewPurpose";
            pm.VerboseMode = true;
            pm.Save();
            pm.VerboseMode = false;
            NDOQuery <Mitarbeiter> qm = new NDOQuery <Mitarbeiter>(pm);

            m = qm.ExecuteSingle(true);
            Assert.AreEqual(1, m.Reisen.Count, "Count wrong");
            Assert.AreEqual("NewPurpose", r.Zweck, "Reise wrong");
        }
Exemplo n.º 25
0
        public void Test()
        {
            ParentWithEmbedded pwe = new ParentWithEmbedded();

            pwe.Ewom = new EmbeddedWithOneMember("MyEwom");
            pwe.Test = "Test";
            pm.MakePersistent(pwe);
            pm.Save();

            Assert.AreEqual(NDOObjectState.Persistent, pwe.NDOObjectState, "Status falsch #1");
            pwe.Ewom = new EmbeddedWithOneMember("SecondEwom");
            Assert.AreEqual(NDOObjectState.PersistentDirty, pwe.NDOObjectState, "Status falsch #2");
            pm.Save();
            pm.UnloadCache();

            IQuery q = new NDOQuery <ParentWithEmbedded>(pm, null);

            pwe = (ParentWithEmbedded)q.ExecuteSingle(true);

            Assert.AreEqual("SecondEwom", pwe.Ewom.Member, "Inhalt falsch ");
        }
Exemplo n.º 26
0
        public void TestCreated()
        {
            var pm = PmFactory.NewPersistenceManager();

            // dt = new DateTime(2004, 10, 12, 13, 30, 31, 123);
            DateTestClass dtc = new DateTestClass();
            InnerDate     id  = new InnerDate();

            id.SetInnerDate();
            pm.MakePersistent(id);
            pm.MakePersistent(dtc);
            pm.Save();
            dtc.InnerDate = id;
            dtc.Name      = "Test";
            pm.Save();
            pm.UnloadCache();

            NDOQuery <DateTestClass> q = new NDOQuery <DateTestClass>(pm, null);

            dtc = (DateTestClass)q.ExecuteSingle(true);
            Assert.AreEqual(2002, dtc.InnerDate.Dt.Year, "DateTime konnte nicht richtig gelesen werden");
        }
Exemplo n.º 27
0
        public void ParametersTest()
        {
            var pm = PmFactory.NewPersistenceManager();

            DataContainer dc = new DataContainer();

            dc.Init();
            pm.MakePersistent(dc);
            pm.Save();
            IQuery q = new NDOQuery <DataContainer>(pm, "boolVar" + " = " + "{0}");

#if !ORACLE
            q.Parameters.Add(true);
#else
            q.Parameters.Add(1);
#endif
            q.ExecuteSingle(true);              // If something goes wrong, an Exception will be thrown.

            q = new NDOQuery <DataContainer>(pm, "byteVar" + " = " + "{0}");
            q.Parameters.Add((byte)127);
            q.ExecuteSingle(true);              // If something goes wrong, an Exception will be thrown.

            q = new NDOQuery <DataContainer>(pm, "dateTimeVar" + " <= " + "{0}");
            q.Parameters.Add(DateTime.Now);
            q.ExecuteSingle(true);              // If something goes wrong, an Exception will be thrown.

            q = new NDOQuery <DataContainer>(pm, "guidVar" + " = " + "{0}");
            q.Parameters.Add(new Guid("12341234-1234-1234-1234-123412341234"));
            q.ExecuteSingle(true);              // If something goes wrong, an Exception will be thrown.

            q = new NDOQuery <DataContainer>(pm, "decVar" + " = " + "{0}");
            q.Parameters.Add(1231.12m);
            q.ExecuteSingle(true);              // If something goes wrong, an Exception will be thrown.

            q = new NDOQuery <DataContainer>(pm, "doubleVar" + " = " + "{0}");
            q.Parameters.Add(1E28);
            q.ExecuteSingle(true);              // If something goes wrong, an Exception will be thrown.

            q = new NDOQuery <DataContainer>(pm, "enumVar" + " = " + "{0}");
            q.Parameters.Add(EnumType.drei);
            q.ExecuteSingle(true);              // If something goes wrong, an Exception will be thrown.

#if !MYSQL
            q = new NDOQuery <DataContainer>(pm, "floatVar" + " = " + "{0}");
            q.Parameters.Add(1E14F);
            q.ExecuteSingle(true);              // If something goes wrong, an Exception will be thrown.
#endif
            q = new NDOQuery <DataContainer>(pm, "int16Var" + " = " + "{0}");
            q.Parameters.Add(short.MaxValue);
            q.ExecuteSingle(true);              // If something goes wrong, an Exception will be thrown.

            q = new NDOQuery <DataContainer>(pm, "int32Var" + " = " + "{0}");
            q.Parameters.Add(int.MaxValue);
            q.ExecuteSingle(true);              // If something goes wrong, an Exception will be thrown.

            q = new NDOQuery <DataContainer>(pm, "int64Var" + " = " + "{0}");
            q.Parameters.Add(0x1ffffffff);
            q.ExecuteSingle(true);              // If something goes wrong, an Exception will be thrown.

            q = new NDOQuery <DataContainer>(pm, "stringVar" + " = " + "{0}");
            q.Parameters.Add("Test");
            q.ExecuteSingle(true);              // If something goes wrong, an Exception will be thrown.

            q = new NDOQuery <DataContainer>(pm, "uint16Var" + " = " + "{0}");
            q.Parameters.Add((ushort)short.MaxValue);
            q.ExecuteSingle(true);              // If something goes wrong, an Exception will be thrown.

            q = new NDOQuery <DataContainer>(pm, "uint32Var" + " = " + "{0}");
            q.Parameters.Add((uint)int.MaxValue);
            q.ExecuteSingle(true);              // If something goes wrong, an Exception will be thrown.

            q = new NDOQuery <DataContainer>(pm, "uint64Var" + " = " + "{0}");
            q.Parameters.Add(0x1ffffffff);
            dc = (DataContainer)q.ExecuteSingle(true);               // If something goes wrong, an Exception will be thrown.

            dc.StringVar = "";
            pm.Save();

#if ORACLE
            q = new NDOQuery <DataContainer>(pm, "stringVar" + Query.Op.IsNull);
            q.ExecuteSingle(true);              // If something goes wrong, an Exception will be thrown.
#else
            q = new NDOQuery <DataContainer>(pm, "stringVar" + " = " + "{0}");
            q.Parameters.Add("");
            q.ExecuteSingle(true);              // If something goes wrong, an Exception will be thrown.
#endif
        }
Exemplo n.º 28
0
        public void TestBaseOnly()
        {
            var    pm   = PmFactory.NewPersistenceManager();
            Device root = new Device();

            root.Name = "root";
            pm.MakePersistent(root);
            pm.Save();

            Device child1 = root.NewDevice(typeof(Device));

            child1.Name = "1";

            Device child2 = root.NewDevice(typeof(Device));

            child2.Name = "2";

            pm.Save();

            Device child11 = child1.NewDevice(typeof(Device));

            child11.Name = "11";

            Device child12 = child1.NewDevice(typeof(Device));

            child12.Name = "12";

            Device child21 = child2.NewDevice(typeof(Device));

            child21.Name = "21";

            Device child22 = child2.NewDevice(typeof(Device));

            child22.Name = "22";

            pm.Save();

            NDOQuery <Device> q = new NDOQuery <Device>(pm);
            decimal           c = (decimal)q.ExecuteAggregate("name", AggregateType.Count);

            Assert.AreEqual(7m, c, "Count wrong: ");

            q = new NDOQuery <Device>(pm, "name = {0}");
            q.Parameters.Add("root");

            root = q.ExecuteSingle(true);

            Assert.AreEqual(2, root.Subdevices.Count, "Child Count wrong #1: ");
            foreach (Device d in root.Subdevices)
            {
                Assert.That(d.Name == "1" || d.Name == "2", "Name wrong #1");
            }

            pm.Delete(root);
            pm.Save();
            pm.UnloadCache();

            q = new NDOQuery <Device>(pm);
            c = (decimal)q.ExecuteAggregate("name", AggregateType.Count);
            Assert.AreEqual(0m, c, "Count wrong: ");
        }