Пример #1
0
        public void PersistAndFind()
        {
            var bindingContext = new BindingContext();

            Assert.IsFalse(bindingContext.StrictExplicitColumnBinding);
            Assert.IsFalse(bindingContext.StrictExplicitKeyBinding);
            Assert.IsFalse(bindingContext.StrictExplicitTableBinding);

            bindingContext.StrictExplicitColumnBinding = true;

            Assert.IsTrue(bindingContext.RegisterColumnBinding(typeof(EntityA), new ColumnBindingEntityA()));
            Assert.IsFalse(bindingContext.RegisterColumnBinding(typeof(EntityA), new ColumnBindingEntityA()));
            Assert.IsTrue(bindingContext.RegisterColumnBinding(typeof(EntityB), new ColumnBinding("b", "qb")));
            Assert.IsTrue(bindingContext.RegisterColumnBinding(typeof(EntityC1), new ColumnBinding("c", "1")));
            Assert.IsTrue(bindingContext.RegisterColumnBinding(typeof(EntityC2), new ColumnBinding("c", "2")));

            var eb1 = new EntityB();

            TestBase.TestSerialization(eb1);

            var eb2 = new EntityB {
                A = new EntityA()
            };

            TestBase.TestSerialization(eb2);

            var ec1 = new EntityC1 {
                A = new EntityA()
            };

            TestBase.TestSerialization(ec1);

            var ec2 = new EntityC2 {
                A = new EntityA()
            };

            TestBase.TestSerialization(ec2);

            using (var em = Emf.CreateEntityManager(bindingContext))
            {
                Assert.IsTrue(em.IsTypeDeclared <EntityA>());
                Assert.IsTrue(em.IsTypeDeclared <EntityB>());
                Assert.IsTrue(em.IsTypeDeclared <EntityC1>());
                Assert.IsTrue(em.IsTypeDeclared <EntityC2>());

                em.Configuration.Binding.StrictExplicitColumnBinding = true;

                em.Persist(eb1);
                Assert.IsNotNull(eb1.Key);
                Assert.IsFalse(string.IsNullOrEmpty(eb1.Key.Row));
                Assert.AreEqual("b", eb1.Key.ColumnFamily);
                Assert.AreEqual("qb", eb1.Key.ColumnQualifier);

                em.Persist(eb2);
                Assert.IsNotNull(eb2.Key);
                Assert.IsFalse(string.IsNullOrEmpty(eb2.Key.Row));
                Assert.AreEqual("b", eb2.Key.ColumnFamily);
                Assert.AreEqual("qb", eb2.Key.ColumnQualifier);

                Assert.IsNotNull(eb2.A.Key);
                Assert.IsFalse(string.IsNullOrEmpty(eb2.A.Key.Row));
                Assert.AreEqual("a", eb2.A.Key.ColumnFamily);
                Assert.AreEqual("qa", eb2.A.Key.ColumnQualifier);

                em.Persist(ec1);
                Assert.IsNotNull(ec1.Key);
                Assert.IsFalse(string.IsNullOrEmpty(ec1.Key.Row));
                Assert.AreEqual("c", ec1.Key.ColumnFamily);
                Assert.AreEqual("1", ec1.Key.ColumnQualifier);

                em.Persist(ec2);
                Assert.IsNotNull(ec2.Key);
                Assert.IsFalse(string.IsNullOrEmpty(ec2.Key.Row));
                Assert.AreEqual("c", ec2.Key.ColumnFamily);
                Assert.AreEqual("2", ec2.Key.ColumnQualifier);
            }

            using (var em = Emf.CreateEntityManager(bindingContext))
            {
                var _eb1 = em.Find <EntityB>(eb1.Key);
                Assert.AreEqual(eb1, _eb1);

                var _ea2 = em.Find <EntityA>(eb2.A.Key);
                Assert.AreEqual(eb2.A, _ea2);

                var _eb2 = em.Find <EntityB>(eb2.Key);
                Assert.AreEqual(eb2, _eb2);

                var _ec1 = em.Find <EntityC1>(ec1.Key);
                Assert.AreEqual(ec1, _ec1);

                var _ec2 = em.Find <EntityC2>(ec2.Key);
                Assert.AreEqual(ec2, _ec2);

                var ecl = em.Fetch <EntityC>().ToList();
                Assert.AreEqual(2, ecl.Count);
                Assert.IsTrue(ecl.Contains(_ec1));
                Assert.IsTrue(ecl.Contains(_ec2));
            }

            Assert.IsTrue(bindingContext.UnregisterColumnBinding(typeof(EntityA)));
            Assert.IsFalse(bindingContext.UnregisterColumnBinding(typeof(EntityA)));
            Assert.IsTrue(bindingContext.UnregisterColumnBinding(typeof(EntityB)));
            Assert.IsTrue(bindingContext.UnregisterColumnBinding(typeof(EntityC1)));
            Assert.IsTrue(bindingContext.UnregisterColumnBinding(typeof(EntityC2)));
        }
