Пример #1
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);
        }
Пример #2
0
        public void UpdateCircularReference()
        {
            int pA = DataUtil.CountRows("ParentA");
            int pB = DataUtil.CountRows("ParentB");
            int cA = DataUtil.CountRows("ChildA");

            ObjectTransaction transaction = manager.BeginTransaction();

            ParentBTestObject parentB = transaction.Select(typeof(ParentBTestObject), 45) as ParentBTestObject;

            parentB.ObjData = "Updated";

            ParentATestObject parentA = transaction.Select(typeof(ParentATestObject), 62) as ParentATestObject;

            parentA.ObjData = "Updated";

            ChildATestObject childA = transaction.Create(typeof(ChildATestObject)) as ChildATestObject;

            childA.ParentA = parentA;
            childA.ParentB = parentB;

            transaction.Commit();

            Assert.AreEqual(pA, DataUtil.CountRows("ParentA"));
            Assert.AreEqual(pB, DataUtil.CountRows("ParentB"));
            Assert.AreEqual(cA + 1, DataUtil.CountRows("ChildA"));
        }
Пример #3
0
        public void SelectValentines()
        {
            ObjectTransaction transaction = manager.BeginTransaction();

            Occasion valentines = transaction.Select(typeof(Occasion), 11) as Occasion;

            Query query = new Query(new SetCondition("OccasionMaps", new Condition("Occasion", Expression.Equal, valentines.Id)));

            ServerObjectCollection recipes = transaction.Select(typeof(Recipe), query);

            Assert.AreEqual(23, recipes.Count);
        }
Пример #4
0
        public void QueryUsedTwice()
        {
            ObjectTransaction transaction = manager.BeginTransaction();

            Query query = new Query(new Condition("Integer", Expression.In, 5, 100));

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

            Assert.AreEqual(2, objects1.Count);
            Assert.AreEqual(2, objects2.Count);
        }
Пример #5
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"));
        }
Пример #6
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"));
        }
Пример #7
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"));
        }
        public void UpdateValues()
        {
            int count = DataUtil.CountRows("NullableIntegers");

            ObjectTransaction transaction = manager.BeginTransaction();

            NullableIntegerTestObject test1 = transaction.Select(typeof(NullableIntegerTestObject), UpdateValue) as NullableIntegerTestObject;

            Assert.AreEqual(true, test1.Boolean);
            Assert.AreEqual(1, test1.TinyInt);
            Assert.AreEqual(1, test1.SmallInt);
            Assert.AreEqual(1, test1.Int);
            Assert.AreEqual(1, test1.BigInt);

            test1.Boolean  = false;
            test1.TinyInt  = 2;
            test1.SmallInt = 3;
            test1.Int      = 4;
            test1.BigInt   = 5;

            transaction.Commit();

            Assert.AreEqual(count, DataUtil.CountRows("NullableIntegers"));

            ObjectTransaction         transaction2 = manager.BeginTransaction();
            NullableIntegerTestObject test2        = transaction2.Select(typeof(NullableIntegerTestObject), UpdateValue) as NullableIntegerTestObject;

            Assert.AreEqual(false, test2.Boolean);
            Assert.AreEqual(2, test2.TinyInt);
            Assert.AreEqual(3, test2.SmallInt);
            Assert.AreEqual(4, test2.Int);
            Assert.AreEqual(5, test2.BigInt);

            Assert.AreEqual(count, DataUtil.CountRows("NullableIntegers"));
        }
