Ejemplo n.º 1
0
        public void SelectParentWithChildren()
        {
            int count = DataUtil.CountRows("IdentityParents");

            ObjectTransaction transaction = manager.BeginTransaction();

            IdentityParentTestObject parent = transaction.Select(typeof(IdentityParentTestObject), 3) as IdentityParentTestObject;

            Assert.AreEqual(3, parent.Id);
            Assert.AreEqual("A", parent.ObjData);
            Assert.AreEqual(2, parent.ChildObjects.Count);

            IdentityChildTestObject obj1 = parent.ChildObjects[0] as IdentityChildTestObject;

            Assert.AreEqual(1, obj1.Id);
            Assert.AreEqual("A", obj1.ObjData);
            Assert.AreEqual(3, obj1.Parent.Id);
            Assert.AreEqual("A", obj1.Parent.ObjData);
            Assert.AreEqual(2, obj1.Parent.ChildObjects.Count);

            IdentityChildTestObject obj2 = parent.ChildObjects[1] as IdentityChildTestObject;

            Assert.AreEqual(2, obj2.Id);
            Assert.AreEqual("B", obj2.ObjData);
            Assert.AreEqual(3, obj2.Parent.Id);
            Assert.AreEqual("A", obj2.Parent.ObjData);
            Assert.AreEqual(2, obj2.Parent.ChildObjects.Count);

            Assert.AreEqual(count, DataUtil.CountRows("IdentityParents"));
        }
Ejemplo n.º 2
0
        public void UpdateChild()
        {
            int parentCount   = DataUtil.CountRows("IdentityParents");
            int childrenCount = DataUtil.CountRows("IdentityChildren");

            ObjectTransaction transaction1 = manager.BeginTransaction();

            IdentityChildTestObject child1 = transaction1.Select(typeof(IdentityChildTestObject), 1) as IdentityChildTestObject;

            Assert.AreEqual(1, child1.Id);
            Assert.AreEqual("A", child1.ObjData);
            Assert.AreEqual(3, child1.Parent.Id);
            Assert.IsTrue(child1.Parent.ChildObjects.Contains(child1));

            child1.ObjData = "X";

            transaction1.Commit();

            Assert.AreEqual(parentCount, DataUtil.CountRows("IdentityParents"));
            Assert.AreEqual(childrenCount, DataUtil.CountRows("IdentityChildren"));

            ObjectTransaction transaction2 = manager.BeginTransaction();

            IdentityChildTestObject child2 = transaction2.Select(typeof(IdentityChildTestObject), 1) as IdentityChildTestObject;

            Assert.AreEqual(1, child2.Id);
            Assert.AreEqual("X", child2.ObjData);
            Assert.AreEqual(3, child2.Parent.Id);
            Assert.IsTrue(child2.Parent.ChildObjects.Contains(child2));

            Assert.AreEqual(parentCount, DataUtil.CountRows("IdentityParents"));
            Assert.AreEqual(childrenCount, DataUtil.CountRows("IdentityChildren"));
        }
Ejemplo n.º 3
0
        public void AddChild()
        {
            int parentCount   = DataUtil.CountRows("IdentityParents");
            int childrenCount = DataUtil.CountRows("IdentityChildren");

            ObjectTransaction transaction = manager.BeginTransaction();

            IdentityParentTestObject parent = transaction.Select(typeof(IdentityParentTestObject), 4) as IdentityParentTestObject;

            Assert.AreEqual(4, parent.Id);
            Assert.AreEqual("B", parent.ObjData);
            Assert.AreEqual(0, parent.ChildObjects.Count);

            IdentityChildTestObject child = transaction.Create(typeof(IdentityChildTestObject)) as IdentityChildTestObject;

            child.ObjData = "test";
            child.Parent  = parent;

            Assert.AreEqual(4, child.Parent.Id);
            Assert.AreEqual(1, parent.ChildObjects.Count);

            Assert.IsTrue(parent.ChildObjects.Contains(child));

            transaction.Commit();

            Assert.AreEqual(parentCount, DataUtil.CountRows("IdentityParents"));
            Assert.AreEqual(childrenCount + 1, DataUtil.CountRows("IdentityChildren"));
        }
Ejemplo n.º 4
0
        public void DoubleParentCondition()
        {
            ObjectTransaction transaction = manager.BeginTransaction();

            Query query = new Query(new Condition("Parent.Id", Expression.Equal, 3), new Condition("Parent.ObjData", Expression.Equal, "A"));

            ServerObjectCollection objects = transaction.Select(typeof(IdentityChildTestObject), query);

            Assert.AreEqual(2, objects.Count);

            IdentityChildTestObject obj1 = objects[0] as IdentityChildTestObject;

            Assert.AreEqual(1, obj1.Id);
            Assert.AreEqual("A", obj1.ObjData);
            Assert.AreEqual(3, obj1.Parent.Id);
            Assert.AreEqual("A", obj1.Parent.ObjData);
            Assert.AreEqual(2, obj1.Parent.ChildObjects.Count);

            IdentityChildTestObject obj2 = objects[1] as IdentityChildTestObject;

            Assert.AreEqual(2, obj2.Id);
            Assert.AreEqual("B", obj2.ObjData);
            Assert.AreEqual(3, obj2.Parent.Id);
            Assert.AreEqual("A", obj2.Parent.ObjData);
            Assert.AreEqual(2, obj2.Parent.ChildObjects.Count);
        }