Пример #2
0
        public void PersistAndFind()
        {
            var eb1 = new EntityB();
            TestBase.TestSerialization(eb1);

            var eb2 = new EntityB { A = new EntityA() };
            TestBase.TestSerialization(eb2);

            using (var em = Emf.CreateEntityManager())
            {
                em.Persist(eb1);
                Assert.IsNotNull(eb1.Key);
                Assert.IsFalse(string.IsNullOrEmpty(eb1.Key.Row));
                Assert.IsFalse(string.IsNullOrEmpty(eb1.Key.ColumnFamily));
                Assert.IsTrue(string.IsNullOrEmpty(eb1.Key.ColumnQualifier));

                em.Persist(eb2);
                Assert.IsNotNull(eb2.Key);
                Assert.IsFalse(string.IsNullOrEmpty(eb2.Key.Row));
                Assert.IsFalse(string.IsNullOrEmpty(eb2.Key.ColumnFamily));
                Assert.IsTrue(string.IsNullOrEmpty(eb2.Key.ColumnQualifier));

                Assert.IsFalse(string.IsNullOrEmpty(eb2.A.RowKey));
            }

            using (var em = Emf.CreateEntityManager())
            {
                var _eb1 = em.Find<EntityB>(eb1.Key);
                Assert.AreEqual(eb1, _eb1);

                var _ea2 = em.Find<EntityA>(eb2.A.RowKey);
                Assert.AreEqual(eb2.A, _ea2);

                var _eb2 = em.Find<EntityB>(eb2.Key);
                Assert.AreEqual(eb2, _eb2);
            }

            var ec1 = new EntityC1();
            var ec2 = new EntityC2 { C1 = new EntityC1() };

            using (var em = Emf.CreateEntityManager())
            {
                em.Persist(ec1);
                Assert.IsNotNull(ec1.Key);
                Assert.IsFalse(string.IsNullOrEmpty(ec1.Key.Row));
                Assert.IsFalse(string.IsNullOrEmpty(ec1.Key.ColumnFamily));
                Assert.IsFalse(string.IsNullOrEmpty(ec1.Key.ColumnQualifier));

                em.Persist(ec2);
                Assert.IsNotNull(ec2.Key);
                Assert.IsFalse(string.IsNullOrEmpty(ec2.Key.Row));
                Assert.IsFalse(string.IsNullOrEmpty(ec2.Key.ColumnFamily));
                Assert.IsFalse(string.IsNullOrEmpty(ec2.Key.ColumnQualifier));

                Assert.IsNotNull(ec2.C1);
                Assert.IsFalse(string.IsNullOrEmpty(ec2.C1.Key.Row));
                Assert.IsFalse(string.IsNullOrEmpty(ec2.C1.Key.ColumnFamily));
                Assert.IsFalse(string.IsNullOrEmpty(ec2.C1.Key.ColumnQualifier));
            }

            using (var em = Emf.CreateEntityManager())
            {
                var _ec1 = em.Find<EntityC1>(ec1.Key);
                Assert.AreEqual(ec1, _ec1);

                var _ec12 = em.Find<EntityC1>(ec2.C1.Key);
                Assert.AreEqual(ec2.C1, _ec12);

                var _ec2 = em.Find<EntityC2>(ec2.Key);
                Assert.AreEqual(ec2, _ec2);
            }
        }
