public async Task GetChildMakeReadOnlyThenMergeDetachedChildWithNewParentAsync()
        {
            VersionedNode child = new VersionedNode("child", "child");

            using (ISession s = OpenSession())
            {
                s.BeginTransaction();
                await(s.PersistAsync(child));
                await(s.Transaction.CommitAsync());
            }

            ClearCounts();

            child.Name = "new child name";
            VersionedNode parent = new VersionedNode("parent", "parent");

            parent.AddChild(child);

            using (ISession s = OpenSession())
            {
                s.BeginTransaction();
                VersionedNode childManaged = await(s.GetAsync <VersionedNode>(child.Id));
                s.SetReadOnly(childManaged, true);
                VersionedNode childMerged = (VersionedNode)await(s.MergeAsync(child));
                Assert.That(childManaged, Is.SameAs(childMerged));
                await(s.Transaction.CommitAsync());
            }

            AssertUpdateCount(0);             // NH-specific: Hibernate issues a separate UPDATE for the version number
            AssertInsertCount(1);
            ClearCounts();

            using (ISession s = OpenSession())
            {
                s.BeginTransaction();
                parent = await(s.GetAsync <VersionedNode>(parent.Id));
                child  = await(s.GetAsync <VersionedNode>(child.Id));
                Assert.That(child.Name, Is.EqualTo("child"));
                Assert.That(child.Parent, Is.Null);
                Assert.That(child.Version, Is.EqualTo(1));
                Assert.That(parent, Is.Not.Null);
                Assert.That(parent.Children.Count, Is.EqualTo(0));
                Assert.That(parent.Version, Is.EqualTo(1));
                // NH-specific: Hibernate incorrectly increments version number, NH does not
                s.SetReadOnly(parent, true);
                s.SetReadOnly(child, true);
                await(s.DeleteAsync(parent));
                await(s.DeleteAsync(child));
                await(s.Transaction.CommitAsync());
            }

            AssertUpdateCount(0);
            AssertDeleteCount(2);
        }
Exemple #2
0
        public void MergeDetachedChildWithNewParentCommitWithReadOnlyChild()
        {
            VersionedNode child = new VersionedNode("child", "child");

            using (ISession s = OpenSession())
            {
                s.BeginTransaction();
                s.Persist(child);
                s.Transaction.Commit();
            }

            ClearCounts();

            child.Name = "new child name";
            VersionedNode parent = new VersionedNode("parent", "parent");

            parent.AddChild(child);

            using (ISession s = OpenSession())
            {
                s.BeginTransaction();
                child = (VersionedNode)s.Merge(child);
                s.SetReadOnly(child, true);
                s.Transaction.Commit();
            }

            AssertUpdateCount(0);             // NH-specific: Hibernate issues a separate UPDATE for the version number
            AssertInsertCount(1);
            ClearCounts();

            using (ISession s = OpenSession())
            {
                s.BeginTransaction();
                parent = s.Get <VersionedNode>(parent.Id);
                child  = s.Get <VersionedNode>(child.Id);
                Assert.That(child.Name, Is.EqualTo("child"));
                Assert.That(child.Parent, Is.Null);
                Assert.That(child.Version, Is.EqualTo(1));
                Assert.That(parent, Is.Not.Null);
                Assert.That(parent.Children.Count, Is.EqualTo(0));
                Assert.That(parent.Version, Is.EqualTo(1));
                s.SetReadOnly(parent, true);
                s.SetReadOnly(child, true);
                s.Delete(parent);
                s.Delete(child);
                s.Transaction.Commit();
            }

            AssertUpdateCount(0);
            AssertDeleteCount(2);
        }
        public async Task UpdateChildWithNewParentCommitWithReadOnlyChildAsync()
        {
            VersionedNode child = new VersionedNode("child", "child");

            using (ISession s = OpenSession())
            {
                s.BeginTransaction();
                await(s.PersistAsync(child));
                await(s.Transaction.CommitAsync());
            }

            ClearCounts();

            child.Name = "new child name";
            VersionedNode parent = new VersionedNode("parent", "parent");

            parent.AddChild(child);

            using (ISession s = OpenSession())
            {
                s.BeginTransaction();
                await(s.UpdateAsync(child));
                s.SetReadOnly(child, true);
                await(s.Transaction.CommitAsync());
            }

            AssertUpdateCount(0);
            AssertInsertCount(1);
            ClearCounts();

            using (ISession s = OpenSession())
            {
                s.BeginTransaction();
                parent = await(s.GetAsync <VersionedNode>(parent.Id));
                child  = await(s.GetAsync <VersionedNode>(child.Id));
                Assert.That(child.Name, Is.EqualTo("child"));
                Assert.That(child.Parent, Is.Null);
                Assert.That(child.Version, Is.EqualTo(1));
                Assert.That(parent, Is.Not.Null);
                Assert.That(parent.Children.Count, Is.EqualTo(0));
                Assert.That(parent.Version, Is.EqualTo(1));
                s.SetReadOnly(parent, true);
                s.SetReadOnly(child, true);
                await(s.DeleteAsync(parent));
                await(s.DeleteAsync(child));
                await(s.Transaction.CommitAsync());
            }

            AssertUpdateCount(0);
            AssertDeleteCount(2);
        }
