Skip to content

NH-3589 - Add tests #354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/NHibernate.Test/NHibernate.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2483,6 +2483,7 @@
<Compile Include="VersionTest\Db\MsSQL\SimpleVersioned.cs" />
<Compile Include="VersionTest\Db\Permission.cs" />
<Compile Include="VersionTest\Db\User.cs" />
<Compile Include="VersionTest\Db\LazyVersionTest.cs" />
<Compile Include="VersionTest\Person.cs" />
<Compile Include="VersionTest\Task.cs" />
<Compile Include="VersionTest\Thing.cs" />
Expand Down Expand Up @@ -2544,7 +2545,9 @@
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<EmbeddedResource Include="Cascade\Circle\CascadeMergeToChildBeforeParent.hbm.xml" />
<EmbeddedResource Include="Cascade\Circle\CascadeMergeToChildBeforeParent.hbm.xml">
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Cascade\Circle\MultiPathCircleCascade.hbm.xml" />
<EmbeddedResource Include="Cascade\MultiPathCascade.hbm.xml" />
<EmbeddedResource Include="Immutable\ContractVariation.hbm.xml" />
Expand Down
65 changes: 65 additions & 0 deletions src/NHibernate.Test/VersionTest/Db/LazyVersionTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Xml;
using NHibernate.Bytecode.CodeDom;
using NHibernate.Cfg;
using NHibernate.Mapping.ByCode;
using NHibernate.Test.Linq;
using NUnit.Framework;

namespace NHibernate.Test.VersionTest.Db
{
public class ProductWithVersionAndLazyProperty
{
byte[] _version = null;

public virtual int Id { get; set; }

public virtual string Summary { get; set; }

public virtual byte[] Version { get { return _version; } }
}

[TestFixture]
public class LazyVersionTest : LinqTestCase
{

protected override void AddMappings(Configuration configuration)
{
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>";
var doc = new XmlDocument();
doc.LoadXml(xml);

configuration.AddDocument(doc);

base.AddMappings(configuration);

configuration.SetProperty(NHibernate.Cfg.Environment.Hbm2ddlAuto, SchemaAutoAction.Recreate.ToString());
configuration.SetProperty(NHibernate.Cfg.Environment.FormatSql, Boolean.TrueString);
configuration.SetProperty(NHibernate.Cfg.Environment.ShowSql, Boolean.TrueString);
}

[Test]
public void CanUseVersionOnEntityWithLazyProperty()
{
//NH-3589
using (session.BeginTransaction())
{
this.session.Save(new ProductWithVersionAndLazyProperty { Id = 1, Summary = "Testing, 1, 2, 3" });

session.Flush();

this.session.Clear();

var p = this.session.Get<ProductWithVersionAndLazyProperty>(1);

p.Summary += ", 4!";

session.Flush();
}
}
}
}