Пример #3
0
        public void PersistAndFind()
        {
            var bindingContext = new BindingContext();
            Assert.IsFalse(bindingContext.StrictExplicitColumnBinding);
            Assert.IsFalse(bindingContext.StrictExplicitKeyBinding);
            Assert.IsFalse(bindingContext.StrictExplicitTableBinding);

            bindingContext.StrictExplicitColumnBinding = true;

            Assert.IsTrue(bindingContext.RegisterColumnBinding(typeof(EntityA), new ColumnBindingEntityA()));
            Assert.IsFalse(bindingContext.RegisterColumnBinding(typeof(EntityA), new ColumnBindingEntityA()));
            Assert.IsTrue(bindingContext.RegisterColumnBinding(typeof(EntityB), new ColumnBinding("b", "qb")));
            Assert.IsTrue(bindingContext.RegisterColumnBinding(typeof(EntityC1), new ColumnBinding("c", "1")));
            Assert.IsTrue(bindingContext.RegisterColumnBinding(typeof(EntityC2), new ColumnBinding("c", "2")));

            var eb1 = new EntityB();
            TestBase.TestSerialization(eb1);

            var eb2 = new EntityB { A = new EntityA() };
            TestBase.TestSerialization(eb2);

            var ec1 = new EntityC1 { A = new EntityA() };
            TestBase.TestSerialization(ec1);

            var ec2 = new EntityC2 { A = new EntityA() };
            TestBase.TestSerialization(ec2);

            using (var em = Emf.CreateEntityManager(bindingContext))
            {
                Assert.IsTrue(em.IsTypeDeclared<EntityA>());
                Assert.IsTrue(em.IsTypeDeclared<EntityB>());
                Assert.IsTrue(em.IsTypeDeclared<EntityC1>());
                Assert.IsTrue(em.IsTypeDeclared<EntityC2>());

                em.Configuration.Binding.StrictExplicitColumnBinding = true;

                em.Persist(eb1);
                Assert.IsNotNull(eb1.Key);
                Assert.IsFalse(string.IsNullOrEmpty(eb1.Key.Row));
                Assert.AreEqual("b", eb1.Key.ColumnFamily);
                Assert.AreEqual("qb", eb1.Key.ColumnQualifier);

                em.Persist(eb2);
                Assert.IsNotNull(eb2.Key);
                Assert.IsFalse(string.IsNullOrEmpty(eb2.Key.Row));
                Assert.AreEqual("b", eb2.Key.ColumnFamily);
                Assert.AreEqual("qb", eb2.Key.ColumnQualifier);

                Assert.IsNotNull(eb2.A.Key);
                Assert.IsFalse(string.IsNullOrEmpty(eb2.A.Key.Row));
                Assert.AreEqual("a", eb2.A.Key.ColumnFamily);
                Assert.AreEqual("qa", eb2.A.Key.ColumnQualifier);

                em.Persist(ec1);
                Assert.IsNotNull(ec1.Key);
                Assert.IsFalse(string.IsNullOrEmpty(ec1.Key.Row));
                Assert.AreEqual("c", ec1.Key.ColumnFamily);
                Assert.AreEqual("1", ec1.Key.ColumnQualifier);

                em.Persist(ec2);
                Assert.IsNotNull(ec2.Key);
                Assert.IsFalse(string.IsNullOrEmpty(ec2.Key.Row));
                Assert.AreEqual("c", ec2.Key.ColumnFamily);
                Assert.AreEqual("2", ec2.Key.ColumnQualifier);
            }

            using (var em = Emf.CreateEntityManager(bindingContext))
            {
                var _eb1 = em.Find<EntityB>(eb1.Key);
                Assert.AreEqual(eb1, _eb1);

                var _ea2 = em.Find<EntityA>(eb2.A.Key);
                Assert.AreEqual(eb2.A, _ea2);

                var _eb2 = em.Find<EntityB>(eb2.Key);
                Assert.AreEqual(eb2, _eb2);

                var _ec1 = em.Find<EntityC1>(ec1.Key);
                Assert.AreEqual(ec1, _ec1);

                var _ec2 = em.Find<EntityC2>(ec2.Key);
                Assert.AreEqual(ec2, _ec2);

                var ecl = em.Fetch<EntityC>().ToList();
                Assert.AreEqual(2, ecl.Count);
                Assert.IsTrue(ecl.Contains(_ec1));
                Assert.IsTrue(ecl.Contains(_ec2));
            }

            Assert.IsTrue(bindingContext.UnregisterColumnBinding(typeof(EntityA)));
            Assert.IsFalse(bindingContext.UnregisterColumnBinding(typeof(EntityA)));
            Assert.IsTrue(bindingContext.UnregisterColumnBinding(typeof(EntityB)));
            Assert.IsTrue(bindingContext.UnregisterColumnBinding(typeof(EntityC1)));
            Assert.IsTrue(bindingContext.UnregisterColumnBinding(typeof(EntityC2)));
        }
