Skip to content

Commit 5b2b330

Browse files
committed
NH-3141 - add tests to ensure consistent behaviour with id changes
1 parent 183e05f commit 5b2b330

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/NHibernate.Test/NHSpecificTest/NH3141/ProxyIdPerformanceTest.cs renamed to src/NHibernate.Test/NHSpecificTest/NH3141/ProxyIdFixture.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace NHibernate.Test.NHSpecificTest.NH3141
66
{
77
[TestFixture]
8-
public class ProxyIdPerformanceTest : BugTestCase
8+
public class ProxyIdFixture : BugTestCase
99
{
1010
private int id;
1111

@@ -48,6 +48,31 @@ public void ShouldUseIdDirectlyFromProxy()
4848
//after fix: 0.8s
4949
Console.WriteLine(watch.Elapsed);
5050
}
51+
52+
[Test]
53+
public void ShouldThrowExceptionIfIdChangedOnUnloadEntity()
54+
{
55+
using (var s = OpenSession())
56+
using (var tx = s.BeginTransaction())
57+
{
58+
var entity = s.Load<Entity>(id);
59+
entity.Id ++;
60+
Assert.Throws<HibernateException>(tx.Commit);
61+
}
62+
}
63+
64+
[Test]
65+
public void ShouldThrowExceptionIfIdChangedOnLoadEntity()
66+
{
67+
using (var s = OpenSession())
68+
using (var tx = s.BeginTransaction())
69+
{
70+
var entity = s.Load<Entity>(id);
71+
NHibernateUtil.Initialize(entity);
72+
entity.Id++;
73+
Assert.Throws<HibernateException>(tx.Commit);
74+
}
75+
}
5176

5277
private Entity CreateInitializedProxy()
5378
{

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@
10981098
<Compile Include="MappingByCode\IntegrationTests\NH3105\Fixture.cs" />
10991099
<Compile Include="NHSpecificTest\NH3436\Fixture.cs" />
11001100
<Compile Include="NHSpecificTest\NH3141\Entity.cs" />
1101-
<Compile Include="NHSpecificTest\NH3141\ProxyIdPerformanceTest.cs" />
1101+
<Compile Include="NHSpecificTest\NH3141\ProxyIdFixture.cs" />
11021102
<Compile Include="NHSpecificTest\NH941\Domain.cs" />
11031103
<Compile Include="NHSpecificTest\NH941\Fixture.cs" />
11041104
<Compile Include="NHSpecificTest\NH941\FixtureUsingList.cs" />

0 commit comments

Comments
 (0)