@@ -14,7 +14,7 @@ public class ManyToManyNotFoundIgnoreFixture : BugTestCase
14
14
private int id2 ;
15
15
private int _drive2Id ;
16
16
private readonly int _drivesCount ;
17
- private int DrivesCountWithOneIgnored => _drivesCount == 0 ? 0 : _drivesCount - 1 ;
17
+ private int ValidDrivesCount => _drivesCount == 0 ? 0 : _drivesCount - 1 ;
18
18
19
19
public ManyToManyNotFoundIgnoreFixture ( int drivesCount )
20
20
{
@@ -80,7 +80,7 @@ public void DeviceOfDrive()
80
80
81
81
Assert . That ( dv1 . Drives , Has . Count . EqualTo ( _drivesCount ) . And . None . Null ) ;
82
82
// 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 ) ;
84
84
85
85
//Make sure that flush didn't touch not-found="ignore" records for not modified collection
86
86
using ( var s = Sfi . OpenSession ( ) )
@@ -91,7 +91,7 @@ public void DeviceOfDrive()
91
91
t . Commit ( ) ;
92
92
}
93
93
94
- VerifyResult ( expectedInCollection : DrivesCountWithOneIgnored , expectedInDb : _drivesCount , msg : "not modified collection" ) ;
94
+ VerifyResult ( expectedInCollection : ValidDrivesCount , expectedInDb : _drivesCount , msg : "not modified collection" ) ;
95
95
96
96
// Many-to-many clears collection and recreates it so not-found ignore records are lost
97
97
// 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)
128
128
[ Test ]
129
129
public void QueryOverFetch ( )
130
130
{
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 ) ) ;
142
142
}
143
143
144
144
[ Test ]
@@ -152,21 +152,22 @@ public void HqlFetch()
152
152
. UniqueResult < Device > ( ) ;
153
153
154
154
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 ) ;
156
156
Assert . That ( log . Appender . GetEvents ( ) . Length , Is . EqualTo ( 1 ) ) ;
157
157
}
158
158
159
159
[ Test ]
160
160
public void LazyLoad ( )
161
161
{
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 ( ) ;
166
164
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 ) ) ;
170
171
}
171
172
}
172
173
}
0 commit comments