Пример #9
0
        public void UpdateChild()
        {
            int parentCount   = DataUtil.CountRows("GuidParents");
            int childrenCount = DataUtil.CountRows("GuidChildren");

            ObjectTransaction transaction1 = manager.BeginTransaction();

            CascadeGuidChildTestObject child1 = transaction1.Select(typeof(CascadeGuidChildTestObject), "{0F455A52-C339-4A3C-9DCD-2620A5998295}") as CascadeGuidChildTestObject;

            Assert.AreEqual(new Guid("{0F455A52-C339-4A3C-9DCD-2620A5998295}"), child1.Id);
            Assert.AreEqual("1", child1.ObjData);
            Assert.AreEqual(new Guid("{C9ECFD97-F8BF-4075-A654-C62F6BD750D9}"), child1.Parent.Id);
            Assert.IsTrue(child1.Parent.ChildObjects.Contains(child1));

            child1.ObjData = "X";

            transaction1.Commit();

            Assert.AreEqual(parentCount, DataUtil.CountRows("GuidParents"));
            Assert.AreEqual(childrenCount, DataUtil.CountRows("GuidChildren"));

            ObjectTransaction transaction2 = manager.BeginTransaction();

            CascadeGuidChildTestObject child2 = transaction2.Select(typeof(CascadeGuidChildTestObject), "{0F455A52-C339-4A3C-9DCD-2620A5998295}") as CascadeGuidChildTestObject;

            Assert.AreEqual(new Guid("{0F455A52-C339-4A3C-9DCD-2620A5998295}"), child2.Id);
            Assert.AreEqual("X", child2.ObjData);
            Assert.AreEqual(new Guid("{C9ECFD97-F8BF-4075-A654-C62F6BD750D9}"), child2.Parent.Id);
            Assert.IsTrue(child2.Parent.ChildObjects.Contains(child2));

            Assert.AreEqual(parentCount, DataUtil.CountRows("GuidParents"));
            Assert.AreEqual(childrenCount, DataUtil.CountRows("GuidChildren"));
        }
Пример #10
0
        public void Delete()
        {
            int count = DataUtil.CountRows("IdentityKeys");

            ObjectTransaction transaction1 = manager.BeginTransaction();

            IdentityKeyTestObject test1 = transaction1.Create(typeof(IdentityKeyTestObject)) as IdentityKeyTestObject;

            Assert.AreEqual(-1, test1.Id);

            test1.ObjData = "blah";
            transaction1.Commit();

            Assert.AreEqual(count + 1, DataUtil.CountRows("IdentityKeys"));

            ObjectTransaction transaction2 = manager.BeginTransaction();

            IdentityKeyTestObject test2 = transaction2.Select(typeof(IdentityKeyTestObject), test1.Id) as IdentityKeyTestObject;

            Assert.AreEqual(test1.Id, test2.Id);
            Assert.AreEqual("blah", test2.ObjData);

            transaction2.Delete(test2);

            transaction2.Commit();

            Assert.AreEqual(count, DataUtil.CountRows("IdentityKeys"));
        }
Пример #11
0
        public void SelectParentWithChildren()
        {
            int count = DataUtil.CountRows("DefinedParents");

            ObjectTransaction transaction = manager.BeginTransaction();

            DefinedParentTestObject parent = transaction.Select(typeof(DefinedParentTestObject), "Key1") as DefinedParentTestObject;

            Assert.AreEqual("Key1", parent.Id);
            Assert.AreEqual("Data1", parent.ObjData);
            Assert.AreEqual(2, parent.ChildObjects.Count);

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

            Assert.AreEqual("ChildKey1", obj1.Id);
            Assert.AreEqual("CData1", obj1.ObjData);
            Assert.AreEqual("Key1", obj1.Parent.Id);
            Assert.AreEqual("Data1", obj1.Parent.ObjData);
            Assert.AreEqual(2, obj1.Parent.ChildObjects.Count);

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

            Assert.AreEqual("ChildKey2", obj2.Id);
            Assert.AreEqual("CData2", obj2.ObjData);
            Assert.AreEqual("Key1", obj2.Parent.Id);
            Assert.AreEqual("Data1", obj2.Parent.ObjData);
            Assert.AreEqual(2, obj2.Parent.ChildObjects.Count);

            Assert.AreEqual(count, DataUtil.CountRows("DefinedParents"));
        }
