Skip to content

Commit 21b39ab

Browse files
committed
More tests
1 parent a7cd433 commit 21b39ab

8 files changed

+129
-17
lines changed

src/NHibernate.Test/Async/NHSpecificTest/GH2201/CircularReferenceFetchDepth0Fixture.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ public class CircularReferenceFetchDepth0FixtureAsync : BaseFetchFixture
1919
{
2020
private int _id2;
2121

22+
public CircularReferenceFetchDepth0FixtureAsync() : base(0)
23+
{
24+
}
25+
2226
protected override void Configure(Configuration configuration)
2327
{
2428
configuration.SetProperty("max_fetch_depth", "0");
2529
base.Configure(configuration);
2630
}
31+
2732
protected override void OnSetUp()
2833
{
2934
base.OnSetUp();

src/NHibernate.Test/Async/NHSpecificTest/GH2201/CircularReferenceFetchDepth1Fixture.cs renamed to src/NHibernate.Test/Async/NHSpecificTest/GH2201/CircularReferenceFetchDepthFixture.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,52 @@
1414
namespace NHibernate.Test.NHSpecificTest.GH2201
1515
{
1616
using System.Threading.Tasks;
17-
[TestFixture]
18-
public class CircularReferenceFetchDepth1FixtureAsync : BaseFetchFixture
17+
[TestFixture(1)]
18+
[TestFixture(2)]
19+
public class CircularReferenceFetchDepthFixtureAsync : BaseFetchFixture
1920
{
2021
private int _id2;
22+
private int _id3;
23+
24+
public CircularReferenceFetchDepthFixtureAsync(int depth) : base(depth)
25+
{
26+
}
2127

2228
protected override void Configure(Configuration configuration)
2329
{
24-
configuration.SetProperty("max_fetch_depth", "1");
30+
configuration.SetProperty("max_fetch_depth", _depth.ToString());
2531
base.Configure(configuration);
2632
}
33+
2734
protected override void OnSetUp()
2835
{
2936
base.OnSetUp();
3037
_id2 = _id;
31-
//Generate another test entity
38+
39+
//Generate another test entities
40+
base.OnSetUp();
41+
_id3 = _id;
3242
base.OnSetUp();
3343
}
3444

3545
[Test]
3646
public async Task QueryOverAsync()
3747
{
48+
using(var logSpy = new SqlLogSpy())
3849
using (var session = OpenSession())
3950
{
4051
Entity e1 = null;
4152
Entity e2 = null;
53+
Entity e3 = null;
4254
var result = await (session.QueryOver<Entity>(() => e1)
43-
.JoinEntityAlias(() => e2, () => e2.EntityNumber == e1.EntityNumber && e2.EntityId != _id)
55+
.JoinEntityAlias(() => e2, () => e2.EntityNumber == e1.EntityNumber && e2.EntityId == _id2)
56+
.JoinEntityAlias(() => e3, () => e3.EntityNumber == e1.EntityNumber && e3.EntityId == _id3)
4457
.Where(e => e.EntityId == _id).SingleOrDefaultAsync());
4558

4659
Verify(result);
60+
4761
Verify(await (session.LoadAsync<Entity>(_id2)));
62+
Verify(await (session.LoadAsync<Entity>(_id3)));
4863
}
4964
}
5065

src/NHibernate.Test/Async/NHSpecificTest/GH2201/CircularReferenceFetchFixture.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ namespace NHibernate.Test.NHSpecificTest.GH2201
1919
[TestFixture]
2020
public class CircularReferenceFetchFixtureAsync : BaseFetchFixture
2121
{
22+
public CircularReferenceFetchFixtureAsync() : base(-1)
23+
{
24+
}
25+
2226
[Test]
2327
public async Task QueryOverAsync()
2428
{

src/NHibernate.Test/NHSpecificTest/GH2201/BaseFetchFixture.cs

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ namespace NHibernate.Test.NHSpecificTest.GH2201
77
public class BaseFetchFixture : TestCaseMappingByCode
88
{
99
protected int _id;
10+
protected int _depth;
11+
12+
protected BaseFetchFixture(int depth)
13+
{
14+
_depth = depth < 0 ? int.MaxValue : depth;
15+
}
1016

1117
protected override HbmMapping GetMappings()
1218
{
@@ -39,6 +45,38 @@ protected override HbmMapping GetMappings()
3945
p.Cascade(Mapping.ByCode.Cascade.Persist);
4046
p.ForeignKey("none");
4147
});
48+
m.ManyToOne(c => c.Level1, p =>
49+
{
50+
p.Column("Level1Id");
51+
p.Fetch(FetchKind.Join);
52+
p.Cascade(Mapping.ByCode.Cascade.Persist);
53+
p.ForeignKey("none");
54+
});
55+
});
56+
57+
mapper.Class<Level1Entity>(m =>
58+
{
59+
m.Id(c => c.Id, id =>
60+
{
61+
id.Generator(Generators.Native);
62+
});
63+
m.Property(c => c.Name);
64+
m.ManyToOne(c => c.Level2, p =>
65+
{
66+
p.Column("Level2Id");
67+
p.Fetch(FetchKind.Join);
68+
p.Cascade(Mapping.ByCode.Cascade.Persist);
69+
p.ForeignKey("none");
70+
});
71+
});
72+
73+
mapper.Class<Level2Entity>(m =>
74+
{
75+
m.Id(c => c.Id, id =>
76+
{
77+
id.Generator(Generators.Native);
78+
});
79+
m.Property(c => c.Name);
4280
});
4381

4482
return mapper.CompileMappingForAllExplicitlyAddedEntities();
@@ -55,6 +93,7 @@ protected override void OnSetUp()
5593
AdditionalEntity = CreateEntity(),
5694
ReferencedEntity = CreateEntity(),
5795
SourceEntity = CreateEntity(),
96+
Level1 = new Level1Entity() { Level2 = new Level2Entity() }
5897
};
5998
session.Save(e1);
6099
transaction.Commit();
@@ -68,6 +107,7 @@ private static Entity CreateEntity()
68107
SourceEntity = new Entity(),
69108
AdditionalEntity = new Entity(),
70109
ReferencedEntity = new Entity(),
110+
Level1 = new Level1Entity() { Level2 = new Level2Entity() }
71111
};
72112
}
73113

@@ -82,26 +122,34 @@ protected override void OnTearDown()
82122
}
83123
}
84124

