Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


using System.Collections.Generic;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.GH2028
{
using System.Threading.Tasks;
[TestFixture]
public class TempReattachedChildFixtureAsync : BugTestCase
{
protected override void OnTearDown()
{
using (ISession session = OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{
session.Delete("from System.Object");

session.Flush();
transaction.Commit();
}
}

[Test]
public async Task WhenRemoveTempChild_ChildShouldNotInsertAsync()
{
Book book = null;
Word word = null;
using (var s = OpenSession())
using (var tr = s.BeginTransaction())
{
book = new Book { Id = 1 };
book.Words = new List<Word> { new Word { Id = 1, Parent = book } };
await (s.SaveAsync(book));
await (tr.CommitAsync());
}

word = new Word { Id = 2, Parent = book };
book.Words.Add(word);

using (var s = OpenSession())
using (var tr = s.BeginTransaction())
{
await (s.UpdateAsync(book));
book.Words.Remove(word);
using (var sl = new SqlLogSpy())
{
await (tr.CommitAsync());
var logs = sl.GetWholeLog();
Assert.That(logs, Does.Not.Contain("INSERT \n INTO\n Word").IgnoreCase, "Сollection record should not be inserted");
}
}
}
}
}
11 changes: 11 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH2028/Book.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;

namespace NHibernate.Test.NHSpecificTest.GH2028
{
public class Book
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual IList<Word> Words { get; set; }
}
}
25 changes: 25 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH2028/Mappings.hbm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="NHibernate.Test"
namespace="NHibernate.Test.NHSpecificTest.GH2028">

<class name="Book">
<cache usage="nonstrict-read-write" include="non-lazy" />
<id name="Id">
<generator class="assigned" />
</id>
<property name="Name" />
<bag name="Words" inverse="true" generic="true" cascade="all-delete-orphan" lazy="false" >
<key column="ParentId" />
<one-to-many class="Word" />
</bag>
</class>

<class name="Word">
<id name="Id" column="Id">
<generator class="assigned" />
</id>
<many-to-one name="Parent" class="Book" column="ParentId" />
</class>

</hibernate-mapping>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Collections.Generic;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.GH2028
{
[TestFixture]
public class TempReattachedChildFixture : BugTestCase
{
protected override void OnTearDown()
{
using (ISession session = OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{
session.Delete("from System.Object");

session.Flush();
transaction.Commit();
}
}

[Test]
public void WhenRemoveTempChild_ChildShouldNotInsert()
{
Book book = null;
Word word = null;
using (var s = OpenSession())
using (var tr = s.BeginTransaction())
{
book = new Book { Id = 1 };
book.Words = new List<Word> { new Word { Id = 1, Parent = book } };
s.Save(book);
tr.Commit();
}

word = new Word { Id = 2, Parent = book };
book.Words.Add(word);

using (var s = OpenSession())
using (var tr = s.BeginTransaction())
{
s.Update(book);
book.Words.Remove(word);
using (var sl = new SqlLogSpy())
{
tr.Commit();
var logs = sl.GetWholeLog();
Assert.That(logs, Does.Not.Contain("INSERT \n INTO\n Word").IgnoreCase, "Сollection record should not be inserted");
}
}
}
}
}
9 changes: 9 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH2028/Word.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace NHibernate.Test.NHSpecificTest.GH2028
{
public class Word
{
public virtual int Id { get; set; }
public virtual byte[] Content { get; set; }
public virtual Book Parent { get; set; }
}
}