Skip to content

Commit 2902396

Browse files
committed
Test case
1 parent a7deeb0 commit 2902396

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

src/NHibernate.Test/NHSpecificTest/NH750/ManyToManyNotFoundIgnoreFixture.cs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class ManyToManyNotFoundIgnoreFixture : BugTestCase
1414
private int id2;
1515
private int _drive2Id;
1616
private readonly int _drivesCount;
17-
private int DrivesCountWithOneIgnored => _drivesCount == 0? 0 : _drivesCount - 1;
17+
private int ValidDrivesCount => _drivesCount == 0? 0 : _drivesCount - 1;
1818

1919
public ManyToManyNotFoundIgnoreFixture(int drivesCount)
2020
{
@@ -80,7 +80,7 @@ public void DeviceOfDrive()
8080

8181
Assert.That(dv1.Drives, Has.Count.EqualTo(_drivesCount).And.None.Null);
8282
// Verify one is missing
83-
Assert.That(dv2.Drives, Has.Count.EqualTo(DrivesCountWithOneIgnored).And.None.Null);
83+
Assert.That(dv2.Drives, Has.Count.EqualTo(ValidDrivesCount).And.None.Null);
8484

8585
//Make sure that flush didn't touch not-found="ignore" records for not modified collection
8686
using (var s = Sfi.OpenSession())
@@ -91,7 +91,7 @@ public void DeviceOfDrive()
9191
t.Commit();
9292
}
9393

94-
VerifyResult(expectedInCollection: DrivesCountWithOneIgnored, expectedInDb: _drivesCount, msg: "not modified collection");
94+
VerifyResult(expectedInCollection: ValidDrivesCount, expectedInDb: _drivesCount, msg: "not modified collection");
9595

9696
// Many-to-many clears collection and recreates it so not-found ignore records are lost
9797
// Note: It's not the case when no valid records are present, so loaded Drives collection is empty
@@ -128,17 +128,17 @@ void VerifyResult(int expectedInCollection, int expectedInDb, string msg)
128128
[Test]
129129
public void QueryOverFetch()
130130
{
131-
using (var s = OpenSession())
132-
{
133-
var dv2 = s.QueryOver<Device>()
134-
.Fetch(SelectMode.Fetch, x => x.Drives)
135-
.Where(Restrictions.IdEq(id2))
136-
.TransformUsing(Transformers.DistinctRootEntity)
137-
.SingleOrDefault();
138-
139-
Assert.That(NHibernateUtil.IsInitialized(dv2.Drives), Is.True);
140-
Assert.That(dv2.Drives, Has.Count.EqualTo(DrivesCountWithOneIgnored).And.None.Null);
141-
}
131+
using var log = new SqlLogSpy();
132+
using var s = OpenSession();
133+
var dv2 = s.QueryOver<Device>()
134+
.Fetch(SelectMode.Fetch, x => x.Drives)
135+
.Where(Restrictions.IdEq(id2))
136+
.TransformUsing(Transformers.DistinctRootEntity)
137+
.SingleOrDefault();
138+
139+
Assert.That(NHibernateUtil.IsInitialized(dv2.Drives), Is.True);
140+
Assert.That(dv2.Drives, Has.Count.EqualTo(ValidDrivesCount).And.None.Null);
141+
Assert.That(log.Appender.GetEvents().Length, Is.EqualTo(1));
142142
}
143143

144144
[Test]
@@ -152,21 +152,22 @@ public void HqlFetch()
152152
.UniqueResult<Device>();
153153

154154
Assert.That(NHibernateUtil.IsInitialized(dv2.Drives), Is.True);
155-
Assert.That(dv2.Drives, Has.Count.EqualTo(DrivesCountWithOneIgnored).And.None.Null);
155+
Assert.That(dv2.Drives, Has.Count.EqualTo(ValidDrivesCount).And.None.Null);
156156
Assert.That(log.Appender.GetEvents().Length, Is.EqualTo(1));
157157
}
158158

159159
[Test]
160160
public void LazyLoad()
161161
{
162-
using (var s = OpenSession())
163-
{
164-
var dv2 = s.Get<Device>(id2);
165-
NHibernateUtil.Initialize(dv2.Drives);
162+
using var log = new SqlLogSpy();
163+
using var s = OpenSession();
166164

167-
Assert.That(NHibernateUtil.IsInitialized(dv2.Drives), Is.True);
168-
Assert.That(dv2.Drives, Has.Count.EqualTo(DrivesCountWithOneIgnored).And.None.Null);
169-
}
165+
var dv2 = s.Get<Device>(id2);
166+
167+
Assert.That(NHibernateUtil.IsInitialized(dv2.Drives), Is.True);
168+
Assert.That(dv2.Drives, Has.Count.EqualTo(ValidDrivesCount).And.None.Null);
169+
// First query for Device, second for Drives collection
170+
Assert.That(log.Appender.GetEvents().Length, Is.EqualTo(2));
170171
}
171172
}
172173
}

0 commit comments

Comments
 (0)