@@ -25,7 +25,7 @@ public class ManyToManyNotFoundIgnoreFixtureAsync : BugTestCase
25
25
private int id2 ;
26
26
private int _drive2Id ;
27
27
private readonly int _drivesCount ;
28
- private int DrivesCountWithOneIgnored => _drivesCount == 0 ? 0 : _drivesCount - 1 ;
28
+ private int ValidDrivesCount => _drivesCount == 0 ? 0 : _drivesCount - 1 ;
29
29
30
30
public ManyToManyNotFoundIgnoreFixtureAsync ( int drivesCount )
31
31
{
@@ -91,7 +91,7 @@ public async Task DeviceOfDriveAsync()
91
91
92
92
Assert . That ( dv1 . Drives , Has . Count . EqualTo ( _drivesCount ) . And . None . Null ) ;
93
93
// 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 ) ;
95
95
96
96
//Make sure that flush didn't touch not-found="ignore" records for not modified collection
97
97
using ( var s = Sfi . OpenSession ( ) )
@@ -102,7 +102,7 @@ public async Task DeviceOfDriveAsync()
102
102
await ( t . CommitAsync ( ) ) ;
103
103
}
104
104
105
- await ( VerifyResultAsync ( expectedInCollection : DrivesCountWithOneIgnored , expectedInDb : _drivesCount , msg : "not modified collection" ) ) ;
105
+ await ( VerifyResultAsync ( expectedInCollection : ValidDrivesCount , expectedInDb : _drivesCount , msg : "not modified collection" ) ) ;
106
106
107
107
// Many-to-many clears collection and recreates it so not-found ignore records are lost
108
108
// 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
139
139
[ Test ]
140
140
public async Task QueryOverFetchAsync ( )
141
141
{
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 ) ) ;
153
153
}
154
154
155
155
[ Test ]
@@ -163,21 +163,22 @@ public async Task HqlFetchAsync()
163
163
. UniqueResultAsync < Device > ( ) ) ;
164
164
165
165
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 ) ;
167
167
Assert . That ( log . Appender . GetEvents ( ) . Length , Is . EqualTo ( 1 ) ) ;
168
168
}
169
169
170
170
[ Test ]
171
171
public async Task LazyLoadAsync ( )
172
172
{
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 ( ) ;
177
175
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 ) ) ;
181
182
}
182
183
}
183
184
}
0 commit comments