Пример #12
0
        public void AddChild()
        {
            int parentCount   = DataUtil.CountRows("DefinedParents");
            int childrenCount = DataUtil.CountRows("DefinedChildren");

            ObjectTransaction transaction = manager.BeginTransaction();

            DefinedParentTestObject parent = transaction.Select(typeof(DefinedParentTestObject), "Key2") as DefinedParentTestObject;

            Assert.AreEqual("Key2", parent.Id);
            Assert.AreEqual("Data2", parent.ObjData);
            Assert.AreEqual(0, parent.ChildObjects.Count);

            DefinedChildTestObject child = transaction.Create(typeof(DefinedChildTestObject), "CK1") as DefinedChildTestObject;

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

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

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

            transaction.Commit();

            Assert.AreEqual(parentCount, DataUtil.CountRows("DefinedParents"));
            Assert.AreEqual(childrenCount + 1, DataUtil.CountRows("DefinedChildren"));
        }
        public void DeleteRandomValues()
        {
            int count = DataUtil.CountRows("NullableDateTimes");

            ObjectTransaction          transaction1 = manager.BeginTransaction();
            NullableDateTimeTestObject test1        = transaction1.Create(typeof(NullableDateTimeTestObject)) as NullableDateTimeTestObject;

            test1.Date      = DateTime.Today.AddDays(-30);
            test1.SmallDate = DateTime.Today.AddMonths(1);

            transaction1.Commit();

            Assert.AreEqual(count + 1, DataUtil.CountRows("NullableDateTimes"));

            ObjectTransaction          transaction2 = manager.BeginTransaction();
            NullableDateTimeTestObject test2        = transaction2.Select(typeof(NullableDateTimeTestObject), test1.Id) as NullableDateTimeTestObject;

            Assert.AreEqual(DateTime.Today.AddDays(-30), test2.Date);
            Assert.AreEqual(DateTime.Today.AddMonths(1), test2.SmallDate);

            transaction2.Delete(test2);
            transaction2.Commit();

            Assert.AreEqual(count, DataUtil.CountRows("NullableDateTimes"));
        }
        public void UpdateValues()
        {
            int count = DataUtil.CountRows("NullableDateTimes");

            ObjectTransaction transaction = manager.BeginTransaction();

            NullableDateTimeTestObject test1 = transaction.Select(typeof(NullableDateTimeTestObject), UpdateValue) as NullableDateTimeTestObject;

            Assert.AreEqual(new DateTime(2003, 10, 23), test1.Date);
            Assert.AreEqual(new DateTime(2003, 10, 23), test1.SmallDate);

            test1.Date      = test1.Date.AddDays(-6);
            test1.SmallDate = test1.SmallDate.AddYears(1);

            transaction.Commit();

            Assert.AreEqual(count, DataUtil.CountRows("NullableDateTimes"));

            ObjectTransaction          transaction2 = manager.BeginTransaction();
            NullableDateTimeTestObject test2        = transaction2.Select(typeof(NullableDateTimeTestObject), UpdateValue) as NullableDateTimeTestObject;

            Assert.AreEqual(new DateTime(2003, 10, 17), test2.Date);
            Assert.AreEqual(new DateTime(2004, 10, 23), test2.SmallDate);

            Assert.AreEqual(count, DataUtil.CountRows("NullableDateTimes"));
        }
Пример #15
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);
        }
        public void InsertNullExplicitValues()
        {
            int count = DataUtil.CountRows("NullableIntegers");

            ObjectTransaction transaction1 = manager.BeginTransaction();

            NullableIntegerTestObject test1 = transaction1.Create(typeof(NullableIntegerTestObject)) as NullableIntegerTestObject;

            test1.Boolean  = false;
            test1.TinyInt  = 1;
            test1.SmallInt = -1;
            test1.Int      = -2;
            test1.BigInt   = -3;

            transaction1.Commit();

            Assert.AreEqual(count + 1, DataUtil.CountRows("NullableIntegers"));
            Assert.IsTrue(DataUtil.IsRowNull("NullableIntegers", "id", test1.Id));

            ObjectTransaction transaction2 = manager.BeginTransaction();

            NullableIntegerTestObject test2 = transaction2.Select(typeof(NullableIntegerTestObject), test1.Id) as NullableIntegerTestObject;


            Assert.AreEqual(false, test2.Boolean);
            Assert.AreEqual(1, test2.TinyInt);
            Assert.AreEqual(-1, test2.SmallInt);
            Assert.AreEqual(-2, test2.Int);
            Assert.AreEqual(-3, test2.BigInt);
        }
