Skip to content

Commit 849b031

Browse files
Generate async files
1 parent 2902396 commit 849b031

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

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

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class ManyToManyNotFoundIgnoreFixtureAsync : BugTestCase
2525
private int id2;
2626
private int _drive2Id;
2727
private readonly int _drivesCount;
28-
private int DrivesCountWithOneIgnored => _drivesCount == 0? 0 : _drivesCount - 1;
28+
private int ValidDrivesCount => _drivesCount == 0? 0 : _drivesCount - 1;
2929

3030
public ManyToManyNotFoundIgnoreFixtureAsync(int drivesCount)
3131
{
@@ -91,7 +91,7 @@ public async Task DeviceOfDriveAsync()
9191

9292
Assert.That(dv1.Drives, Has.Count.EqualTo(_drivesCount).And.None.Null);
9393
// Verify one is missing
94-
Assert.That(dv2.Drives, Has.Count.EqualTo(DrivesCountWithOneIgnored).And.None.Null);
94+
Assert.That(dv2.Drives, Has.Count.EqualTo(ValidDrivesCount).And.None.Null);
9595

9696
//Make sure that flush didn't touch not-found="ignore" records for not modified collection
9797
using (var s = Sfi.OpenSession())
@@ -102,7 +102,7 @@ public async Task DeviceOfDriveAsync()
102102
await (t.CommitAsync());
103103
}
104104

105-
await (VerifyResultAsync(expectedInCollection: DrivesCountWithOneIgnored, expectedInDb: _drivesCount, msg: "not modified collection"));
105+
await (VerifyResultAsync(expectedInCollection: ValidDrivesCount, expectedInDb: _drivesCount, msg: "not modified collection"));
106106

107107
// Many-to-many clears collection and recreates it so not-found ignore records are lost
108108
// Note: It's not the case when no valid records are present, so loaded Drives collection is empty
@@ -139,17 +139,17 @@ async Task VerifyResultAsync(int expectedInCollection, int expectedInDb, string
139139
[Test]
140140
public async Task QueryOverFetchAsync()
141141
{
142-
using (var s = OpenSession())
143-
{
144-
var dv2 = await (s.QueryOver<Device>()
145-
.Fetch(SelectMode.Fetch, x => x.Drives)
146-
.Where(Restrictions.IdEq(id2))
147-
.TransformUsing(Transformers.DistinctRootEntity)
148-
.SingleOrDefaultAsync());
149-
150-
Assert.That(NHibernateUtil.IsInitialized(dv2.Drives), Is.True);
151-
Assert.That(dv2.Drives, Has.Count.EqualTo(DrivesCountWithOneIgnored).And.None.Null);
152-
}
142+
using var log = new SqlLogSpy();
143+
using var s = OpenSession();
144+
var dv2 = await (s.QueryOver<Device>()
145+
.Fetch(SelectMode.Fetch, x => x.Drives)
146+
.Where(Restrictions.IdEq(id2))
147+
.TransformUsing(Transformers.DistinctRootEntity)
148+
.SingleOrDefaultAsync());
149+
150+
Assert.That(NHibernateUtil.IsInitialized(dv2.Drives), Is.True);
151+
Assert.That(dv2.Drives, Has.Count.EqualTo(ValidDrivesCount).And.None.Null);
152+
Assert.That(log.Appender.GetEvents().Length, Is.EqualTo(1));
153153
}
154154

155155
[Test]
@@ -163,21 +163,22 @@ public async Task HqlFetchAsync()
163163
.UniqueResultAsync<Device>());
164164

165165
Assert.That(NHibernateUtil.IsInitialized(dv2.Drives), Is.True);
166-
Assert.That(dv2.Drives, Has.Count.EqualTo(DrivesCountWithOneIgnored).And.None.Null);
166+
Assert.That(dv2.Drives, Has.Count.EqualTo(ValidDrivesCount).And.None.Null);
167167
Assert.That(log.Appender.GetEvents().Length, Is.EqualTo(1));
168168
}
169169

170170
[Test]
171171
public async Task LazyLoadAsync()
172172
{
173-
using (var s = OpenSession())
174-
{
175-
var dv2 = await (s.GetAsync<Device>(id2));
176-
await (NHibernateUtil.InitializeAsync(dv2.Drives));
173+
using var log = new SqlLogSpy();
174+
using var s = OpenSession();
177175

178-
Assert.That(NHibernateUtil.IsInitialized(dv2.Drives), Is.True);
179-
Assert.That(dv2.Drives, Has.Count.EqualTo(DrivesCountWithOneIgnored).And.None.Null);
180-
}
176+
var dv2 = await (s.GetAsync<Device>(id2));
177+
178+
Assert.That(NHibernateUtil.IsInitialized(dv2.Drives), Is.True);
179+
Assert.That(dv2.Drives, Has.Count.EqualTo(ValidDrivesCount).And.None.Null);
180+
// First query for Device, second for Drives collection
181+
Assert.That(log.Appender.GetEvents().Length, Is.EqualTo(2));
181182
}
182183
}
183184
}

0 commit comments

Comments
 (0)