Skip to content

Commit 32b2125

Browse files
committed
Lazy-Property test, not supported yet in NH. Waiting for a field-interceptor provider to be ready, probably Linfu.
SVN: trunk@4349
1 parent a53bdfb commit 32b2125

File tree

4 files changed

+100
-0
lines changed

4 files changed

+100
-0
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace NHibernate.Test.LazyProperty
2+
{
3+
public class Book
4+
{
5+
public virtual int Id { get; set; }
6+
public virtual string Name { get; set; }
7+
8+
private string _aLotOfText;
9+
10+
public virtual string ALotOfText
11+
{
12+
get { return _aLotOfText; }
13+
set { _aLotOfText = value; }
14+
}
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System.Collections;
2+
using NUnit.Framework;
3+
4+
namespace NHibernate.Test.LazyProperty
5+
{
6+
[TestFixture]
7+
public class LazyPropertyFixture : TestCase
8+
{
9+
protected override string MappingsAssembly
10+
{
11+
get { return "NHibernate.Test"; }
12+
}
13+
14+
protected override IList Mappings
15+
{
16+
get { return new[] {"LazyProperty.Mappings.hbm.xml"}; }
17+
}
18+
19+
public void LoadData()
20+
{
21+
Book b = new Book
22+
{
23+
Name = "some name",
24+
ALotOfText = "a lot of text ..."
25+
};
26+
27+
using(var s = OpenSession())
28+
using(var tx = s.BeginTransaction())
29+
{
30+
s.Persist(b);
31+
tx.Commit();
32+
}
33+
34+
}
35+
36+
public void CleanUp()
37+
{
38+
using (var s = OpenSession())
39+
using (var tx = s.BeginTransaction())
40+
{
41+
Assert.That(s.CreateSQLQuery("delete from Book").ExecuteUpdate(), Is.EqualTo(1));
42+
tx.Commit();
43+
}
44+
}
45+
46+
[Test,Ignore("Not supported yet, waiting for a field-interceptor provider, probably Linfu.")]
47+
public void PropertyLoadedNotInitialized()
48+
{
49+
LoadData();
50+
51+
using(ISession s = OpenSession())
52+
{
53+
var book = s.Load<Book>(1);
54+
55+
Assert.False(NHibernateUtil.IsPropertyInitialized(book, "Id"));
56+
Assert.False(NHibernateUtil.IsPropertyInitialized(book, "Name"));
57+
Assert.False(NHibernateUtil.IsPropertyInitialized(book, "ALotOfText"));
58+
var name = book.Name;
59+
Assert.True(NHibernateUtil.IsPropertyInitialized(book, "Id"));
60+
Assert.True(NHibernateUtil.IsPropertyInitialized(book, "Name"));
61+
Assert.False(NHibernateUtil.IsPropertyInitialized(book, "ALotOfText"));
62+
}
63+
64+
CleanUp();
65+
}
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
3+
assembly="NHibernate.Test"
4+
namespace="NHibernate.Test.LazyProperty">
5+
6+
<class name="Book">
7+
<id name="Id">
8+
<generator class="native" />
9+
</id>
10+
<property name="Name" />
11+
<property name="ALotOfText" lazy="true" />
12+
</class>
13+
14+
</hibernate-mapping>

src/NHibernate.Test/NHibernate.Test.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@
332332
<Compile Include="LazyOneToOne\Employment.cs" />
333333
<Compile Include="LazyOneToOne\LazyOneToOneTest.cs" />
334334
<Compile Include="LazyOneToOne\Person.cs" />
335+
<Compile Include="LazyProperty\Book.cs" />
336+
<Compile Include="LazyProperty\LazyPropertyFixture.cs" />
335337
<Compile Include="MappingTest\NonReflectiveBinderFixture.cs" />
336338
<Compile Include="MappingTest\Wicked.cs" />
337339
<Compile Include="NHSpecificTest\ElementsEnums\AbstractIntEnumsBagFixture.cs" />
@@ -1819,6 +1821,7 @@
18191821
<EmbeddedResource Include="BulkManipulation\SimpleClass.hbm.xml" />
18201822
<EmbeddedResource Include="Ado\VerySimple.hbm.xml" />
18211823
<Content Include="DynamicEntity\package.html" />
1824+
<EmbeddedResource Include="LazyProperty\Mappings.hbm.xml" />
18221825
<EmbeddedResource Include="NHSpecificTest\NH1783\Mappings.hbm.xml" />
18231826
<EmbeddedResource Include="LazyOneToOne\Person.hbm.xml" />
18241827
<EmbeddedResource Include="NHSpecificTest\NH1747\Mappings.hbm.xml" />

0 commit comments

Comments
 (0)