85-
protected static void Verify(Entity result)
125+
protected void Verify(Entity result)
86126
{
87-
88127
VerifyChildrenInitialized(result);
89128

90129
VerifyChildrenNotInitialized(result.AdditionalEntity);
91130
VerifyChildrenNotInitialized(result.SourceEntity);
92131
VerifyChildrenNotInitialized(result.ReferencedEntity);
132+
93133
}
94134

95-
protected static void VerifyChildrenInitialized(Entity result)
135+
protected void VerifyChildrenInitialized(Entity result)
96136
{
137+
var isInited = _depth > 0 ? (NUnit.Framework.Constraints.IResolveConstraint) Is.True : Is.False;
97138
Assert.That(result, Is.Not.Null);
98-
Assert.That(NHibernateUtil.IsInitialized(result), Is.True);
139+
Assert.That(NHibernateUtil.IsInitialized(result), isInited);
99140
Assert.That(result.AdditionalEntity, Is.Not.Null);
100-
Assert.That(NHibernateUtil.IsInitialized(result.AdditionalEntity), Is.True);
141+
Assert.That(NHibernateUtil.IsInitialized(result.AdditionalEntity), isInited);
101142
Assert.That(result.SourceEntity, Is.Not.Null);
102-
Assert.That(NHibernateUtil.IsInitialized(result.SourceEntity), Is.True);
143+
Assert.That(NHibernateUtil.IsInitialized(result.SourceEntity), isInited);
103144
Assert.That(result.ReferencedEntity, Is.Not.Null);
104-
Assert.That(NHibernateUtil.IsInitialized(result.ReferencedEntity), Is.True);
145+
Assert.That(NHibernateUtil.IsInitialized(result.ReferencedEntity), isInited);
146+
Assert.That(result.Level1, Is.Not.Null);
147+
Assert.That(NHibernateUtil.IsInitialized(result.Level1), isInited);
148+
if (_depth >= 1)
149+
{
150+
Assert.That(result.Level1.Level2, Is.Not.Null);
151+
Assert.That(NHibernateUtil.IsInitialized(result.Level1.Level2), _depth > 1 ? Is.True : Is.False);
152+
}
105153
}
106154

