Esempio n. 1
0
        public void DeleteParentAndChild()
        {
            CollectionListeners   listeners = new CollectionListeners(Sfi);
            IParentWithCollection parent    = CreateParentWithOneChild("parent", "child");
            IChild child = GetFirstChild(parent.Children);

            listeners.Clear();
            ISession     s  = OpenSession();
            ITransaction tx = s.BeginTransaction();

            parent = (IParentWithCollection)s.Get(parent.GetType(), parent.Id);
            IEntity e = child as IEntity;

            if (e != null)
            {
                child = (IChild)s.Get(child.GetType(), e.Id);
            }
            parent.RemoveChild(child);
            if (e != null)
            {
                s.Delete(child);
            }
            s.Delete(parent);
            tx.Commit();
            s.Close();
            int index = 0;

            CheckResult(listeners, listeners.InitializeCollection, parent, index++);
            ChildWithBidirectionalManyToMany childWithManyToMany = child as ChildWithBidirectionalManyToMany;

            if (childWithManyToMany != null)
            {
                CheckResult(listeners, listeners.InitializeCollection, childWithManyToMany, index++);
            }
            CheckResult(listeners, listeners.PreCollectionRemove, parent, index++);
            CheckResult(listeners, listeners.PostCollectionRemove, parent, index++);
            if (childWithManyToMany != null)
            {
                CheckResult(listeners, listeners.PreCollectionRemove, childWithManyToMany, index++);
                CheckResult(listeners, listeners.PostCollectionRemove, childWithManyToMany, index++);
            }
            CheckNumberOfResults(listeners, index);
        }
Esempio n. 2
0
        public void DeleteParentWithNullChildren()
        {
            CollectionListeners   listeners = new CollectionListeners(Sfi);
            IParentWithCollection parent    = CreateParentWithNullChildren("parent");

            listeners.Clear();
            ISession     s  = OpenSession();
            ITransaction tx = s.BeginTransaction();

            parent = (IParentWithCollection)s.Get(parent.GetType(), parent.Id);
            s.Delete(parent);
            tx.Commit();
            s.Close();
            int index = 0;

            CheckResult(listeners, listeners.InitializeCollection, parent, index++);
            CheckResult(listeners, listeners.PreCollectionRemove, parent, index++);
            CheckResult(listeners, listeners.PostCollectionRemove, parent, index++);
            CheckNumberOfResults(listeners, index);
        }
        public async Task DeleteParentWithNullChildrenAsync()
        {
            CollectionListeners   listeners = new CollectionListeners(Sfi);
            IParentWithCollection parent    = await(CreateParentWithNullChildrenAsync("parent"));

            listeners.Clear();
            ISession     s  = OpenSession();
            ITransaction tx = s.BeginTransaction();

            parent = (IParentWithCollection)await(s.GetAsync(parent.GetType(), parent.Id));
            await(s.DeleteAsync(parent));
            await(tx.CommitAsync());
            s.Close();
            int index = 0;

            CheckResult(listeners, listeners.InitializeCollection, parent, index++);
            CheckResult(listeners, listeners.PreCollectionRemove, parent, index++);
            CheckResult(listeners, listeners.PostCollectionRemove, parent, index++);
            CheckNumberOfResults(listeners, index);
        }
Esempio n. 4
0
        public void SaveParentEmptyChildren()
        {
            CollectionListeners   listeners = new CollectionListeners(Sfi);
            IParentWithCollection parent    = CreateParentWithNoChildren("parent");

            Assert.That(parent.Children.Count, Is.EqualTo(0));
            int index = 0;

            CheckResult(listeners, listeners.PreCollectionRecreate, parent, index++);
            CheckResult(listeners, listeners.PostCollectionRecreate, parent, index++);
            CheckNumberOfResults(listeners, index);
            listeners.Clear();
            using (ISession s = OpenSession())
            {
                using (ITransaction tx = s.BeginTransaction())
                {
                    parent = (IParentWithCollection)s.Get(parent.GetType(), parent.Id);
                    tx.Commit();
                }
            }
            Assert.That(parent.Children, Is.Not.Null);
            CheckNumberOfResults(listeners, 0);
        }
Esempio n. 5
0
        public void UpdateParentNoneToOneChildDiffCollection()
        {
            CollectionListeners   listeners = new CollectionListeners(Sfi);
            IParentWithCollection parent    = CreateParentWithNoChildren("parent");

            listeners.Clear();
            Assert.That(parent.Children.Count, Is.EqualTo(0));
            ISession     s  = OpenSession();
            ITransaction tx = s.BeginTransaction();

            parent = (IParentWithCollection)s.Get(parent.GetType(), parent.Id);
            ICollection <IChild> oldCollection = parent.Children;

            parent.NewChildren(CreateCollection());
            ChildWithBidirectionalManyToMany newChild = parent.AddChild("new") as ChildWithBidirectionalManyToMany;

            tx.Commit();
            s.Close();
            int index = 0;

            if (((IPersistentCollection)oldCollection).WasInitialized)
            {
                CheckResult(listeners, listeners.InitializeCollection, parent, oldCollection, index++);
            }
            CheckResult(listeners, listeners.PreCollectionRemove, parent, oldCollection, index++);
            CheckResult(listeners, listeners.PostCollectionRemove, parent, oldCollection, index++);
            if (newChild != null)
            {
                CheckResult(listeners, listeners.PreCollectionRecreate, newChild, index++);
                CheckResult(listeners, listeners.PostCollectionRecreate, newChild, index++);
            }

            CheckResult(listeners, listeners.PreCollectionRecreate, parent, index++);
            CheckResult(listeners, listeners.PostCollectionRecreate, parent, index++);
            CheckNumberOfResults(listeners, index);
        }
