Skip to content

Commit 210ab69

Browse files
authored
Merge pull request #608 from hazzik/NH-3755
NH-3755 - Fix overrides of members with the same names
2 parents c336aed + a56af53 commit 210ab69

File tree

12 files changed

+202
-0
lines changed

12 files changed

+202
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.NH3755
4+
{
5+
public class Circle : Shape, ICircle
6+
{
7+
public override string Property2 { get; set; }
8+
public virtual string Property3 { get; set; }
9+
}
10+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System.Linq;
2+
using NHibernate.Linq;
3+
using NUnit.Framework;
4+
5+
namespace NHibernate.Test.NHSpecificTest.NH3755
6+
{
7+
[TestFixture]
8+
public class Fixture : BugTestCase
9+
{
10+
protected override void OnSetUp()
11+
{
12+
using (var session = OpenSession())
13+
using (var transaction = session.BeginTransaction())
14+
{
15+
var c = new Circle {Property1 = "Circle1", Property2 = "Circle2", Property3 = "Circle3"};
16+
session.Save(c);
17+
18+
var s = new Square {Property1 = "Square1", Property2 = "Square2", Property3 = "Square3"};
19+
session.Save(c);
20+
session.Save(s);
21+
22+
var sc1 = new ShapeContainer {Name = "Circle", Shape = c};
23+
var sc2 = new ShapeContainer {Name = "Square", Shape = s};
24+
25+
session.Save(sc1);
26+
session.Save(sc2);
27+
28+
session.Flush();
29+
transaction.Commit();
30+
}
31+
}
32+
33+
protected override void OnTearDown()
34+
{
35+
using (var session = OpenSession())
36+
using (var transaction = session.BeginTransaction())
37+
{
38+
session.Delete("from System.Object");
39+
40+
session.Flush();
41+
transaction.Commit();
42+
}
43+
}
44+
45+
[Test]
46+
public void TestCompositeProxy()
47+
{
48+
using (var session = OpenSession())
49+
using (session.BeginTransaction())
50+
{
51+
var result1 = (from e in session.Query<ShapeContainer>()
52+
where e.Name == "Circle"
53+
select e).ToList();
54+
55+
var result2 = (from e in session.Query<ShapeContainer>()
56+
where e.Name == "Square"
57+
select e).ToList();
58+
59+
var circle = (ICircle) result1[0].Shape;
60+
var square = (ISquare) result2[0].Shape;
61+
62+
Assert.That(circle.Property1, Is.Not.Null);
63+
Assert.That(circle.Property2, Is.Not.Null);
64+
Assert.That(circle.Property3, Is.Not.Null);
65+
66+
Assert.That(square.Property1, Is.Not.Null);
67+
Assert.That(square.Property2, Is.Not.Null);
68+
Assert.That(square.Property3, Is.Not.Null);
69+
}
70+
}
71+
}
72+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace NHibernate.Test.NHSpecificTest.NH3755
7+
{
8+
public interface ICircle : IShape
9+
{
10+
string Property2 { get; set; }
11+
string Property3 { get; set; }
12+
}
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.NH3755
4+
{
5+
public interface IShape
6+
{
7+
Guid Id { get; set; }
8+
string Property1 { get; set; }
9+
}
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.NH3755
4+
{
5+
public interface IShapeContainer
6+
{
7+
Guid Id { get; set; }
8+
string Name { get; set; }
9+
IShape Shape { get; set; }
10+
}
11+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace NHibernate.Test.NHSpecificTest.NH3755
2+
{
3+
public interface ISquare : IShape
4+
{
5+
string Property2 { get; set; }
6+
string Property3 { get; set; }
7+
}
8+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="true" assembly="NHibernate.Test" namespace="NHibernate.Test.NHSpecificTest.NH3755">
3+
4+
<class name="Shape" proxy="IShape">
5+
<id name="Id">
6+
<generator class="guid.comb" />
7+
</id>
8+
<property name="Property1" />
9+
</class>
10+
11+
<joined-subclass proxy="ISquare" extends="Shape" name="Square">
12+
<key column="ShapeId" />
13+
<property name="Property2"/>
14+
<property name="Property3"/>
15+
</joined-subclass>
16+
17+
<joined-subclass proxy="ICircle" extends="Shape" name="Circle">
18+
<key column="ShapeId" />
19+
<property name="Property2"/>
20+
<property name="Property3"/>
21+
</joined-subclass>
22+
23+
<class name="ShapeContainer" proxy="IShapeContainer">
24+
<id name="Id">
25+
<generator class="guid.comb" />
26+
</id>
27+
<property name="Name" />
28+
<many-to-one name="Shape" class="Shape" />
29+
</class>
30+
31+
32+
33+
34+
</hibernate-mapping>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.NH3755
4+
{
5+
public abstract class Shape : IShape
6+
{
7+
public virtual Guid Id { get; set; }
8+
public string Property1 { get; set; }
9+
public abstract string Property2 { get; set; }
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.NH3755
4+
{
5+
public class ShapeContainer : IShapeContainer
6+
{
7+
public Guid Id { get; set; }
8+
public string Name { get; set; }
9+
public IShape Shape { get; set; }
10+
}
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.NH3755
4+
{
5+
public class Square : Shape, ISquare
6+
{
7+
public override string Property2 { get; set; }
8+
public virtual string Property3 { get; set; }
9+
}
10+
}

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,15 @@
975975
<Compile Include="NHSpecificTest\NH3909\FixtureByCode.cs" />
976976
<Compile Include="NHSpecificTest\NH3957\ResultTransformerEqualityFixture.cs" />
977977
<Compile Include="NHSpecificTest\NH3956\Fixture.cs" />
978+
<Compile Include="NHSpecificTest\NH3755\Circle.cs" />
979+
<Compile Include="NHSpecificTest\NH3755\Fixture.cs" />
980+
<Compile Include="NHSpecificTest\NH3755\ICircle.cs" />
981+
<Compile Include="NHSpecificTest\NH3755\IShape.cs" />
982+
<Compile Include="NHSpecificTest\NH3755\IShapeContainer.cs" />
983+
<Compile Include="NHSpecificTest\NH3755\ISquare.cs" />
984+
<Compile Include="NHSpecificTest\NH3755\Shape.cs" />
985+
<Compile Include="NHSpecificTest\NH3755\ShapeContainer.cs" />
986+
<Compile Include="NHSpecificTest\NH3755\Square.cs" />
978987
<Compile Include="NHSpecificTest\NH646\Domain.cs" />
979988
<Compile Include="NHSpecificTest\NH646\Fixture.cs" />
980989
<Compile Include="NHSpecificTest\NH3234\Fixture.cs" />
@@ -3291,6 +3300,7 @@
32913300
<SubType>Designer</SubType>
32923301
</EmbeddedResource>
32933302
<EmbeddedResource Include="NHSpecificTest\NH3757\Mappings.hbm.xml" />
3303+
<EmbeddedResource Include="NHSpecificTest\NH3755\Mappings.hbm.xml" />
32943304
<EmbeddedResource Include="LazyComponentTest\Person.hbm.xml" />
32953305
<EmbeddedResource Include="NHSpecificTest\NH3372\Mappings.hbm.xml" />
32963306
<EmbeddedResource Include="NHSpecificTest\NH3567\Mappings.hbm.xml" />

src/NHibernate/Proxy/DynamicProxy/DefaultProxyMethodBuilder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ public void CreateProxiedMethod(FieldInfo field, MethodInfo method, TypeBuilder
141141
var proxyMethod = GenerateMethodSignature(method.Name, method, typeBuilder);
142142

143143
MethodBodyEmitter.EmitMethodBody(proxyMethod, callbackMethod, method, field);
144+
145+
typeBuilder.DefineMethodOverride(proxyMethod, method);
144146
}
145147
}
146148
}

0 commit comments

Comments
 (0)