Exemple #4
0
        public void UpdateParentWithNewChildCommitWithReadOnlyParent()
        {
            VersionedNode parent = new VersionedNode("parent", "parent");

            using (ISession s = OpenSession())
            {
                s.BeginTransaction();
                s.Persist(parent);
                s.Transaction.Commit();
            }

            ClearCounts();

            parent.Name = "new parent name";
            VersionedNode child = new VersionedNode("child", "child");

            parent.AddChild(child);

            using (ISession s = OpenSession())
            {
                s.BeginTransaction();
                s.Update(parent);
                s.SetReadOnly(parent, true);
                s.Transaction.Commit();
            }

            AssertUpdateCount(1);
            AssertInsertCount(1);
            ClearCounts();

            using (ISession s = OpenSession())
            {
                s.BeginTransaction();
                parent = s.Get <VersionedNode>(parent.Id);
                child  = s.Get <VersionedNode>(child.Id);
                Assert.That(parent.Name, Is.EqualTo("parent"));
                Assert.That(parent.Children.Count, Is.EqualTo(1));
                Assert.That(parent.Version, Is.EqualTo(2));
                Assert.That(child.Parent, Is.SameAs(parent));
                Assert.That(parent.Children.First(), Is.SameAs(child));
                Assert.That(child.Version, Is.EqualTo(1));
                s.SetReadOnly(parent, true);
                s.SetReadOnly(child, true);
                s.Delete(parent);
                s.Delete(child);
                s.Transaction.Commit();
            }

            AssertUpdateCount(0);
            AssertDeleteCount(2);
        }
        public async Task GetParentMakeReadOnlyThenMergeDetachedParentWithNewChildCAsync()
        {
            VersionedNode parent = new VersionedNode("parent", "parent");

            using (ISession s = OpenSession())
            {
                s.BeginTransaction();
                await(s.PersistAsync(parent));
                await(s.Transaction.CommitAsync());
            }

            ClearCounts();

            parent.Name = "new parent name";
            VersionedNode child = new VersionedNode("child", "child");

            parent.AddChild(child);

            using (var s = OpenSession())
            {
                s.BeginTransaction();
                VersionedNode parentManaged = await(s.GetAsync <VersionedNode>(parent.Id));
                s.SetReadOnly(parentManaged, true);
                VersionedNode parentMerged = (VersionedNode)await(s.MergeAsync(parent));
                Assert.That(parentManaged, Is.SameAs(parentMerged));
                await(s.Transaction.CommitAsync());
            }

            AssertUpdateCount(1);
            AssertInsertCount(1);
            ClearCounts();

            using (var s = OpenSession())
            {
                s.BeginTransaction();
                parent = await(s.GetAsync <VersionedNode>(parent.Id));
                child  = await(s.GetAsync <VersionedNode>(child.Id));
                Assert.That(parent.Name, Is.EqualTo("parent"));
                Assert.That(parent.Children.Count, Is.EqualTo(1));
                Assert.That(parent.Version, Is.EqualTo(2));
                Assert.That(child.Parent, Is.SameAs(parent));
                Assert.That(parent.Children.First(), Is.SameAs(child));
                Assert.That(child.Version, Is.EqualTo(1));
                await(s.DeleteAsync(parent));
                await(s.DeleteAsync(child));
                await(s.Transaction.CommitAsync());
            }

            AssertUpdateCount(0);
            AssertDeleteCount(2);
        }
        public void GetParentMakeReadOnlyThenMergeDetachedParentWithNewChildC()
        {
            ISession s = OpenSession();

            s.BeginTransaction();
            VersionedNode parent = new VersionedNode("parent", "parent");

            s.Persist(parent);
            s.Transaction.Commit();
            s.Close();

            ClearCounts();

            parent.Name = "new parent name";
            VersionedNode child = new VersionedNode("child", "child");

            parent.AddChild(child);

            s = OpenSession();
            s.BeginTransaction();
            VersionedNode parentManaged = s.Get <VersionedNode>(parent.Id);

            s.SetReadOnly(parentManaged, true);
            VersionedNode parentMerged = (VersionedNode)s.Merge(parent);

            Assert.That(parentManaged, Is.SameAs(parentMerged));
            s.Transaction.Commit();
            s.Close();

            AssertUpdateCount(1);
            AssertInsertCount(1);
            ClearCounts();

            s = OpenSession();
            s.BeginTransaction();
            parent = s.Get <VersionedNode>(parent.Id);
            child  = s.Get <VersionedNode>(child.Id);
            Assert.That(parent.Name, Is.EqualTo("parent"));
            Assert.That(parent.Children.Count, Is.EqualTo(1));
            Assert.That(parent.Version, Is.EqualTo(2));
            Assert.That(child.Parent, Is.SameAs(parent));
            Assert.That(parent.Children.First(), Is.SameAs(child));
            Assert.That(child.Version, Is.EqualTo(1));
            s.Delete(parent);
            s.Delete(child);
            s.Transaction.Commit();
            s.Close();

            AssertUpdateCount(0);
            AssertDeleteCount(2);
        }
        public void UpdateChildWithNewParentCommitWithReadOnlyChild()
        {
            ISession s = OpenSession();

            s.BeginTransaction();
            VersionedNode child = new VersionedNode("child", "child");

            s.Persist(child);
            s.Transaction.Commit();
            s.Close();

            ClearCounts();

            child.Name = "new child name";
            VersionedNode parent = new VersionedNode("parent", "parent");

            parent.AddChild(child);

            s = OpenSession();
            s.BeginTransaction();
            s.Update(child);
            s.SetReadOnly(child, true);
            s.Transaction.Commit();
            s.Close();

            AssertUpdateCount(0);
            AssertInsertCount(1);
            ClearCounts();

            s = OpenSession();
            s.BeginTransaction();
            parent = s.Get <VersionedNode>(parent.Id);
            child  = s.Get <VersionedNode>(child.Id);
            Assert.That(child.Name, Is.EqualTo("child"));
            Assert.That(child.Parent, Is.Null);
            Assert.That(child.Version, Is.EqualTo(1));
            Assert.That(parent, Is.Not.Null);
            Assert.That(parent.Children.Count, Is.EqualTo(0));
            Assert.That(parent.Version, Is.EqualTo(1));
            s.SetReadOnly(parent, true);
            s.SetReadOnly(child, true);
            s.Delete(parent);
            s.Delete(child);
            s.Transaction.Commit();
            s.Close();

            AssertUpdateCount(0);
            AssertDeleteCount(2);
        }