Пример #17
0
        public void Update()
        {
            int count = DataUtil.CountRows("DefinedKeys");

            ObjectTransaction transaction1 = manager.BeginTransaction();

            DefinedKeyTestObject test1 = transaction1.Select(typeof(DefinedKeyTestObject), "defined2") as DefinedKeyTestObject;

            Assert.AreEqual("defined2", test1.Id);
            Assert.AreEqual(2, test1.ObjData);

            test1.ObjData = 13;
            transaction1.Commit();

            Assert.AreEqual(count, DataUtil.CountRows("DefinedKeys"));

            ObjectTransaction transaction2 = manager.BeginTransaction();

            DefinedKeyTestObject test2 = transaction2.Select(typeof(DefinedKeyTestObject), "defined2") as DefinedKeyTestObject;

            Assert.AreEqual("defined2", test2.Id);
            Assert.AreEqual(13, test2.ObjData);

            Assert.AreEqual(count, DataUtil.CountRows("DefinedKeys"));
        }
Пример #18
0
        public void Delete()
        {
            int count = DataUtil.CountRows("DefinedKeys");

            ObjectTransaction transaction1 = manager.BeginTransaction();

            DefinedKeyTestObject test1 = transaction1.Create(typeof(DefinedKeyTestObject), "defined10") as DefinedKeyTestObject;

            Assert.AreEqual("defined10", test1.Id);

            test1.ObjData = 101;
            transaction1.Commit();

            Assert.AreEqual(count + 1, DataUtil.CountRows("DefinedKeys"));

            ObjectTransaction transaction2 = manager.BeginTransaction();

            DefinedKeyTestObject test2 = transaction2.Select(typeof(DefinedKeyTestObject), "defined10") as DefinedKeyTestObject;

            Assert.AreEqual("defined10", test2.Id);
            Assert.AreEqual(101, test2.ObjData);

            transaction2.Delete(test2);

            transaction2.Commit();

            Assert.AreEqual(count, DataUtil.CountRows("DefinedKeys"));
        }
Пример #19
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"));
        }
Пример #20
0
        public void UpdateRandomValues()
        {
            Random random = new Random();

            int count = DataUtil.CountRows("Binary");

            ObjectTransaction transaction = manager.BeginTransaction();

            BinaryTestObject test1 = transaction.Select(typeof(BinaryTestObject), UpdateValue) as BinaryTestObject;

            test1.Binary = new Byte[8];
            random.NextBytes(test1.Binary);

            byte b = test1.Binary[3];

            test1.VarBinary[2] = 16;
            test1.Image[1]     = 69;

            transaction.Commit();

            Assert.AreEqual(count, DataUtil.CountRows("Binary"));

            ObjectTransaction transaction2 = manager.BeginTransaction();
            BinaryTestObject  test2        = transaction2.Select(typeof(BinaryTestObject), UpdateValue) as BinaryTestObject;

            Assert.AreEqual(b, test2.Binary[3]);
            Assert.AreEqual(16, test2.VarBinary[2]);
            Assert.AreEqual(69, test2.Image[1]);

            transaction2.Commit();

            Assert.AreEqual(count, DataUtil.CountRows("Binary"));
        }
