Skip to content

Commit 6e63217

Browse files
Kildibekov_ARKildibekov_AR
Kildibekov_AR
authored and
Kildibekov_AR
committed
Test for #3665
1 parent 916c6dc commit 6e63217

File tree

5 files changed

+160
-0
lines changed

5 files changed

+160
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using System.Collections.Generic;
12+
using NUnit.Framework;
13+
14+
namespace NHibernate.Test.NHSpecificTest.GH3665
15+
{
16+
using System.Threading.Tasks;
17+
[TestFixture]
18+
public class TempReattachedChildFixtureAsync : BugTestCase
19+
{
20+
protected override void OnTearDown()
21+
{
22+
using (ISession session = OpenSession())
23+
using (ITransaction transaction = session.BeginTransaction())
24+
{
25+
session.Delete("from System.Object");
26+
27+
session.Flush();
28+
transaction.Commit();
29+
}
30+
}
31+
32+
[Test]
33+
public async Task WhenRemoveTempChild_ChildShouldNotInsertAsync()
34+
{
35+
Book book = null;
36+
Word word = null;
37+
using (var s = OpenSession())
38+
using (var tr = s.BeginTransaction())
39+
{
40+
book = new Book { Id = 1 };
41+
book.Words = new List<Word> { new Word { Id = 1, Parent = book } };
42+
await (s.SaveAsync(book));
43+
await (tr.CommitAsync());
44+
}
45+
46+
word = new Word { Id = 2, Parent = book };
47+
book.Words.Add(word);
48+
49+
using (var s = OpenSession())
50+
using (var tr = s.BeginTransaction())
51+
{
52+
await (s.UpdateAsync(book));
53+
book.Words.Remove(word);
54+
using (var sl = new SqlLogSpy())
55+
{
56+
await (tr.CommitAsync());
57+
var logs = sl.GetWholeLog();
58+
Assert.That(logs, Does.Not.Contain("INSERT \n INTO\n Word").IgnoreCase, "Сollection record should not be inserted");
59+
}
60+
}
61+
}
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Collections.Generic;
2+
3+
namespace NHibernate.Test.NHSpecificTest.GH3665
4+
{
5+
public class Book
6+
{
7+
public virtual int Id { get; set; }
8+
public virtual string Name { get; set; }
9+
public virtual IList<Word> Words { get; set; }
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
3+
assembly="NHibernate.Test"
4+
namespace="NHibernate.Test.NHSpecificTest.GH3665">
5+
6+
<class name="Book">
7+
<cache usage="nonstrict-read-write" include="non-lazy" />
8+
<id name="Id">
9+
<generator class="assigned" />
10+
</id>
11+
<property name="Name" />
12+
<bag name="Words" inverse="true" generic="true" cascade="all-delete-orphan" lazy="false" >
13+
<key column="ParentId" />
14+
<one-to-many class="Word" />
15+
</bag>
16+
</class>
17+
18+
<class name="Word">
19+
<id name="Id" column="Id">
20+
<generator class="assigned" />
21+
</id>
22+
<many-to-one name="Parent" class="Book" column="ParentId" />
23+
</class>
24+
25+
</hibernate-mapping>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System.Collections.Generic;
2+
using NUnit.Framework;
3+
4+
namespace NHibernate.Test.NHSpecificTest.GH3665
5+
{
6+
[TestFixture]
7+
public class TempReattachedChildFixture : BugTestCase
8+
{
9+
protected override void OnTearDown()
10+
{
11+
using (ISession session = OpenSession())
12+
using (ITransaction transaction = session.BeginTransaction())
13+
{
14+
session.Delete("from System.Object");
15+
16+
session.Flush();
17+
transaction.Commit();
18+
}
19+
}
20+
21+
[Test]
22+
public void WhenRemoveTempChild_ChildShouldNotInsert()
23+
{
24+
Book book = null;
25+
Word word = null;
26+
using (var s = OpenSession())
27+
using (var tr = s.BeginTransaction())
28+
{
29+
book = new Book { Id = 1 };
30+
book.Words = new List<Word> { new Word { Id = 1, Parent = book } };
31+
s.Save(book);
32+
tr.Commit();
33+
}
34+
35+
word = new Word { Id = 2, Parent = book };
36+
book.Words.Add(word);
37+
38+
using (var s = OpenSession())
39+
using (var tr = s.BeginTransaction())
40+
{
41+
s.Update(book);
42+
book.Words.Remove(word);
43+
using (var sl = new SqlLogSpy())
44+
{
45+
tr.Commit();
46+
var logs = sl.GetWholeLog();
47+
Assert.That(logs, Does.Not.Contain("INSERT \n INTO\n Word").IgnoreCase, "Сollection record should not be inserted");
48+
}
49+
}
50+
}
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace NHibernate.Test.NHSpecificTest.GH3665
2+
{
3+
public class Word
4+
{
5+
public virtual int Id { get; set; }
6+
public virtual byte[] Content { get; set; }
7+
public virtual Book Parent { get; set; }
8+
}
9+
}

0 commit comments

Comments
 (0)