107155
protected static void VerifyChildrenNotInitialized(Entity result)
@@ -114,6 +162,8 @@ protected static void VerifyChildrenNotInitialized(Entity result)
114162
Assert.That(NHibernateUtil.IsInitialized(result.SourceEntity), Is.False);
115163
Assert.That(result.ReferencedEntity, Is.Not.Null);
116164
Assert.That(NHibernateUtil.IsInitialized(result.ReferencedEntity), Is.False);
165+
Assert.That(result.Level1, Is.Not.Null);
166+
Assert.That(NHibernateUtil.IsInitialized(result.Level1), Is.False);
117167
}
118168
}
119169
}

src/NHibernate.Test/NHSpecificTest/GH2201/CircularReferenceFetchDepth0Fixture.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ public class CircularReferenceFetchDepth0Fixture : BaseFetchFixture
88
{
99
private int _id2;
1010

11+
public CircularReferenceFetchDepth0Fixture() : base(0)
12+
{
13+
}
14+
1115
protected override void Configure(Configuration configuration)
1216
{
1317
configuration.SetProperty("max_fetch_depth", "0");
1418
base.Configure(configuration);
1519
}
20+
1621
protected override void OnSetUp()
1722
{
1823
base.OnSetUp();

src/NHibernate.Test/NHSpecificTest/GH2201/CircularReferenceFetchDepth1Fixture.cs renamed to src/NHibernate.Test/NHSpecificTest/GH2201/CircularReferenceFetchDepthFixture.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,52 @@
33

44
namespace NHibernate.Test.NHSpecificTest.GH2201
55
{
6-
[TestFixture]
7-
public class CircularReferenceFetchDepth1Fixture : BaseFetchFixture
6+
[TestFixture(1)]
7+
[TestFixture(2)]
8+
public class CircularReferenceFetchDepthFixture : BaseFetchFixture
89
{
910
private int _id2;
11+
private int _id3;
12+
13+
public CircularReferenceFetchDepthFixture(int depth) : base(depth)
14+
{
15+
}
1016

1117
protected override void Configure(Configuration configuration)
1218
{
13-
configuration.SetProperty("max_fetch_depth", "1");
19+
configuration.SetProperty("max_fetch_depth", _depth.ToString());
1420
base.Configure(configuration);
1521
}
22+
1623
protected override void OnSetUp()
1724
{
1825
base.OnSetUp();
1926
_id2 = _id;
20-
//Generate another test entity
27+
28+
//Generate another test entities
29+
base.OnSetUp();
30+
_id3 = _id;
2131
base.OnSetUp();
2232
}
2333

2434
[Test]
2535
public void QueryOver()
2636
{
37+
using(var logSpy = new SqlLogSpy())
2738
using (var session = OpenSession())
2839
{
2940
Entity e1 = null;
3041
Entity e2 = null;
42+
Entity e3 = null;
3143
var result = session.QueryOver<Entity>(() => e1)
32-
.JoinEntityAlias(() => e2, () => e2.EntityNumber == e1.EntityNumber && e2.EntityId != _id)
44+
.JoinEntityAlias(() => e2, () => e2.EntityNumber == e1.EntityNumber && e2.EntityId == _id2)
45+
.JoinEntityAlias(() => e3, () => e3.EntityNumber == e1.EntityNumber && e3.EntityId == _id3)
3346
.Where(e => e.EntityId == _id).SingleOrDefault();
3447

3548
Verify(result);
49+
3650
Verify(session.Load<Entity>(_id2));
51+
Verify(session.Load<Entity>(_id3));
3752
}
3853
}
3954

src/NHibernate.Test/NHSpecificTest/GH2201/CircularReferenceFetchFixture.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ namespace NHibernate.Test.NHSpecificTest.GH2201
88
[TestFixture]
99
public class CircularReferenceFetchFixture : BaseFetchFixture
1010
{
11+
public CircularReferenceFetchFixture() : base(-1)
12+
{
13+
}
14+
1115
[Test]
1216
public void QueryOver()
1317
{

src/NHibernate.Test/NHSpecificTest/GH2201/Entity.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,19 @@ public class Entity
77
public virtual Entity ReferencedEntity { get; set; }
88
public virtual Entity AdditionalEntity { get; set; }
99
public virtual Entity SourceEntity { get; set; }
10+
public virtual Level1Entity Level1 { get; set; }
11+
}
12+
13+
public class Level1Entity
14+
{
15+
public virtual int Id { get; set; }
16+
public virtual string Name { get; set; }
17+
public virtual Level2Entity Level2 { get; set; }
18+
}
19+
20+
public class Level2Entity
21+
{
22+
public virtual int Id { get; set; }
23+
public virtual string Name { get; set; }
1024
}
1125
}

0 commit comments

Comments
 (0)