Пример #21
0
        public void UpdateChild()
        {
            int parentCount   = DataUtil.CountRows("DefinedParents");
            int childrenCount = DataUtil.CountRows("DefinedChildren");

            ObjectTransaction transaction1 = manager.BeginTransaction();

            DefinedChildTestObject child1 = transaction1.Select(typeof(DefinedChildTestObject), "ChildKey1") as DefinedChildTestObject;

            Assert.AreEqual("ChildKey1", child1.Id);
            Assert.AreEqual("CData1", child1.ObjData);
            Assert.AreEqual("Key1", child1.Parent.Id);
            Assert.IsTrue(child1.Parent.ChildObjects.Contains(child1));

            child1.ObjData = "X";

            transaction1.Commit();

            Assert.AreEqual(parentCount, DataUtil.CountRows("DefinedParents"));
            Assert.AreEqual(childrenCount, DataUtil.CountRows("DefinedChildren"));

            ObjectTransaction transaction2 = manager.BeginTransaction();

            DefinedChildTestObject child2 = transaction2.Select(typeof(DefinedChildTestObject), "ChildKey1") as DefinedChildTestObject;

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

            Assert.AreEqual(parentCount, DataUtil.CountRows("DefinedParents"));
            Assert.AreEqual(childrenCount, DataUtil.CountRows("DefinedChildren"));
        }
Пример #22
0
        public void DeleteRandomValues()
        {
            Random random = new Random();

            int count = DataUtil.CountRows("Binary");

            ObjectTransaction transaction = manager.BeginTransaction();

            BinaryTestObject test1 = transaction.Create(typeof(BinaryTestObject)) as BinaryTestObject;

            test1.Binary = new byte[8];
            random.NextBytes(test1.Binary);

            test1.VarBinary = new byte[5];
            random.NextBytes(test1.VarBinary);

            test1.Image = new byte[1024];
            random.NextBytes(test1.Image);

            transaction.Commit();

            Assert.AreEqual(count + 1, DataUtil.CountRows("Binary"));

            ObjectTransaction transaction2 = manager.BeginTransaction();
            BinaryTestObject  test2        = transaction2.Select(typeof(BinaryTestObject), test1.Id) as BinaryTestObject;

            Assert.AreEqual(8, test2.Binary.Length);
            Assert.AreEqual(5, test2.VarBinary.Length);
            Assert.AreEqual(1024, test2.Image.Length);

            transaction2.Delete(test2);
            transaction2.Commit();

            Assert.AreEqual(count, DataUtil.CountRows("Binary"));
        }
Пример #23
0
        public void Update()
        {
            int count = DataUtil.CountRows("IdentityKeys");

            ObjectTransaction transaction1 = manager.BeginTransaction();

            IdentityKeyTestObject test1 = transaction1.Select(typeof(IdentityKeyTestObject), 2) as IdentityKeyTestObject;

            Assert.AreEqual(2, test1.Id);
            Assert.AreEqual("data2", test1.ObjData);

            test1.ObjData = "datatest";
            transaction1.Commit();

            Assert.AreEqual(count, DataUtil.CountRows("IdentityKeys"));

            ObjectTransaction transaction2 = manager.BeginTransaction();

            IdentityKeyTestObject test2 = transaction2.Select(typeof(IdentityKeyTestObject), 2) as IdentityKeyTestObject;

            Assert.AreEqual(2, test2.Id);
            Assert.AreEqual("datatest", test2.ObjData);

            Assert.AreEqual(count, DataUtil.CountRows("IdentityKeys"));
        }
Пример #24
0
        public void SelectMinValues()
        {
            int count = DataUtil.CountRows("Binary");

            ObjectTransaction transaction = manager.BeginTransaction();

            BinaryTestObject test = transaction.Select(typeof(BinaryTestObject), ZeroValues) as BinaryTestObject;

            Assert.AreEqual(new Guid(ZeroValues), test.Id);

            Assert.AreEqual(8, test.Binary.Length);
            foreach (byte b in test.Binary)
            {
                Assert.AreEqual(Byte.MinValue, b);
            }

            Assert.AreEqual(16, test.VarBinary.Length);
            foreach (byte b in test.VarBinary)
            {
                Assert.AreEqual(Byte.MinValue, b);
            }

            Assert.AreEqual(32, test.Image.Length);
            foreach (byte b in test.Image)
            {
                Assert.AreEqual(Byte.MinValue, b);
            }

            Assert.AreEqual(count, DataUtil.CountRows("Binary"));
        }