Esempio n. 6
0
 protected void CheckResult(CollectionListeners listeners, CollectionListeners.IListener listenerExpected,
                            IParentWithCollection parent, int index)
 {
     CheckResult(listeners, listenerExpected, parent, parent.Children, index);
 }
Esempio n. 7
0
        public void MoveCollectionToDifferentParentFlushMoveToDifferentParent()
        {
            CollectionListeners   listeners        = new CollectionListeners(Sfi);
            IParentWithCollection parent           = CreateParentWithOneChild("parent", "child");
            IParentWithCollection otherParent      = CreateParentWithOneChild("otherParent", "otherChild");
            IParentWithCollection otherOtherParent = CreateParentWithNoChildren("otherParent");

            listeners.Clear();
            ISession     s  = OpenSession();
            ITransaction tx = s.BeginTransaction();

            parent           = (IParentWithCollection)s.Get(parent.GetType(), parent.Id);
            otherParent      = (IParentWithCollection)s.Get(otherParent.GetType(), otherParent.Id);
            otherOtherParent = (IParentWithCollection)s.Get(otherOtherParent.GetType(), otherOtherParent.Id);
            ICollection <IChild> otherCollectionOrig      = otherParent.Children;
            ICollection <IChild> otherOtherCollectionOrig = otherOtherParent.Children;

            otherParent.NewChildren(parent.Children);
            parent.NewChildren(null);
            s.Flush();
            otherOtherParent.NewChildren(otherParent.Children);
            otherParent.NewChildren(null);
            tx.Commit();
            s.Close();
            int index = 0;
            ChildWithBidirectionalManyToMany otherChildOrig = null;

            if (((IPersistentCollection)otherCollectionOrig).WasInitialized)
            {
                CheckResult(listeners, listeners.InitializeCollection, otherParent, otherCollectionOrig, index++);
                otherChildOrig = GetFirstChild(otherCollectionOrig) as ChildWithBidirectionalManyToMany;
                if (otherChildOrig != null)
                {
                    CheckResult(listeners, listeners.InitializeCollection, otherChildOrig, index++);
                }
            }
            CheckResult(listeners, listeners.InitializeCollection, parent, otherOtherParent.Children, index++);
            ChildWithBidirectionalManyToMany otherOtherChild =
                GetFirstChild(otherOtherParent.Children) as ChildWithBidirectionalManyToMany;

            if (otherOtherChild != null)
            {
                CheckResult(listeners, listeners.InitializeCollection, otherOtherChild, index++);
            }
            CheckResult(listeners, listeners.PreCollectionRemove, parent, otherOtherParent.Children, index++);
            CheckResult(listeners, listeners.PostCollectionRemove, parent, otherOtherParent.Children, index++);
            CheckResult(listeners, listeners.PreCollectionRemove, otherParent, otherCollectionOrig, index++);
            CheckResult(listeners, listeners.PostCollectionRemove, otherParent, otherCollectionOrig, index++);
            if (otherOtherChild != null)
            {
                CheckResult(listeners, listeners.PreCollectionUpdate, otherChildOrig, index++);
                CheckResult(listeners, listeners.PostCollectionUpdate, otherChildOrig, index++);
                CheckResult(listeners, listeners.PreCollectionUpdate, otherOtherChild, index++);
                CheckResult(listeners, listeners.PostCollectionUpdate, otherOtherChild, index++);
            }
            CheckResult(listeners, listeners.PreCollectionRecreate, otherParent, otherOtherParent.Children, index++);
            CheckResult(listeners, listeners.PostCollectionRecreate, otherParent, otherOtherParent.Children, index++);
            if (((IPersistentCollection)otherOtherCollectionOrig).WasInitialized)
            {
                CheckResult(listeners, listeners.InitializeCollection, otherOtherParent, otherOtherCollectionOrig, index++);
            }
            CheckResult(listeners, listeners.PreCollectionRemove, otherParent, otherOtherParent.Children, index++);
            CheckResult(listeners, listeners.PostCollectionRemove, otherParent, otherOtherParent.Children, index++);
            CheckResult(listeners, listeners.PreCollectionRemove, otherOtherParent, otherOtherCollectionOrig, index++);
            CheckResult(listeners, listeners.PostCollectionRemove, otherOtherParent, otherOtherCollectionOrig, index++);
            if (otherOtherChild != null)
            {
                CheckResult(listeners, listeners.PreCollectionUpdate, otherOtherChild, index++);
                CheckResult(listeners, listeners.PostCollectionUpdate, otherOtherChild, index++);
            }

            CheckResult(listeners, listeners.PreCollectionRecreate, otherOtherParent, index++);
            CheckResult(listeners, listeners.PostCollectionRecreate, otherOtherParent, index++);
            // there should also be pre- and post-recreate collection events for parent, and otherParent
            // but thats broken now; this is covered in BrokenCollectionEventTest
            CheckNumberOfResults(listeners, index);
        }
		protected void CheckResult(CollectionListeners listeners, CollectionListeners.IListener listenerExpected,
		                           IParentWithCollection parent, int index)
		{
			CheckResult(listeners, listenerExpected, parent, parent.Children, index);
		}