Skip to content

Commit 289bda3

Browse files
committed
Address requested changes
1 parent 1366baf commit 289bda3

File tree

4 files changed

+180
-126
lines changed

4 files changed

+180
-126
lines changed

src/NHibernate.Test/Async/NHSpecificTest/GH948/FixtureByCode.cs renamed to src/NHibernate.Test/Async/Criteria/EntityProjectionsTest.cs

Lines changed: 68 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,52 @@
1515
using NHibernate.Transform;
1616
using NUnit.Framework;
1717

18-
namespace NHibernate.Test.NHSpecificTest.GH948
18+
namespace NHibernate.Test.Criteria
1919
{
2020
using System.Threading.Tasks;
21+
/// <summary>
22+
/// GH948
23+
/// </summary>
2124
[TestFixture]
22-
public class ByCodeFixtureAsync : TestCaseMappingByCode
25+
public class EntityProjectionsTestAsync : TestCaseMappingByCode
2326
{
2427
private EntityWithCompositeId _entityWithCompositeId;
2528

2629
protected override HbmMapping GetMappings()
2730
{
2831
var mapper = new ModelMapper();
29-
mapper.Class<EntityComplex>(rc =>
30-
{
31-
rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
32+
mapper.Class<EntityComplex>(
33+
rc =>
34+
{
35+
rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
3236

33-
rc.Version(ep => ep.Version, vm => { });
37+
rc.Version(ep => ep.Version, vm => { });
3438

35-
rc.Property(x => x.Name);
39+
rc.Property(x => x.Name);
3640

37-
rc.Property(ep => ep.LazyProp, m => m.Lazy(true));
41+
rc.Property(ep => ep.LazyProp, m => m.Lazy(true));
3842

39-
rc.ManyToOne(ep => ep.Child1, m => m.Column("Child1Id"));
40-
rc.ManyToOne(ep => ep.Child2, m => m.Column("Child2Id"));
41-
rc.ManyToOne(ep => ep.SameTypeChild, m => m.Column("SameTypeChildId"));
43+
rc.ManyToOne(ep => ep.Child1, m => m.Column("Child1Id"));
44+
rc.ManyToOne(ep => ep.Child2, m => m.Column("Child2Id"));
45+
rc.ManyToOne(ep => ep.SameTypeChild, m => m.Column("SameTypeChildId"));
4246

43-
rc.Bag(ep => ep.ChildrenList, m =>
44-
{
45-
m.Cascade(Mapping.ByCode.Cascade.All);
46-
m.Inverse(true);
47-
}, a => a.OneToMany());
48-
49-
});
47+
rc.Bag(
48+
ep => ep.ChildrenList,
49+
m =>
50+
{
51+
m.Cascade(Mapping.ByCode.Cascade.All);
52+
m.Inverse(true);
53+
},
54+
a => a.OneToMany());
5055

51-
mapper.Class<EntitySimpleChild>(rc =>
52-
{
53-
rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
54-
rc.Property(x => x.Name);
55-
});
56+
});
57+
58+
mapper.Class<EntitySimpleChild>(
59+
rc =>
60+
{
61+
rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
62+
rc.Property(x => x.Name);
63+
});
5664

5765
mapper.Class<EntityWithCompositeId>(
5866
rc =>
@@ -96,14 +104,16 @@ protected override void OnSetUp()
96104
Name = "Child1"
97105
};
98106

99-
100107
var parent = new EntityComplex
101108
{
102109
Name = "ComplexEnityParent",
103110
Child1 = child1,
104111
Child2 = child2,
105112
LazyProp = "SomeBigValue",
106-
SameTypeChild = new EntityComplex() { Name = "ComplexEntityChild" }
113+
SameTypeChild = new EntityComplex()
114+
{
115+
Name = "ComplexEntityChild"
116+
}
107117
};
108118

109119
_entityWithCompositeId = new EntityWithCompositeId
@@ -130,19 +140,19 @@ protected override void OnSetUp()
130140
[Test]
131141
public async Task RootEntityProjectionFullyInitializedAndWithUnfetchedLazyPropertiesByDefaultAsync()
132142
{
133-
using(var sqlLog = new SqlLogSpy())
143+
using (var sqlLog = new SqlLogSpy())
134144
using (var session = OpenSession())
135145
{
136146
Sfi.Statistics.Clear();
137-
EntityComplex entitypRoot = await (session
147+
EntityComplex entityRoot = await (session
138148
.QueryOver<EntityComplex>()
139149
.Where(ec => ec.LazyProp != null)
140150
.Select(Projections.RootEntity())
141151
.Take(1).SingleOrDefaultAsync());
142-
143-
Assert.That(NHibernateUtil.IsInitialized(entitypRoot),Is.True, "Object must be initialized by default");
144-
Assert.That(session.IsReadOnly(entitypRoot),Is.False, "Object must not be readonly by default");
145-
Assert.That(NHibernateUtil.IsPropertyInitialized(entitypRoot, nameof(entitypRoot.LazyProp)), Is.False, "Lazy properties should not be initialized by default.");
152+
153+
Assert.That(NHibernateUtil.IsInitialized(entityRoot), Is.True, "Object must be initialized by default");
154+
Assert.That(session.IsReadOnly(entityRoot), Is.False, "Object must not be readonly by default");
155+
Assert.That(NHibernateUtil.IsPropertyInitialized(entityRoot, nameof(entityRoot.LazyProp)), Is.False, "Lazy properties should not be initialized by default.");
146156
Assert.That(sqlLog.Appender.GetEvents().Length, Is.EqualTo(1), "Only one SQL select is expected");
147157
}
148158
}
@@ -152,13 +162,13 @@ public async Task RootEntityProjectionLazyAsync()
152162
{
153163
using (var session = OpenSession())
154164
{
155-
EntityComplex entitypRoot = await (session
165+
EntityComplex entityRoot = await (session
156166
.QueryOver<EntityComplex>()
157167
.Select(Projections.RootEntity().SetLazy(true))
158168
.Take(1).SingleOrDefaultAsync());
159-
160-
161-
Assert.That(NHibernateUtil.IsInitialized(entitypRoot),Is.False, "Object must be lazy loaded.");
169+
170+
171+
Assert.That(NHibernateUtil.IsInitialized(entityRoot), Is.False, "Object must be lazy loaded.");
162172
}
163173
}
164174

@@ -213,10 +223,10 @@ public async Task MultipleLazyEntityProjectionsAsync()
213223
Assert.That(NHibernateUtil.IsInitialized(sameTypeChild), Is.False, "Object must be lazy loaded.");
214224
Assert.That(NHibernateUtil.IsInitialized(child1), Is.False, "Object must be lazy loaded.");
215225
Assert.That(NHibernateUtil.IsInitialized(child2), Is.False, "Object must be lazy loaded.");
216-
226+
217227
//make sure objects are populated from different aliases for the same types
218-
Assert.That(root.Id , Is.Not.EqualTo(sameTypeChild.Id), "Different objects are expected.");
219-
Assert.That(child1.Id , Is.Not.EqualTo(child2.Id), "Different objects are expected.");
228+
Assert.That(root.Id, Is.Not.EqualTo(sameTypeChild.Id), "Different objects are expected.");
229+
Assert.That(child1.Id, Is.Not.EqualTo(child2.Id), "Different objects are expected.");
220230

221231
}
222232
}
@@ -226,15 +236,15 @@ public async Task EntityProjectionWithLazyPropertiesFetchedAsync()
226236
{
227237
using (var session = OpenSession())
228238
{
229-
EntityComplex entitypRoot = await (session
239+
EntityComplex entityRoot = await (session
230240
.QueryOver<EntityComplex>()
231241
.Where(ec => ec.LazyProp != null)
232-
.Select(Projections.RootEntity().SetAllPropertyFetch(true))
242+
.Select(Projections.RootEntity().SetFetchLazyProperties(true))
233243
.Take(1).SingleOrDefaultAsync());
234244

235-
Assert.That(entitypRoot, Is.Not.Null);
236-
Assert.That(NHibernateUtil.IsInitialized(entitypRoot), Is.True, "Object must be initialized");
237-
Assert.That(NHibernateUtil.IsPropertyInitialized(entitypRoot, nameof(entitypRoot.LazyProp)), Is.True, "Lazy property must be initialized");
245+
Assert.That(entityRoot, Is.Not.Null);
246+
Assert.That(NHibernateUtil.IsInitialized(entityRoot), Is.True, "Object must be initialized");
247+
Assert.That(NHibernateUtil.IsPropertyInitialized(entityRoot, nameof(entityRoot.LazyProp)), Is.True, "Lazy property must be initialized");
238248
}
239249
}
240250

@@ -319,18 +329,18 @@ public async Task MultipleEntitiesProjectionsToResultTransformerAsync()
319329
EntitySimpleChild nullListElem = null;
320330

321331
r = await (session
322-
.QueryOver<EntityComplex>()
323-
.JoinAlias(ep => ep.Child1, () => child1)
324-
.JoinAlias(ep => ep.Child2, () => child2)
325-
.JoinAlias(ep => ep.SameTypeChild, () => sameAsRootChild)
326-
.JoinAlias(ep => ep.ChildrenList, () => nullListElem, JoinType.LeftOuterJoin)
327-
.Select(
328-
Projections.Alias(Projections.RootEntity(), nameof(r.Root)),
329-
Projections.Entity(() => child1),
330-
Projections.Entity(() => child2),
331-
Projections.Entity(() => sameAsRootChild),
332-
Projections.Entity(() => nullListElem)
333-
)
332+
.QueryOver<EntityComplex>()
333+
.JoinAlias(ep => ep.Child1, () => child1)
334+
.JoinAlias(ep => ep.Child2, () => child2)
335+
.JoinAlias(ep => ep.SameTypeChild, () => sameAsRootChild)
336+
.JoinAlias(ep => ep.ChildrenList, () => nullListElem, JoinType.LeftOuterJoin)
337+
.Select(
338+
Projections.Alias(Projections.RootEntity(), nameof(r.Root)),
339+
Projections.Entity(() => child1),
340+
Projections.Entity(() => child2),
341+
Projections.Entity(() => sameAsRootChild),
342+
Projections.Entity(() => nullListElem)
343+
)
334344
.TransformUsing(Transformers.AliasToBean<MultipleEntitiesResult>())
335345
.Take(1)
336346
.SingleOrDefaultAsync<MultipleEntitiesResult>());
@@ -350,12 +360,12 @@ public async Task ReadOnlyProjectionAsync()
350360
{
351361
using (var session = OpenSession())
352362
{
353-
EntityComplex entitypRoot = await (session
363+
EntityComplex entityRoot = await (session
354364
.QueryOver<EntityComplex>()
355365
.Select(Projections.RootEntity().SetReadonly(true))
356366
.Take(1).SingleOrDefaultAsync());
357367

358-
Assert.That(session.IsReadOnly(entitypRoot), Is.True, "Object must be loaded readonly.");
368+
Assert.That(session.IsReadOnly(entityRoot), Is.True, "Object must be loaded readonly.");
359369
}
360370
}
361371

@@ -375,7 +385,7 @@ public async Task EntityProjectionForCompositeKeyInitializedAsync()
375385
Assert.That(composite, Is.EqualTo(_entityWithCompositeId).Using((EntityWithCompositeId x, EntityWithCompositeId y) => (Equals(x.Key, y.Key) && Equals(x.Name, y.Name)) ? 0 : 1));
376386
Assert.That(sqlLog.Appender.GetEvents().Length, Is.EqualTo(1), "Only one SQL select is expected");
377387
}
378-
388+
379389
}
380390

381391
[Test]

src/NHibernate.Test/NHSpecificTest/GH948/Entities.cs renamed to src/NHibernate.Test/Criteria/EntityProjectionsEntities.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33

4-
namespace NHibernate.Test.NHSpecificTest.GH948
4+
namespace NHibernate.Test.Criteria
55
{
66
public class EntitySimpleChild
77
{
@@ -14,7 +14,7 @@ public class EntityComplex
1414
public virtual Guid Id { get; set; }
1515

1616
public virtual int Version { get; set; }
17-
17+
1818
public virtual string Name { get; set; }
1919

2020
public virtual string LazyProp { get; set; }

0 commit comments

Comments
 (0)