Пример #25
0
        public void AddChild()
        {
            int parentCount   = DataUtil.CountRows("GuidParents");
            int childrenCount = DataUtil.CountRows("GuidChildren");

            ObjectTransaction transaction = manager.BeginTransaction();

            CascadeGuidParentTestObject parent = transaction.Select(typeof(CascadeGuidParentTestObject), "{F9643D1E-9FAC-4C01-B535-D2B0D2F582E7}") as CascadeGuidParentTestObject;

            Assert.AreEqual(new Guid("{F9643D1E-9FAC-4C01-B535-D2B0D2F582E7}"), parent.Id);
            Assert.AreEqual("Y", parent.ObjData);
            Assert.AreEqual(0, parent.ChildObjects.Count);

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

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

            Assert.AreEqual(new Guid("{F9643D1E-9FAC-4C01-B535-D2B0D2F582E7}"), child.Parent.Id);
            Assert.AreEqual(1, parent.ChildObjects.Count);

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

            transaction.Commit();

            Assert.AreEqual(parentCount, DataUtil.CountRows("GuidParents"));
            Assert.AreEqual(childrenCount + 1, DataUtil.CountRows("GuidChildren"));
        }
Пример #26
0
        public void Delete()
        {
            int count = DataUtil.CountRows("GuidKeys");

            ObjectTransaction transaction1 = manager.BeginTransaction();

            GuidKeyTestObject test1 = transaction1.Create(typeof(GuidKeyTestObject)) as GuidKeyTestObject;

            test1.ObjData = 169;
            transaction1.Commit();

            Assert.AreEqual(count + 1, DataUtil.CountRows("GuidKeys"));

            ObjectTransaction transaction2 = manager.BeginTransaction();

            GuidKeyTestObject test2 = transaction2.Select(typeof(GuidKeyTestObject), test1.Id) as GuidKeyTestObject;

            Assert.AreEqual(test1.Id, test2.Id);
            Assert.AreEqual(169, test2.ObjData);

            transaction2.Delete(test2);

            transaction2.Commit();

            Assert.AreEqual(count, DataUtil.CountRows("GuidKeys"));
        }
Пример #27
0
        public void SelectParentWithChildren()
        {
            int count = DataUtil.CountRows("GuidParents");

            ObjectTransaction transaction = manager.BeginTransaction();

            CascadeGuidParentTestObject parent = transaction.Select(typeof(CascadeGuidParentTestObject), "{C9ECFD97-F8BF-4075-A654-C62F6BD750D9}") as CascadeGuidParentTestObject;

            Assert.AreEqual(new Guid("{C9ECFD97-F8BF-4075-A654-C62F6BD750D9}"), parent.Id);
            Assert.AreEqual("X", parent.ObjData);
            Assert.AreEqual(2, parent.ChildObjects.Count);

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

            Assert.AreEqual(new Guid("{0F455A52-C339-4A3C-9DCD-2620A5998295}"), obj1.Id);
            Assert.AreEqual("1", obj1.ObjData);
            Assert.AreEqual(new Guid("{C9ECFD97-F8BF-4075-A654-C62F6BD750D9}"), obj1.Parent.Id);
            Assert.AreEqual("X", obj1.Parent.ObjData);
            Assert.AreEqual(2, obj1.Parent.ChildObjects.Count);

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

            Assert.AreEqual(new Guid("{D513049E-13CC-42DA-83D7-4848AF7E3D0E}"), obj2.Id);
            Assert.AreEqual("0", obj2.ObjData);
            Assert.AreEqual(new Guid("{C9ECFD97-F8BF-4075-A654-C62F6BD750D9}"), obj2.Parent.Id);
            Assert.AreEqual("X", obj2.Parent.ObjData);
            Assert.AreEqual(2, obj2.Parent.ChildObjects.Count);

            Assert.AreEqual(count, DataUtil.CountRows("GuidParents"));
        }
        public void DeleteRandomValues()
        {
            int count = DataUtil.CountRows("NullableIntegers");

            ObjectTransaction         transaction1 = manager.BeginTransaction();
            NullableIntegerTestObject test1        = transaction1.Create(typeof(NullableIntegerTestObject)) as NullableIntegerTestObject;

            test1.Boolean  = true;
            test1.TinyInt  = 5;
            test1.Int      = 12457;
            test1.SmallInt = 124;
            test1.BigInt   = 1234567;
            transaction1.Commit();

            Assert.AreEqual(count + 1, DataUtil.CountRows("NullableIntegers"));

            ObjectTransaction         transaction2 = manager.BeginTransaction();
            NullableIntegerTestObject test2        = transaction2.Select(typeof(NullableIntegerTestObject), test1.Id) as NullableIntegerTestObject;

            Assert.AreEqual(true, test2.Boolean);
            Assert.AreEqual(5, test2.TinyInt);
            Assert.AreEqual(124, test2.SmallInt);
            Assert.AreEqual(12457, test1.Int);
            Assert.AreEqual(1234567, test2.BigInt);

            transaction2.Delete(test2);
            transaction2.Commit();

            Assert.AreEqual(count, DataUtil.CountRows("NullableIntegers"));
        }
