Skip to content

Commit 263df3e

Browse files
committed
Test case
1 parent 86d463a commit 263df3e

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
using System.Linq;
2+
using NHibernate.Cfg.MappingSchema;
3+
using NHibernate.Linq;
4+
using NHibernate.Mapping.ByCode;
5+
using NUnit.Framework;
6+
7+
namespace NHibernate.Test.NHSpecificTest.GH3289
8+
{
9+
[TestFixture]
10+
public class ByCodeFixture : TestCaseMappingByCode
11+
{
12+
protected override HbmMapping GetMappings()
13+
{
14+
var mapper = new ModelMapper();
15+
mapper.Class<Entity>(rc =>
16+
{
17+
rc.Id(x => x.Id, m => m.Generator(Generators.Identity));
18+
rc.Property(x => x.Name);
19+
rc.Component(x => x.Component);
20+
});
21+
mapper.JoinedSubclass<SubEntity>(rc =>
22+
{
23+
rc.EntityName(typeof(ISubEntity).FullName);
24+
rc.Key(k => k.Column("Id"));
25+
rc.Property(x => x.SomeProperty);
26+
});
27+
mapper.Component<Component>(rc =>
28+
{
29+
rc.Property(x => x.Field);
30+
rc.Lazy(true);
31+
});
32+
33+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
34+
}
35+
36+
protected override void OnSetUp()
37+
{
38+
using (var session = OpenSession())
39+
using (var transaction = session.BeginTransaction())
40+
{
41+
var e1 = new SubEntity { Name = "Jim" };
42+
session.Save(e1);
43+
44+
transaction.Commit();
45+
}
46+
}
47+
48+
protected override void OnTearDown()
49+
{
50+
using (var session = OpenSession())
51+
using (var transaction = session.BeginTransaction())
52+
{
53+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
54+
55+
transaction.Commit();
56+
}
57+
}
58+
59+
[Test]
60+
public void TestSubEntityInterfaceWithFetchIsPropertyInitialized()
61+
{
62+
using (var session = OpenSession())
63+
using (var transaction = session.BeginTransaction())
64+
{
65+
var data = session.Query<ISubEntity>()
66+
.Fetch(e => e.Component)
67+
.ToList();
68+
var result = NHibernateUtil.IsPropertyInitialized(data[0], "Component");
69+
70+
Assert.That(result, Is.True);
71+
}
72+
}
73+
74+
[Test]
75+
public void TestSubEntityWithFetchIsPropertyInitialized()
76+
{
77+
using (var session = OpenSession())
78+
using (var transaction = session.BeginTransaction())
79+
{
80+
var data = session.Query<SubEntity>()
81+
.Fetch(e => e.Component)
82+
.ToList();
83+
var result = NHibernateUtil.IsPropertyInitialized(data[0], "Component");
84+
85+
Assert.That(result, Is.True);
86+
}
87+
}
88+
}
89+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace NHibernate.Test.NHSpecificTest.GH3289
2+
{
3+
public interface IEntity
4+
{
5+
int Id { get; set; }
6+
string Name { get; set; }
7+
Component Component { get; set; }
8+
}
9+
10+
public interface ISubEntity : IEntity
11+
{
12+
public bool SomeProperty { get; set; }
13+
}
14+
15+
public class Entity : IEntity
16+
{
17+
public virtual int Id { get; set; }
18+
public virtual string Name { get; set; }
19+
public virtual Component Component { get; set; }
20+
}
21+
22+
public class SubEntity : Entity, ISubEntity
23+
{
24+
public virtual bool SomeProperty { get; set; }
25+
}
26+
27+
public class Component
28+
{
29+
public virtual string Field { get; set; }
30+
}
31+
}

0 commit comments

Comments
 (0)