Skip to content

Commit a73e4bc

Browse files
committed
NH-3453 - Added test case
1 parent dc008a6 commit a73e4bc

File tree

4 files changed

+113
-0
lines changed

4 files changed

+113
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace NHibernate.Test.NHSpecificTest.NH3453
7+
{
8+
class Direction
9+
{
10+
11+
#region Compisite ID
12+
13+
public virtual Int32 Id1 { get; set; }
14+
15+
public virtual Int32 Id2 { get; set; }
16+
17+
#endregion
18+
19+
public virtual Guid GUID { get; set; }
20+
21+
public override int GetHashCode()
22+
{
23+
return string.Format("{0} - {1}", Id1, Id2).GetHashCode();
24+
}
25+
26+
public override bool Equals(object obj)
27+
{
28+
return Id1 == ((Direction)obj).Id1 &&
29+
Id2 == ((Direction)obj).Id2;
30+
}
31+
}
32+
33+
class DirectionReferrer
34+
{
35+
public virtual Guid GUID { get; set; }
36+
37+
public virtual Direction Direction { get; set; }
38+
}
39+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using NUnit.Framework;
3+
4+
namespace NHibernate.Test.NHSpecificTest.NH3453
5+
{
6+
[TestFixture]
7+
public class Fixture : BugTestCase
8+
{
9+
public override string BugNumber
10+
{
11+
get { return "NH3453"; }
12+
}
13+
14+
[Test]
15+
public void PropertyRefWithCompositeIdUpdateTest()
16+
{
17+
using (var spy = new SqlLogSpy())
18+
using (var session = OpenSession())
19+
using (session.BeginTransaction())
20+
{
21+
22+
var direction1 = new Direction { Id1 = 1, Id2 = 1, GUID = Guid.NewGuid() };
23+
session.Save(direction1);
24+
25+
var direction2 = new Direction { Id1 = 2, Id2 = 2, GUID = Guid.NewGuid() };
26+
session.Save(direction2);
27+
28+
session.Flush();
29+
30+
var directionReferrer = new DirectionReferrer
31+
{
32+
GUID = Guid.NewGuid(),
33+
Direction = direction1,
34+
};
35+
36+
session.Save(directionReferrer);
37+
38+
directionReferrer.Direction = direction2;
39+
40+
session.Update(directionReferrer);
41+
42+
session.Flush();
43+
44+
Console.WriteLine(spy.ToString());
45+
Assert.That(true);
46+
}
47+
}
48+
49+
}
50+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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.NHSpecificTest.NH3453"
5+
default-lazy="false"
6+
default-access="property">
7+
8+
<class name="Direction" table="Direction">
9+
<composite-id>
10+
<key-property column="Id1" name="Id1" />
11+
<key-property column="Id2" name="Id2" />
12+
</composite-id>
13+
<property column="GUID" name="GUID" not-null="true" unique="true"/>
14+
</class>
15+
16+
<class name="DirectionReferrer" table="DirectionReferrer">
17+
<id column="GUID" name="GUID"></id>
18+
<many-to-one name="Direction" column="guid_Direction" not-null="false" property-ref="GUID" />
19+
</class>
20+
21+
</hibernate-mapping>

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,8 @@
691691
<Compile Include="NHSpecificTest\BagWithLazyExtraAndFilter\Fixture.cs" />
692692
<Compile Include="Linq\ByMethod\DistinctTests.cs" />
693693
<Compile Include="Component\Basic\ComponentWithUniqueConstraintTests.cs" />
694+
<Compile Include="NHSpecificTest\NH3453\Classes.cs" />
695+
<Compile Include="NHSpecificTest\NH3453\Fixture.cs" />
694696
<Compile Include="NHSpecificTest\NH3480\Entity.cs" />
695697
<Compile Include="NHSpecificTest\NH3480\Fixture.cs" />
696698
<Compile Include="NHSpecificTest\NH3487\Entity.cs" />
@@ -3070,6 +3072,7 @@
30703072
<EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" />
30713073
</ItemGroup>
30723074
<ItemGroup>
3075+
<EmbeddedResource Include="NHSpecificTest\NH3453\Mappings.hbm.xml" />
30733076
<EmbeddedResource Include="NHSpecificTest\NH3480\Mappings.hbm.xml">
30743077
<SubType>Designer</SubType>
30753078
</EmbeddedResource>

0 commit comments

Comments
 (0)