Пример #29
0
        public void Update()
        {
            int  count = DataUtil.CountRows("GuidKeys");
            Guid id    = new Guid("{EEDD8FC4-9081-4573-B7E6-B3930FBDAA3C}");

            ObjectTransaction transaction1 = manager.BeginTransaction();

            GuidKeyTestObject test1 = transaction1.Select(typeof(GuidKeyTestObject), id) as GuidKeyTestObject;

            Assert.AreEqual(id, test1.Id);
            Assert.AreEqual(2, test1.ObjData);

            test1.ObjData = 13;
            transaction1.Commit();

            Assert.AreEqual(count, DataUtil.CountRows("GuidKeys"));

            ObjectTransaction transaction2 = manager.BeginTransaction();

            GuidKeyTestObject test2 = transaction2.Select(typeof(GuidKeyTestObject), id) as GuidKeyTestObject;

            Assert.AreEqual(test1.Id, test2.Id);
            Assert.AreEqual(13, test2.ObjData);

            Assert.AreEqual(count, DataUtil.CountRows("GuidKeys"));
        }
        public void DeleteRandomValues()
        {
            int count = DataUtil.CountRows("FloatingPointNumbers");

            ObjectTransaction             transaction1 = manager.BeginTransaction();
            FloatingPointNumberTestObject test1        = transaction1.Create(typeof(FloatingPointNumberTestObject)) as FloatingPointNumberTestObject;

            test1.Decimal    = 1.565m;
            test1.Numeric    = 565m;
            test1.Float      = -1.25;
            test1.Real       = 126;
            test1.Money      = -65.65m;
            test1.SmallMoney = 23.545m;

            transaction1.Commit();

            Assert.AreEqual(count + 1, DataUtil.CountRows("FloatingPointNumbers"));

            ObjectTransaction             transaction2 = manager.BeginTransaction();
            FloatingPointNumberTestObject test2        = transaction2.Select(typeof(FloatingPointNumberTestObject), test1.Id) as FloatingPointNumberTestObject;

            Assert.AreEqual(2, test2.Decimal);
            Assert.AreEqual(565, test2.Numeric);
            Assert.AreEqual(-1.25, test2.Float);
            Assert.AreEqual(126, test2.Real);
            Assert.AreEqual(-65.65m, test2.Money);
            Assert.AreEqual(23.545m, test2.SmallMoney);

            transaction2.Delete(test2);
            transaction2.Commit();

            Assert.AreEqual(count, DataUtil.CountRows("FloatingPointNumbers"));
        }