@@ -21,24 +21,25 @@ namespace NHibernate.Test.NHSpecificTest.NH750
21
21
public class ManyToManyThrowsForNotFoundFixtureAsync : BugTestCase
22
22
{
23
23
private int _id ;
24
+ private int _withTempalteId ;
24
25
25
26
protected override void OnSetUp ( )
26
27
{
27
- using ( var s = Sfi . OpenSession ( ) )
28
- using ( var t = s . BeginTransaction ( ) )
29
- {
30
- Device dv = new Device ( "Device ") ;
31
- Drive dr = new Drive ( "Drive" ) ;
32
- s . Save ( dr ) ;
33
- dv . DrivesNotIgnored . Add ( dr ) ;
28
+ using var s = Sfi . OpenSession ( ) ;
29
+ using var t = s . BeginTransaction ( ) ;
30
+ Device dv = new Device ( "Device" ) ;
31
+ Drive dr = new Drive ( "Drive ") ;
32
+ var withTempalte = new Device ( "Device With Device 2 template" ) { Template = dv } ;
33
+ s . Save ( dr ) ;
34
+ dv . DrivesNotIgnored . Add ( dr ) ;
34
35
35
- _id = ( int ) s . Save ( dv ) ;
36
- s . Flush ( ) ;
36
+ _id = ( int ) s . Save ( dv ) ;
37
+ _withTempalteId = ( int ) s . Save ( withTempalte ) ;
38
+ s . Flush ( ) ;
37
39
38
- s . Clear ( ) ;
39
- s . Delete ( dr ) ;
40
- t . Commit ( ) ;
41
- }
40
+ s . Clear ( ) ;
41
+ s . Delete ( dr ) ;
42
+ t . Commit ( ) ;
42
43
}
43
44
44
45
protected override void OnTearDown ( )
@@ -69,7 +70,18 @@ public void QueryOverFetchAsync()
69
70
. Fetch ( SelectMode . Fetch , x => x . DrivesNotIgnored )
70
71
. Where ( Restrictions . IdEq ( _id ) )
71
72
. TransformUsing ( Transformers . DistinctRootEntity ) ;
72
- Assert . ThrowsAsync < ObjectNotFoundException > ( async ( ) => await ( NHibernateUtil . InitializeAsync ( await ( queryOver . SingleOrDefaultAsync ( ) ) ) ) ) ;
73
+ Assert . ThrowsAsync < ObjectNotFoundException > ( ( ) => queryOver . SingleOrDefaultAsync ( ) ) ;
74
+ }
75
+
76
+ [ Test ]
77
+ public void QueryOverFetch2Async ( )
78
+ {
79
+ using var s = OpenSession ( ) ;
80
+ var queryOver = s . QueryOver < Device > ( )
81
+ . Fetch ( SelectMode . Fetch , x=> x . Template , x => x . Template . DrivesNotIgnored )
82
+ . Where ( Restrictions . IdEq ( _withTempalteId ) )
83
+ . TransformUsing ( Transformers . DistinctRootEntity ) ;
84
+ Assert . ThrowsAsync < ObjectNotFoundException > ( ( ) => queryOver . SingleOrDefaultAsync ( ) ) ;
73
85
}
74
86
75
87
[ Test ]
@@ -82,5 +94,17 @@ public void LinqFetchAsync()
82
94
. Where ( x => x . Id == _id ) ;
83
95
Assert . ThrowsAsync < ObjectNotFoundException > ( async ( ) => await ( NHibernateUtil . InitializeAsync ( await ( query . SingleOrDefaultAsync ( ) ) ) ) ) ;
84
96
}
97
+
98
+ [ Test ]
99
+ public void LinqFetch2Async ( )
100
+ {
101
+ using var s = OpenSession ( ) ;
102
+ var query = s . Query < Device > ( )
103
+
104
+ . Fetch ( x => x . Template )
105
+ . ThenFetchMany ( x => x . DrivesNotIgnored )
106
+ . Where ( x => x . Id == _withTempalteId ) ;
107
+ Assert . ThrowsAsync < ObjectNotFoundException > ( async ( ) => await ( NHibernateUtil . InitializeAsync ( await ( query . SingleOrDefaultAsync ( ) ) ) ) ) ;
108
+ }
85
109
}
86
110
}
0 commit comments