Ejemplo n.º 1
0
        public void DeleteTest()
        {
            using (Db4oDatabase db = new Db4oDatabase(dbfile1, container)) {
                MockObject obj1 = new MockObject
                {
                    Name = "Jacky",
                    Phone = "22305779",
                    Address = new Address
                    {
                        Office = "ZDH",
                        Home = "BBG"
                    }
                };

                db.Store(obj1);
                Assert.AreEqual(1, db.Load<MockObject>(delegate(MockObject obj) {
                    return obj.Name == "Jacky";
                }).Count);

                MockObject obj2 = db.Load<MockObject>(delegate(MockObject obj) {
                    return obj.Name == "Jacky";
                })[0];
                db.Delete(obj2);
                Assert.AreEqual(0, db.Load<MockObject>(delegate(MockObject obj) {
                    return obj.Name == "Jacky";
                }).Count);

            }
        }
Ejemplo n.º 2
0
        public void StoreTest()
        {
            using (Db4oDatabase db = new Db4oDatabase(dbfile1, container)) {
                MockObject obj1 = new MockObject
                {
                    Name    = "Jacky",
                    Phone   = "22305779",
                    Address = new Address {
                        Office = "ZDH",
                        Home   = "BBG"
                    }
                };

                db.Store(obj1);

                Assert.IsNotNull(db.Load <MockObject>()[0]);
                Assert.IsNotNull(db.Load <Address>()[0]);

                IList <MockObject> list = db.Load <MockObject>(delegate(MockObject obj) {
                    return(obj.Name == "Jacky");
                });
                Assert.AreEqual("Jacky", list[0].Name);
                Assert.AreEqual("22305779", list[0].Phone);
                Assert.IsNotNull(list[0].Address);
                Console.WriteLine(list[0]);

                MockObject obj2 = list[0];
                obj2.Phone = "22228057";
                db.Store(obj2);
                Assert.AreEqual(1, db.Load <MockObject>(delegate(MockObject obj) {
                    return(obj.Name == "Jacky");
                }).Count);
                Console.WriteLine(obj2);

                MockObject obj3 = new MockObject
                {
                    Name    = "Jacky",
                    Phone   = "22305779",
                    Address = new Address
                    {
                        Office = "ZDH",
                        Home   = "BBG"
                    }
                };
                db.Store(obj3);
                list.Clear();
                list = db.Load <MockObject>(delegate(MockObject obj) {
                    return(obj.Name == "Jacky");
                });
                Assert.AreEqual(2, list.Count);
                foreach (MockObject obj in list)
                {
                    Console.WriteLine(obj);
                }
            }
        }
Ejemplo n.º 3
0
        public void StoreTest()
        {
            using (Db4oDatabase db = new Db4oDatabase(dbfile1, container)) {
                MockObject obj1 = new MockObject
                {
                    Name = "Jacky",
                    Phone = "22305779",
                    Address = new Address {
                        Office = "ZDH",
                        Home = "BBG"
                    }
                };

                db.Store(obj1);

                Assert.IsNotNull(db.Load<MockObject>()[0]);
                Assert.IsNotNull(db.Load<Address>()[0]);

                IList<MockObject> list = db.Load<MockObject>(delegate(MockObject obj) {
                    return obj.Name == "Jacky";
                });
                Assert.AreEqual("Jacky", list[0].Name);
                Assert.AreEqual("22305779", list[0].Phone);
                Assert.IsNotNull(list[0].Address);
                Console.WriteLine(list[0]);

                MockObject obj2 = list[0];
                obj2.Phone = "22228057";
                db.Store(obj2);
                Assert.AreEqual(1, db.Load<MockObject>(delegate(MockObject obj) {
                    return obj.Name == "Jacky";
                }).Count);
                Console.WriteLine(obj2);

                MockObject obj3 = new MockObject
                {
                    Name = "Jacky",
                    Phone = "22305779",
                    Address = new Address
                    {
                        Office = "ZDH",
                        Home = "BBG"
                    }
                };
                db.Store(obj3);
                list.Clear();
                list = db.Load<MockObject>(delegate(MockObject obj) {
                    return obj.Name == "Jacky";
                });
                Assert.AreEqual(2, list.Count);
                foreach (MockObject obj in list) {
                    Console.WriteLine(obj);
                }
            }
        }