Пример #4
0
        public void PersistAndFind()
        {
            var eb1 = new EntityB();

            TestBase.TestSerialization(eb1);

            var eb2 = new EntityB {
                A = new EntityA()
            };

            TestBase.TestSerialization(eb2);

            using (var em = Emf.CreateEntityManager())
            {
                em.Persist(eb1);
                Assert.IsNotNull(eb1.Key);
                Assert.IsFalse(string.IsNullOrEmpty(eb1.Key.Row));
                Assert.IsFalse(string.IsNullOrEmpty(eb1.Key.ColumnFamily));
                Assert.IsTrue(string.IsNullOrEmpty(eb1.Key.ColumnQualifier));

                em.Persist(eb2);
                Assert.IsNotNull(eb2.Key);
                Assert.IsFalse(string.IsNullOrEmpty(eb2.Key.Row));
                Assert.IsFalse(string.IsNullOrEmpty(eb2.Key.ColumnFamily));
                Assert.IsTrue(string.IsNullOrEmpty(eb2.Key.ColumnQualifier));

                Assert.IsFalse(string.IsNullOrEmpty(eb2.A.RowKey));
            }

            using (var em = Emf.CreateEntityManager())
            {
                var _eb1 = em.Find <EntityB>(eb1.Key);
                Assert.AreEqual(eb1, _eb1);

                var _ea2 = em.Find <EntityA>(eb2.A.RowKey);
                Assert.AreEqual(eb2.A, _ea2);

                var _eb2 = em.Find <EntityB>(eb2.Key);
                Assert.AreEqual(eb2, _eb2);
            }

            var ec1 = new EntityC1();
            var ec2 = new EntityC2 {
                C1 = new EntityC1()
            };

            using (var em = Emf.CreateEntityManager())
            {
                em.Persist(ec1);
                Assert.IsNotNull(ec1.Key);
                Assert.IsFalse(string.IsNullOrEmpty(ec1.Key.Row));
                Assert.IsFalse(string.IsNullOrEmpty(ec1.Key.ColumnFamily));
                Assert.IsFalse(string.IsNullOrEmpty(ec1.Key.ColumnQualifier));

                em.Persist(ec2);
                Assert.IsNotNull(ec2.Key);
                Assert.IsFalse(string.IsNullOrEmpty(ec2.Key.Row));
                Assert.IsFalse(string.IsNullOrEmpty(ec2.Key.ColumnFamily));
                Assert.IsFalse(string.IsNullOrEmpty(ec2.Key.ColumnQualifier));

                Assert.IsNotNull(ec2.C1);
                Assert.IsFalse(string.IsNullOrEmpty(ec2.C1.Key.Row));
                Assert.IsFalse(string.IsNullOrEmpty(ec2.C1.Key.ColumnFamily));
                Assert.IsFalse(string.IsNullOrEmpty(ec2.C1.Key.ColumnQualifier));
            }

            using (var em = Emf.CreateEntityManager())
            {
                var _ec1 = em.Find <EntityC1>(ec1.Key);
                Assert.AreEqual(ec1, _ec1);

                var _ec12 = em.Find <EntityC1>(ec2.C1.Key);
                Assert.AreEqual(ec2.C1, _ec12);

                var _ec2 = em.Find <EntityC2>(ec2.Key);
                Assert.AreEqual(ec2, _ec2);
            }
        }