Skip to content

Commit 15bde0a

Browse files
committedJun 16, 2023
Test case
1 parent 86d463a commit 15bde0a

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
var e1 = new SubEntity { Name = "Jim" };
41+
session.Save(e1);
42+
43+
transaction.Commit();
44+
}
45+
46+
protected override void OnTearDown()
47+
{
48+
using var session = OpenSession();
49+
using var transaction = session.BeginTransaction();
50+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
51+
52+
transaction.Commit();
53+
}
54+
55+
[Test]
56+
public void TestSubEntityInterfaceWithFetchIsPropertyInitialized()
57+
{
58+
using var session = OpenSession();
59+
var data = session.Query<ISubEntity>()
60+
.Fetch(e => e.Component)
61+
.ToList();
62+
var result = NHibernateUtil.IsPropertyInitialized(data[0], "Component");
63+
64+
Assert.That(result, Is.True);
65+
}
66+
67+
[Test]
68+
public void TestSubEntityWithFetchIsPropertyInitialized()
69+
{
70+
using var session = OpenSession();
71+
var data = session.Query<SubEntity>()
72+
.Fetch(e => e.Component)
73+
.ToList();
74+
var result = NHibernateUtil.IsPropertyInitialized(data[0], "Component");
75+
76+
Assert.That(result, Is.True);
77+
}
78+
}
79+
}
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)