Skip to content

Commit e2b916c

Browse files
committed
Merge pull request #354 from rjperes/NH-3589
NH-3589 - Add tests
2 parents 89fd30a + e92f8a1 commit e2b916c

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2483,6 +2483,7 @@
24832483
<Compile Include="VersionTest\Db\MsSQL\SimpleVersioned.cs" />
24842484
<Compile Include="VersionTest\Db\Permission.cs" />
24852485
<Compile Include="VersionTest\Db\User.cs" />
2486+
<Compile Include="VersionTest\Db\LazyVersionTest.cs" />
24862487
<Compile Include="VersionTest\Person.cs" />
24872488
<Compile Include="VersionTest\Task.cs" />
24882489
<Compile Include="VersionTest\Thing.cs" />
@@ -2544,7 +2545,9 @@
25442545
<None Include="App.config">
25452546
<SubType>Designer</SubType>
25462547
</None>
2547-
<EmbeddedResource Include="Cascade\Circle\CascadeMergeToChildBeforeParent.hbm.xml" />
2548+
<EmbeddedResource Include="Cascade\Circle\CascadeMergeToChildBeforeParent.hbm.xml">
2549+
<SubType>Designer</SubType>
2550+
</EmbeddedResource>
25482551
<EmbeddedResource Include="Cascade\Circle\MultiPathCircleCascade.hbm.xml" />
25492552
<EmbeddedResource Include="Cascade\MultiPathCascade.hbm.xml" />
25502553
<EmbeddedResource Include="Immutable\ContractVariation.hbm.xml" />
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Drawing;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Xml;
7+
using NHibernate.Bytecode.CodeDom;
8+
using NHibernate.Cfg;
9+
using NHibernate.Mapping.ByCode;
10+
using NHibernate.Test.Linq;
11+
using NUnit.Framework;
12+
13+
namespace NHibernate.Test.VersionTest.Db
14+
{
15+
public class ProductWithVersionAndLazyProperty
16+
{
17+
byte[] _version = null;
18+
19+
public virtual int Id { get; set; }
20+
21+
public virtual string Summary { get; set; }
22+
23+
public virtual byte[] Version { get { return _version; } }
24+
}
25+
26+
[TestFixture]
27+
public class LazyVersionTest : LinqTestCase
28+
{
29+
30+
protected override void AddMappings(Configuration configuration)
31+
{
32+
var xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><hibernate-mapping xmlns=\"urn:nhibernate-mapping-2.2\" namespace=\"NHibernate.Test.VersionTest.Db\" assembly=\"NHibernate.Test\"><class name=\"ProductWithVersionAndLazyProperty\"><id name=\"Id\" generator=\"assigned\"/><version name=\"Version\" generated=\"always\" unsaved-value=\"null\" type=\"BinaryBlob\" access=\"nosetter.camelcase-underscore\"><column name=\"version\" not-null=\"false\" sql-type=\"timestamp\" /></version><property name=\"Summary\" lazy=\"true\"/></class></hibernate-mapping>";
33+
var doc = new XmlDocument();
34+
doc.LoadXml(xml);
35+
36+
configuration.AddDocument(doc);
37+
38+
base.AddMappings(configuration);
39+
40+
configuration.SetProperty(NHibernate.Cfg.Environment.Hbm2ddlAuto, SchemaAutoAction.Recreate.ToString());
41+
configuration.SetProperty(NHibernate.Cfg.Environment.FormatSql, Boolean.TrueString);
42+
configuration.SetProperty(NHibernate.Cfg.Environment.ShowSql, Boolean.TrueString);
43+
}
44+
45+
[Test]
46+
public void CanUseVersionOnEntityWithLazyProperty()
47+
{
48+
//NH-3589
49+
using (session.BeginTransaction())
50+
{
51+
this.session.Save(new ProductWithVersionAndLazyProperty { Id = 1, Summary = "Testing, 1, 2, 3" });
52+
53+
session.Flush();
54+
55+
this.session.Clear();
56+
57+
var p = this.session.Get<ProductWithVersionAndLazyProperty>(1);
58+
59+
p.Summary += ", 4!";
60+
61+
session.Flush();
62+
}
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)