Esempio n. 1
0
 protected override void AddToCollection(ICollection collection, Person person)
 {
     PersistentBag concrete = collection as PersistentBag;
     if (concrete != null)
         concrete.Add(person);
     else
         ((ArrayList)collection).Add(person);
 }
        public void InvalidCollection()
        {
            // we are testing that work for Bag, List, Set PersistentCollections
            Person parent = CreateGrandparent();
            SavePerson(parent);

            using (ISession s = OpenSession())
            using (ITransaction tx = s.BeginTransaction())
            {
                Person p = s.CreateQuery("from Person p where p.Name = 'GP'")
                    .UniqueResult<Person>();

                NHibernateUtil.Initialize(p.Children);

                Assert.IsTrue(vengine.IsValid(p));

                for (int i = 0; i < 10; i++)
                {
                    Person child = new Person("CC" + i);
                    child.Parent = parent;
                    AddToCollection(p.Children, child);
                }

                Assert.IsFalse(vengine.IsValid(p));

                tx.Rollback();
            }

            using (ISession s = OpenSession())
            using (ITransaction tx = s.BeginTransaction())
            {
                Person p = s.CreateQuery("from Person p where p.Name = 'GP'")
                    .UniqueResult<Person>();

                NHibernateUtil.Initialize(p.Friends);

                Assert.IsTrue(vengine.IsValid(p));

                for (int i = 0; i < 3; i++)
                {
                    Person friend = new Person("FF" + i);
                    AddToCollection(p.Friends, friend);
                }

                Assert.IsFalse(vengine.IsValid(p));

                tx.Rollback();
            }

            CleanUp();
        }
Esempio n. 3
0
 protected override void AddToCollection(ICollection<Person> collection, Person person)
 {
     collection.Add(person);
 }
 private void SavePerson(Person parent)
 {
     using (ISession s = OpenSession())
     using (ITransaction tx = s.BeginTransaction())
     {
         s.Save(parent);
         tx.Commit();
     }
 }
        private Person CreateGrandparent()
        {
            Person parent = new Person("GP");
            parent.Children = GCreateCollection();

            for (int i = 0; i < 2; i++)
            {
                Person child = new Person("C" + i);
                child.Parent = parent;
                AddToCollection(parent.Children, child);

                child.Children = GCreateCollection();

                for (int j = 0; j < 3; j++)
                {
                    Person grandChild = new Person("C" + i + "-" + j);
                    grandChild.Parent = child;
                    AddToCollection(child.Children, grandChild);
                }
            }

            parent.Friends = CreateCollection();
            for (int i = 0; i < 3; i++)
            {
                Person friend = new Person("F" + i);
                AddToCollection(parent.Friends, friend);
            }
            return parent;
        }
 protected abstract void AddToCollection(ICollection<Person> collection, Person person);
 protected override void AddToCollection(ICollection collection, Person person)
 {
     ((ISet) collection).Add(person);
 }