Skip to content

Commit

Permalink
NH-3141 - add tests to ensure consistent behaviour with id changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hazzik committed Oct 21, 2013
1 parent 183e05f commit 5b2b330
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace NHibernate.Test.NHSpecificTest.NH3141
{
[TestFixture]
public class ProxyIdPerformanceTest : BugTestCase
public class ProxyIdFixture : BugTestCase
{
private int id;

Expand Down Expand Up @@ -48,6 +48,31 @@ public void ShouldUseIdDirectlyFromProxy()
//after fix: 0.8s
Console.WriteLine(watch.Elapsed);
}

[Test]
public void ShouldThrowExceptionIfIdChangedOnUnloadEntity()
{
using (var s = OpenSession())
using (var tx = s.BeginTransaction())
{
var entity = s.Load<Entity>(id);
entity.Id ++;
Assert.Throws<HibernateException>(tx.Commit);
}
}

[Test]
public void ShouldThrowExceptionIfIdChangedOnLoadEntity()
{
using (var s = OpenSession())
using (var tx = s.BeginTransaction())
{
var entity = s.Load<Entity>(id);
NHibernateUtil.Initialize(entity);
entity.Id++;
Assert.Throws<HibernateException>(tx.Commit);
}
}

private Entity CreateInitializedProxy()
{
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate.Test/NHibernate.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@
<Compile Include="MappingByCode\IntegrationTests\NH3105\Fixture.cs" />
<Compile Include="NHSpecificTest\NH3436\Fixture.cs" />
<Compile Include="NHSpecificTest\NH3141\Entity.cs" />
<Compile Include="NHSpecificTest\NH3141\ProxyIdPerformanceTest.cs" />
<Compile Include="NHSpecificTest\NH3141\ProxyIdFixture.cs" />
<Compile Include="NHSpecificTest\NH941\Domain.cs" />
<Compile Include="NHSpecificTest\NH941\Fixture.cs" />
<Compile Include="NHSpecificTest\NH941\FixtureUsingList.cs" />
Expand Down

0 comments on commit 5b2b330

Please sign in to comment.