Skip to content

Commit ebaf8aa

Browse files
committed
More tests
1 parent a555cd0 commit ebaf8aa

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

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

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,25 @@ namespace NHibernate.Test.NHSpecificTest.NH750
1010
public class ManyToManyThrowsForNotFoundFixture : BugTestCase
1111
{
1212
private int _id;
13+
private int _withTempalteId;
1314

1415
protected override void OnSetUp()
1516
{
16-
using (var s = Sfi.OpenSession())
17-
using (var t = s.BeginTransaction())
18-
{
19-
Device dv = new Device("Device");
20-
Drive dr = new Drive("Drive");
21-
s.Save(dr);
22-
dv.DrivesNotIgnored.Add(dr);
17+
using var s = Sfi.OpenSession();
18+
using var t = s.BeginTransaction();
19+
Device dv = new Device("Device");
20+
Drive dr = new Drive("Drive");
21+
var withTempalte = new Device("Device With Device 2 template") { Template = dv };
22+
s.Save(dr);
23+
dv.DrivesNotIgnored.Add(dr);
2324

24-
_id = (int) s.Save(dv);
25-
s.Flush();
25+
_id = (int) s.Save(dv);
26+
_withTempalteId = (int)s.Save(withTempalte);
27+
s.Flush();
2628

27-
s.Clear();
28-
s.Delete(dr);
29-
t.Commit();
30-
}
29+
s.Clear();
30+
s.Delete(dr);
31+
t.Commit();
3132
}
3233

3334
protected override void OnTearDown()
@@ -58,7 +59,18 @@ public void QueryOverFetch()
5859
.Fetch(SelectMode.Fetch, x => x.DrivesNotIgnored)
5960
.Where(Restrictions.IdEq(_id))
6061
.TransformUsing(Transformers.DistinctRootEntity);
61-
Assert.Throws<ObjectNotFoundException>(() => NHibernateUtil.Initialize(queryOver.SingleOrDefault()));
62+
Assert.Throws<ObjectNotFoundException>(() => queryOver.SingleOrDefault());
63+
}
64+
65+
[Test]
66+
public void QueryOverFetch2()
67+
{
68+
using var s = OpenSession();
69+
var queryOver = s.QueryOver<Device>()
70+
.Fetch(SelectMode.Fetch, x=> x.Template, x => x.Template.DrivesNotIgnored)
71+
.Where(Restrictions.IdEq(_withTempalteId))
72+
.TransformUsing(Transformers.DistinctRootEntity);
73+
Assert.Throws<ObjectNotFoundException>(() => queryOver.SingleOrDefault());
6274
}
6375

6476
[Test]
@@ -71,5 +83,17 @@ public void LinqFetch()
7183
.Where(x => x.Id == _id);
7284
Assert.Throws<ObjectNotFoundException>(() => NHibernateUtil.Initialize(query.SingleOrDefault()));
7385
}
86+
87+
[Test]
88+
public void LinqFetch2()
89+
{
90+
using var s = OpenSession();
91+
var query = s.Query<Device>()
92+
93+
.Fetch(x => x.Template)
94+
.ThenFetchMany(x => x.DrivesNotIgnored)
95+
.Where(x => x.Id == _withTempalteId);
96+
Assert.Throws<ObjectNotFoundException>(() => NHibernateUtil.Initialize(query.SingleOrDefault()));
97+
}
7498
}
7599
}

src/NHibernate.Test/SubselectFetchTest/SubselectFetchFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public void ManyToManyCriteriaJoin()
280280

281281
s = OpenSession();
282282
t = s.BeginTransaction();
283-
var log = new SqlLogSpy();
283+
284284
s.CreateCriteria(typeof(Parent))
285285
.AddOrder(Order.Desc("Name"))
286286
// H3 has this after CreateCriteria("Friends"), but it's not yet supported in NH

0 commit comments

Comments
 (0)