Ejemplo n.º 5
0
        public void QueryUsedTwice()
        {
            ObjectTransaction transaction = manager.BeginTransaction();

            Query query = new Query(new LiteralCondition("Parent.ObjData", " + 'X' = 'AX'"));

            query.Order = "Parent.ObjData";

            ServerObjectCollection objects1 = transaction.Select(typeof(IdentityChildTestObject), query);
            ServerObjectCollection objects2 = transaction.Select(typeof(IdentityChildTestObject), query);

            Assert.AreEqual(2, objects1.Count);
            Assert.AreEqual(2, objects2.Count);

            IdentityChildTestObject obj1 = objects1[0] as IdentityChildTestObject;

            Assert.AreEqual(1, obj1.Id);
            Assert.AreEqual("A", obj1.ObjData);
            Assert.AreEqual(3, obj1.Parent.Id);
            Assert.AreEqual("A", obj1.Parent.ObjData);
            Assert.AreEqual(2, obj1.Parent.ChildObjects.Count);

            IdentityChildTestObject obj2 = objects2[0] as IdentityChildTestObject;

            Assert.AreEqual(1, obj2.Id);
            Assert.AreEqual("A", obj2.ObjData);
            Assert.AreEqual(3, obj2.Parent.Id);
            Assert.AreEqual("A", obj2.Parent.ObjData);
            Assert.AreEqual(2, obj2.Parent.ChildObjects.Count);
        }
Ejemplo n.º 6
0
        public void InsertChildWithNoParent()
        {
            ObjectTransaction transaction = manager.BeginTransaction();

            IdentityChildTestObject child = transaction.Create(typeof(IdentityChildTestObject)) as IdentityChildTestObject;

            child.ObjData = "test";

            transaction.Commit();
        }
Ejemplo n.º 7
0
        public void SelectChild()
        {
            int count = DataUtil.CountRows("IdentityChildren");

            ObjectTransaction transaction = manager.BeginTransaction();

            IdentityChildTestObject child = transaction.Select(typeof(IdentityChildTestObject), 1) as IdentityChildTestObject;

            Assert.AreEqual(1, child.Id);
            Assert.AreEqual("A", child.ObjData);
            Assert.AreEqual(3, child.Parent.Id);
            Assert.IsTrue(child.Parent.ChildObjects.Contains(child));

            Assert.AreEqual(count, DataUtil.CountRows("IdentityChildren"));
        }
Ejemplo n.º 8
0
        public void ShiftToNewParent()
        {
            int parentCount   = DataUtil.CountRows("IdentityParents");
            int childrenCount = DataUtil.CountRows("IdentityChildren");

            ObjectTransaction transaction1 = manager.BeginTransaction();

            IdentityParentTestObject parent1 = transaction1.Select(typeof(IdentityParentTestObject), 3) as IdentityParentTestObject;
            IdentityParentTestObject parent2 = transaction1.Create(typeof(IdentityParentTestObject)) as IdentityParentTestObject;

            parent2.ObjData = "X";

            IdentityChildTestObject child1 = transaction1.Select(typeof(IdentityChildTestObject), 1) as IdentityChildTestObject;

            Assert.AreEqual(1, child1.Id);
            Assert.AreEqual("A", child1.ObjData);
            Assert.AreEqual(3, child1.Parent.Id);
            Assert.IsTrue(child1.Parent.ChildObjects.Contains(child1));
            Assert.AreEqual(parent1, child1.Parent);
            Assert.IsTrue(parent1.ChildObjects.Contains(child1));
            Assert.IsFalse(parent2.ChildObjects.Contains(child1));

            child1.Parent = parent2;

            Assert.AreEqual(1, child1.Id);
            Assert.AreEqual("A", child1.ObjData);
            Assert.AreEqual(-1, child1.Parent.Id);
            Assert.IsTrue(child1.Parent.ChildObjects.Contains(child1));
            Assert.AreEqual(parent2, child1.Parent);
            Assert.IsTrue(parent2.ChildObjects.Contains(child1));
            Assert.IsFalse(parent1.ChildObjects.Contains(child1));

            transaction1.Commit();

            Assert.AreEqual(parentCount + 1, DataUtil.CountRows("IdentityParents"));
            Assert.AreEqual(childrenCount, DataUtil.CountRows("IdentityChildren"));

            ObjectTransaction transaction2 = manager.BeginTransaction();

            IdentityChildTestObject child2 = transaction2.Select(typeof(IdentityChildTestObject), 1) as IdentityChildTestObject;

            Assert.AreEqual(1, child2.Id);
            Assert.AreEqual("A", child2.ObjData);
            Assert.AreEqual("X", child2.Parent.ObjData);

            Assert.AreEqual(parentCount + 1, DataUtil.CountRows("IdentityParents"));
            Assert.AreEqual(childrenCount, DataUtil.CountRows("IdentityChildren"));
        }
Ejemplo n.º 9
0
        public void InsertParentChild()
        {
            int parentCount   = DataUtil.CountRows("IdentityParents");
            int childrenCount = DataUtil.CountRows("IdentityChildren");

            ObjectTransaction transaction = manager.BeginTransaction();

            IdentityParentTestObject parent = transaction.Create(typeof(IdentityParentTestObject)) as IdentityParentTestObject;

            parent.ObjData = "XXX";
            Assert.AreEqual(0, parent.ChildObjects.Count);
            for (int i = 0; i < 10; i++)
            {
                IdentityChildTestObject child = transaction.Create(typeof(IdentityChildTestObject)) as IdentityChildTestObject;
                child.ObjData = i.ToString();
                child.Parent  = parent;
            }
            Assert.AreEqual(10, parent.ChildObjects.Count);
            transaction.Commit();

            Assert.AreEqual(parentCount + 1, DataUtil.CountRows("IdentityParents"));
            Assert.AreEqual(childrenCount + 10, DataUtil.CountRows("IdentityChildren"));
        }