Skip to content

Commit ac1de47

Browse files
NH-4034 - checking behavior with "grand-children".
1 parent f76cf81 commit ac1de47

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

src/NHibernate.Test/SystemTransactions/TransactionFixture.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,27 @@ public void FlushFromTransactionAppliesToDisposedSharingSession()
4545
// The relationship is there for failing in case the flush ordering is not the expected one.
4646
var p2 = new Person { Related = p1 };
4747
var p3 = new Person { Related = p2 };
48+
// If putting p3 here, adjust base tear-down.
49+
var p4 = new Person { Related = p2 };
4850

4951
using (var s1 = builder.OpenSession())
5052
s1.Save(p1);
5153
using (var s2 = builder.OpenSession())
54+
{
5255
s2.Save(p2);
53-
s.Save(p3);
56+
using (var s3 = s2.SessionWithOptions().Connection().OpenSession())
57+
s3.Save(p3);
58+
}
59+
s.Save(p4);
5460
t.Complete();
5561
}
5662
}
5763

5864
using (var s = OpenSession())
5965
using (var t = s.BeginTransaction())
6066
{
61-
Assert.That(s.Query<Person>().Count(), Is.EqualTo(3));
62-
Assert.That(s.Query<Person>().Count(p => p.Related != null), Is.EqualTo(2));
67+
Assert.That(s.Query<Person>().Count(), Is.EqualTo(4));
68+
Assert.That(s.Query<Person>().Count(p => p.Related != null), Is.EqualTo(3));
6369
t.Commit();
6470
}
6571
}
@@ -73,24 +79,28 @@ public void FlushFromTransactionAppliesToSharingSession()
7379

7480
using (var s1 = builder.OpenSession())
7581
using (var s2 = builder.OpenSession())
82+
using (var s3 = s2.SessionWithOptions().Connection().OpenSession())
7683
using (var t = new TransactionScope())
7784
{
7885
var p1 = new Person();
7986
// The relationship is there for failing in case the flush ordering is not the expected one.
8087
var p2 = new Person { Related = p1 };
8188
var p3 = new Person { Related = p2 };
89+
// If putting p3 here, adjust base tear-down.
90+
var p4 = new Person { Related = p2 };
8291
s1.Save(p1);
8392
s2.Save(p2);
84-
s.Save(p3);
93+
s3.Save(p3);
94+
s.Save(p4);
8595
t.Complete();
8696
}
8797
}
8898

8999
using (var s = OpenSession())
90100
using (var t = s.BeginTransaction())
91101
{
92-
Assert.That(s.Query<Person>().Count(), Is.EqualTo(3));
93-
Assert.That(s.Query<Person>().Count(p => p.Related != null), Is.EqualTo(2));
102+
Assert.That(s.Query<Person>().Count(), Is.EqualTo(4));
103+
Assert.That(s.Query<Person>().Count(p => p.Related != null), Is.EqualTo(3));
94104
t.Commit();
95105
}
96106
}

src/NHibernate.Test/TransactionTest/TransactionFixture.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,24 +145,28 @@ public void FlushFromTransactionAppliesToSharingSession()
145145

146146
using (var s1 = builder.OpenSession())
147147
using (var s2 = builder.OpenSession())
148+
using (var s3 = s1.SessionWithOptions().Connection().OpenSession())
148149
using (var t = s.BeginTransaction())
149150
{
150151
var p1 = new Person();
151152
// The relationship is there for failing in case the flush ordering is not the expected one.
152153
var p2 = new Person { Related = p1 };
153154
var p3 = new Person { Related = p2 };
155+
// If putting p3 here, adjust base tear-down.
156+
var p4 = new Person { Related = p2 };
154157
s1.Save(p1);
155158
s2.Save(p2);
156-
s.Save(p3);
159+
s3.Save(p3);
160+
s.Save(p4);
157161
t.Commit();
158162
}
159163
}
160164

161165
using (var s = OpenSession())
162166
using (var t = s.BeginTransaction())
163167
{
164-
Assert.That(s.Query<Person>().Count(), Is.EqualTo(3));
165-
Assert.That(s.Query<Person>().Count(p => p.Related != null), Is.EqualTo(2));
168+
Assert.That(s.Query<Person>().Count(), Is.EqualTo(4));
169+
Assert.That(s.Query<Person>().Count(p => p.Related != null), Is.EqualTo(3));
166170
t.Commit();
167171
}
168172
}

src/NHibernate/AdoNet/ConnectionManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ public ConnectionManager(
7575
ownConnection = suppliedConnection == null;
7676
}
7777

78-
public void AddSessionSharingManager(ISessionImplementor session)
78+
public void AddDependentSession(ISessionImplementor session)
7979
{
8080
_dependentSessions.Add(session);
8181
}
8282

83-
public void RemoveSessionSharingManager(ISessionImplementor session)
83+
public void RemoveDependentSession(ISessionImplementor session)
8484
{
8585
_dependentSessions.Remove(session);
8686
}

src/NHibernate/Impl/SessionImpl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ internal SessionImpl(SessionFactoryImpl factory, ISessionCreationOptions options
201201
if (options.UserSuppliedConnection != null)
202202
throw new SessionException("Cannot simultaneously share transaction context and specify connection");
203203
connectionManager = sharedOptions.ConnectionManager;
204-
connectionManager.AddSessionSharingManager(this);
204+
connectionManager.AddDependentSession(this);
205205
}
206206
else
207207
{
@@ -299,7 +299,7 @@ public DbConnection Close()
299299
{
300300
if (!_transactionCoordinatorShared)
301301
return connectionManager.Close();
302-
connectionManager.RemoveSessionSharingManager(this);
302+
connectionManager.RemoveDependentSession(this);
303303
return null;
304304
}
305305
finally

0 commit comments

Comments
 (0)