Exemple #8
0
        public void AddNewParentToReadOnlyChild()
        {
            VersionedNode child = new VersionedNode("child", "child");

            using (ISession s = OpenSession())
            {
                s.BeginTransaction();
                s.Persist(child);
                s.Transaction.Commit();
            }

            ClearCounts();

            VersionedNode parent = new VersionedNode("parent", "parent");

            using (ISession s = OpenSession())
            {
                s.BeginTransaction();
                VersionedNode childManaged = s.Get <VersionedNode>(child.Id);
                s.SetReadOnly(childManaged, true);
                childManaged.Name = "new child name";
                parent.AddChild(childManaged);
                s.Transaction.Commit();
            }

            AssertUpdateCount(0);
            AssertInsertCount(1);

            using (ISession s = OpenSession())
            {
                s.BeginTransaction();
                child = s.Get <VersionedNode>(child.Id);
                Assert.That(child.Name, Is.EqualTo("child"));
                Assert.That(child.Parent, Is.Null);
                Assert.That(child.Version, Is.EqualTo(1));
                parent = s.Get <VersionedNode>(parent.Id);
                Assert.That(parent, Is.Not.Null);
                s.SetReadOnly(child, true);
                s.Delete(child);
                s.Transaction.Commit();
            }

            AssertUpdateCount(0);
            AssertDeleteCount(1);
        }
        public async Task AddNewChildToReadOnlyParentAsync()
        {
            VersionedNode parent = new VersionedNode("parent", "parent");

            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    s.CacheMode = CacheMode.Ignore;
                    await(s.PersistAsync(parent));
                    await(t.CommitAsync());
                }

            ClearCounts();

            VersionedNode child = new VersionedNode("child", "child");

            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    s.CacheMode = CacheMode.Ignore;
                    VersionedNode parentManaged = await(s.GetAsync <VersionedNode>(parent.Id));
                    s.SetReadOnly(parentManaged, true);
                    parentManaged.Name = "new parent name";
                    parentManaged.AddChild(child);
                    await(s.SaveAsync(parentManaged));
                    await(t.CommitAsync());
                }

            AssertUpdateCount(1);
            AssertInsertCount(1);

            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    s.CacheMode = CacheMode.Ignore;
                    parent      = await(s.GetAsync <VersionedNode>(parent.Id));
                    Assert.That(parent.Name, Is.EqualTo("parent"));
                    Assert.That(parent.Children.Count, Is.EqualTo(1));
                    Assert.That(parent.Version, Is.EqualTo(2));
                    child = await(s.GetAsync <VersionedNode>(child.Id));
                    Assert.That(child, Is.Not.Null);
                    await(s.DeleteAsync(parent));
                    await(t.CommitAsync());
                }
        }
        public void AddNewChildToReadOnlyParent()
        {
            ISession s = OpenSession();

            s.CacheMode = CacheMode.Ignore;
            s.BeginTransaction();
            VersionedNode parent = new VersionedNode("parent", "parent");

            s.Persist(parent);
            s.Transaction.Commit();
            s.Close();

            ClearCounts();

            s           = OpenSession();
            s.CacheMode = CacheMode.Ignore;
            s.BeginTransaction();
            VersionedNode parentManaged = s.Get <VersionedNode>(parent.Id);

            s.SetReadOnly(parentManaged, true);
            parentManaged.Name = "new parent name";
            VersionedNode child = new VersionedNode("child", "child");

            parentManaged.AddChild(child);
            s.Save(parentManaged);
            s.Transaction.Commit();
            s.Close();

            AssertUpdateCount(1);
            AssertInsertCount(1);

            s           = OpenSession();
            s.CacheMode = CacheMode.Ignore;
            s.BeginTransaction();
            parent = s.Get <VersionedNode>(parent.Id);
            Assert.That(parent.Name, Is.EqualTo("parent"));
            Assert.That(parent.Children.Count, Is.EqualTo(1));
            Assert.That(parent.Version, Is.EqualTo(2));
            child = s.Get <VersionedNode>(child.Id);
            Assert.That(child, Is.Not.Null);
            s.Delete(parent);
            s.Transaction.Commit();
            s.Close();
        }
        public async Task AddNewParentToReadOnlyChildAsync()
        {
            VersionedNode child = new VersionedNode("child", "child");

            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    await(s.PersistAsync(child));
                    await(t.CommitAsync());
                }

            ClearCounts();

            VersionedNode parent = new VersionedNode("parent", "parent");

            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    VersionedNode childManaged = await(s.GetAsync <VersionedNode>(child.Id));
                    s.SetReadOnly(childManaged, true);
                    childManaged.Name = "new child name";
                    parent.AddChild(childManaged);
                    await(t.CommitAsync());
                }

            AssertUpdateCount(0);
            AssertInsertCount(1);
            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    child = await(s.GetAsync <VersionedNode>(child.Id));
                    Assert.That(child.Name, Is.EqualTo("child"));
                    Assert.That(child.Parent, Is.Null);
                    Assert.That(child.Version, Is.EqualTo(1));
                    parent = await(s.GetAsync <VersionedNode>(parent.Id));
                    Assert.That(parent, Is.Not.Null);
                    s.SetReadOnly(child, true);
                    await(s.DeleteAsync(child));
                    await(t.CommitAsync());
                }

            AssertUpdateCount(0);
            AssertDeleteCount(1);
        }
		public void GetChildMakeReadOnlyThenMergeDetachedChildWithNewParent()
		{
			ISession s = OpenSession();
			s.BeginTransaction();
			VersionedNode child = new VersionedNode("child", "child");
			s.Persist(child);
			s.Transaction.Commit();
			s.Close();
	
			ClearCounts();
	
			child.Name = "new child name";
			VersionedNode parent = new VersionedNode("parent", "parent");
			parent.AddChild(child);
	
			s = OpenSession();
			s.BeginTransaction();
			VersionedNode childManaged = s.Get<VersionedNode>(child.Id);
			s.SetReadOnly(childManaged, true);
			VersionedNode childMerged = (VersionedNode)s.Merge(child);
			Assert.That(childManaged, Is.SameAs(childMerged));
			s.Transaction.Commit();
			s.Close();
	
			AssertUpdateCount(0); // NH-specific: Hibernate issues a seperate UPDATE for the version number
			AssertInsertCount(1);
			ClearCounts();
	
			s = OpenSession();
			s.BeginTransaction();
			parent = s.Get<VersionedNode>(parent.Id);
			child = s.Get<VersionedNode>(child.Id);
			Assert.That(child.Name, Is.EqualTo("child"));
			Assert.That(child.Parent, Is.Null);
			Assert.That(child.Version, Is.EqualTo(1));
			Assert.That(parent, Is.Not.Null);
			Assert.That(parent.Children.Count, Is.EqualTo(0));
			Assert.That(parent.Version, Is.EqualTo(1)); // NH-specific: Hibernate incorrectly increments version number, NH does not
			s.SetReadOnly(parent, true);
			s.SetReadOnly(child, true);
			s.Delete(parent);
			s.Delete(child);
			s.Transaction.Commit();
			s.Close();
	
			AssertUpdateCount(0);
			AssertDeleteCount(2);
		}
		public void UpdateChildWithNewParentCommitWithReadOnlyChild()
		{
			ISession s = OpenSession();
			s.BeginTransaction();
			VersionedNode child = new VersionedNode("child", "child");
			s.Persist(child);
			s.Transaction.Commit();
			s.Close();
	
			ClearCounts();
	
			child.Name = "new child name";
			VersionedNode parent = new VersionedNode("parent", "parent");
			parent.AddChild(child);
	
			s = OpenSession();
			s.BeginTransaction();
			s.Update(child);
			s.SetReadOnly(child, true);
			s.Transaction.Commit();
			s.Close();
	
			AssertUpdateCount(0);
			AssertInsertCount(1);
			ClearCounts();
	
			s = OpenSession();
			s.BeginTransaction();
			parent = s.Get<VersionedNode>(parent.Id);
			child = s.Get<VersionedNode>(child.Id);
			Assert.That(child.Name, Is.EqualTo("child"));
			Assert.That(child.Parent, Is.Null);
			Assert.That(child.Version, Is.EqualTo(1));
			Assert.That(parent, Is.Not.Null);
			Assert.That(parent.Children.Count, Is.EqualTo(0));
			Assert.That(parent.Version, Is.EqualTo(1));
			s.SetReadOnly(parent, true);
			s.SetReadOnly(child, true);
			s.Delete(parent);
			s.Delete(child);
			s.Transaction.Commit();
			s.Close();
	
			AssertUpdateCount(0);
			AssertDeleteCount(2);
		}
		public void MergeUnchangedDetachedParentChildren()
		{
			ISession s = OpenSession();
			s.BeginTransaction();
			VersionedNode parent = new VersionedNode("parent", "parent");
			VersionedNode child = new VersionedNode("child", "child");
			parent.AddChild(child);
			s.Persist(parent);
			s.Transaction.Commit();
			s.Close();
	
			ClearCounts();
	
			s = OpenSession();
			s.BeginTransaction();
			parent = (VersionedNode)s.Merge(parent);
			s.Transaction.Commit();
			s.Close();
	
			AssertUpdateCount(0);
			AssertInsertCount(0);
			ClearCounts();
	
			s = OpenSession();
			s.BeginTransaction();
			VersionedNode parentGet = s.Get<VersionedNode>(parent.Id);
			s.Merge(parent);
			s.Transaction.Commit();
			s.Close();
	
			AssertUpdateCount(0);
			AssertInsertCount(0);
			ClearCounts();
	
			s = OpenSession();
			s.BeginTransaction();
			VersionedNode parentLoad = s.Load<VersionedNode>(parent.Id);
			s.Merge(parent);
			s.Transaction.Commit();
			s.Close();
	
			AssertUpdateCount(0);
			AssertInsertCount(0);
			ClearCounts();
	
			s = OpenSession();
			s.BeginTransaction();
			parent = s.Get<VersionedNode>(parent.Id);
			child = s.Get<VersionedNode>(child.Id);
			Assert.That(parent.Name, Is.EqualTo("parent"));
			Assert.That(parent.Children.Count, Is.EqualTo(1));
			Assert.That(parent.Version, Is.EqualTo(1));
			Assert.That(child.Parent, Is.SameAs(parent));
			Assert.That(parent.Children.First(), Is.SameAs(child));
			Assert.That(child.Version, Is.EqualTo(1));
			s.Delete(parent);
			s.Delete(child);
			s.Transaction.Commit();
			s.Close();
	
			AssertUpdateCount(0);
			AssertDeleteCount(2);
		}
		public void GetParentMakeReadOnlyThenMergeDetachedParentWithNewChildC()
		{
			ISession s = OpenSession();
			s.BeginTransaction();
			VersionedNode parent = new VersionedNode("parent", "parent");
			s.Persist(parent);
			s.Transaction.Commit();
			s.Close();
	
			ClearCounts();
	
			parent.Name = "new parent name";
			VersionedNode child = new VersionedNode("child", "child");
			parent.AddChild(child);
	
			s = OpenSession();
			s.BeginTransaction();
			VersionedNode parentManaged = s.Get<VersionedNode>(parent.Id);
			s.SetReadOnly(parentManaged, true);
			VersionedNode parentMerged = (VersionedNode) s.Merge(parent);
			Assert.That(parentManaged, Is.SameAs(parentMerged));
			s.Transaction.Commit();
			s.Close();
	
			AssertUpdateCount(1);
			AssertInsertCount(1);
			ClearCounts();
	
			s = OpenSession();
			s.BeginTransaction();
			parent = s.Get<VersionedNode>(parent.Id);
			child = s.Get<VersionedNode>(child.Id);
			Assert.That(parent.Name, Is.EqualTo("parent"));
			Assert.That(parent.Children.Count, Is.EqualTo(1));
			Assert.That(parent.Version, Is.EqualTo(2));
			Assert.That(child.Parent, Is.SameAs(parent));
			Assert.That(parent.Children.First(), Is.SameAs(child));
			Assert.That(child.Version, Is.EqualTo(1));
			s.Delete(parent);
			s.Delete(child);
			s.Transaction.Commit();
			s.Close();
	
			AssertUpdateCount(0);
			AssertDeleteCount(2);
		}
		public void AddNewParentToReadOnlyChild()
		{
			VersionedNode child = new VersionedNode("child", "child");
			using (ISession s = OpenSession())
			{
				s.BeginTransaction();
				s.Persist(child);
				s.Transaction.Commit();
			}

			ClearCounts();

			VersionedNode parent = new VersionedNode("parent", "parent");
			using (ISession s = OpenSession())
			{
				s.BeginTransaction();
				VersionedNode childManaged = s.Get<VersionedNode>(child.Id);
				s.SetReadOnly(childManaged, true);
				childManaged.Name = "new child name";
				parent.AddChild(childManaged);
				s.Transaction.Commit();
			}

			AssertUpdateCount(0);
			AssertInsertCount(1);

			using (ISession s = OpenSession())
			{
				s.BeginTransaction();
				child = s.Get<VersionedNode>(child.Id);
				Assert.That(child.Name, Is.EqualTo("child"));
				Assert.That(child.Parent, Is.Null);
				Assert.That(child.Version, Is.EqualTo(1));
				parent = s.Get<VersionedNode>(parent.Id);
				Assert.That(parent, Is.Not.Null);
				s.SetReadOnly(child, true);
				s.Delete(child);
				s.Transaction.Commit();
			}

			AssertUpdateCount(0);
			AssertDeleteCount(1);
		}
        public void MergeUnchangedDetachedParentChildren()
        {
            ISession s = OpenSession();

            s.BeginTransaction();
            VersionedNode parent = new VersionedNode("parent", "parent");
            VersionedNode child  = new VersionedNode("child", "child");

            parent.AddChild(child);
            s.Persist(parent);
            s.Transaction.Commit();
            s.Close();

            ClearCounts();

            s = OpenSession();
            s.BeginTransaction();
            parent = (VersionedNode)s.Merge(parent);
            s.Transaction.Commit();
            s.Close();

            AssertUpdateCount(0);
            AssertInsertCount(0);
            ClearCounts();

            s = OpenSession();
            s.BeginTransaction();
            VersionedNode parentGet = s.Get <VersionedNode>(parent.Id);

            s.Merge(parent);
            s.Transaction.Commit();
            s.Close();

            AssertUpdateCount(0);
            AssertInsertCount(0);
            ClearCounts();

            s = OpenSession();
            s.BeginTransaction();
            VersionedNode parentLoad = s.Load <VersionedNode>(parent.Id);

            s.Merge(parent);
            s.Transaction.Commit();
            s.Close();

            AssertUpdateCount(0);
            AssertInsertCount(0);
            ClearCounts();

            s = OpenSession();
            s.BeginTransaction();
            parent = s.Get <VersionedNode>(parent.Id);
            child  = s.Get <VersionedNode>(child.Id);
            Assert.That(parent.Name, Is.EqualTo("parent"));
            Assert.That(parent.Children.Count, Is.EqualTo(1));
            Assert.That(parent.Version, Is.EqualTo(1));
            Assert.That(child.Parent, Is.SameAs(parent));
            Assert.That(parent.Children.First(), Is.SameAs(child));
            Assert.That(child.Version, Is.EqualTo(1));
            s.Delete(parent);
            s.Delete(child);
            s.Transaction.Commit();
            s.Close();

            AssertUpdateCount(0);
            AssertDeleteCount(2);
        }
		public void MergeDetachedChildWithNewParentCommitWithReadOnlyChild()
		{
			VersionedNode child = new VersionedNode("child", "child");
			using (ISession s = OpenSession())
			{
				s.BeginTransaction();
				s.Persist(child);
				s.Transaction.Commit();
			}

			ClearCounts();
	
			child.Name = "new child name";
			VersionedNode parent = new VersionedNode("parent", "parent");
			parent.AddChild(child);

			using (ISession s = OpenSession())
			{
				s.BeginTransaction();
				child = (VersionedNode) s.Merge(child);
				s.SetReadOnly(child, true);
				s.Transaction.Commit();
			}

			AssertUpdateCount(0); // NH-specific: Hibernate issues a separate UPDATE for the version number
			AssertInsertCount(1);
			ClearCounts();

			using (ISession s = OpenSession())
			{
				s.BeginTransaction();
				parent = s.Get<VersionedNode>(parent.Id);
				child = s.Get<VersionedNode>(child.Id);
				Assert.That(child.Name, Is.EqualTo("child"));
				Assert.That(child.Parent, Is.Null);
				Assert.That(child.Version, Is.EqualTo(1));
				Assert.That(parent, Is.Not.Null);
				Assert.That(parent.Children.Count, Is.EqualTo(0));
				Assert.That(parent.Version, Is.EqualTo(1));
				s.SetReadOnly(parent, true);
				s.SetReadOnly(child, true);
				s.Delete(parent);
				s.Delete(child);
				s.Transaction.Commit();
			}

			AssertUpdateCount(0);
			AssertDeleteCount(2);
		}
        public async Task MergeUnchangedDetachedParentChildrenAsync()
        {
            VersionedNode parent = new VersionedNode("parent", "parent");
            VersionedNode child  = new VersionedNode("child", "child");

            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    parent.AddChild(child);
                    await(s.PersistAsync(parent));
                    await(t.CommitAsync());
                }

            ClearCounts();
            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    parent = (VersionedNode)await(s.MergeAsync(parent));
                    await(t.CommitAsync());
                }

            AssertUpdateCount(0);
            AssertInsertCount(0);
            ClearCounts();
            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    VersionedNode parentGet = await(s.GetAsync <VersionedNode>(parent.Id));
                    await(s.MergeAsync(parent));
                    await(t.CommitAsync());
                }

            AssertUpdateCount(0);
            AssertInsertCount(0);
            ClearCounts();
            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    VersionedNode parentLoad = await(s.LoadAsync <VersionedNode>(parent.Id));
                    await(s.MergeAsync(parent));
                    await(t.CommitAsync());
                }

            AssertUpdateCount(0);
            AssertInsertCount(0);
            ClearCounts();
            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    parent = await(s.GetAsync <VersionedNode>(parent.Id));
                    child  = await(s.GetAsync <VersionedNode>(child.Id));
                    Assert.That(parent.Name, Is.EqualTo("parent"));
                    Assert.That(parent.Children.Count, Is.EqualTo(1));
                    Assert.That(parent.Version, Is.EqualTo(1));
                    Assert.That(child.Parent, Is.SameAs(parent));
                    Assert.That(parent.Children.First(), Is.SameAs(child));
                    Assert.That(child.Version, Is.EqualTo(1));
                    await(s.DeleteAsync(parent));
                    await(s.DeleteAsync(child));
                    await(t.CommitAsync());
                }

            AssertUpdateCount(0);
            AssertDeleteCount(2);
        }
		public void UpdateParentWithNewChildCommitWithReadOnlyParent()
		{
			VersionedNode parent = new VersionedNode("parent", "parent");
			using (ISession s = OpenSession())
			{
				s.BeginTransaction();
				s.Persist(parent);
				s.Transaction.Commit();
			}

			ClearCounts();
	
			parent.Name = "new parent name";
			VersionedNode child = new VersionedNode("child", "child");
			parent.AddChild(child);

			using (ISession s = OpenSession())
			{
				s.BeginTransaction();
				s.Update(parent);
				s.SetReadOnly(parent, true);
				s.Transaction.Commit();
			}

			AssertUpdateCount(1);
			AssertInsertCount(1);
			ClearCounts();

			using (ISession s = OpenSession())
			{
				s.BeginTransaction();
				parent = s.Get<VersionedNode>(parent.Id);
				child = s.Get<VersionedNode>(child.Id);
				Assert.That(parent.Name, Is.EqualTo("parent"));
				Assert.That(parent.Children.Count, Is.EqualTo(1));
				Assert.That(parent.Version, Is.EqualTo(2));
				Assert.That(child.Parent, Is.SameAs(parent));
				Assert.That(parent.Children.First(), Is.SameAs(child));
				Assert.That(child.Version, Is.EqualTo(1));
				s.SetReadOnly(parent, true);
				s.SetReadOnly(child, true);
				s.Delete(parent);
				s.Delete(child);
				s.Transaction.Commit();
			}

			AssertUpdateCount(0);
			AssertDeleteCount(2);
		}