Skip to content

Commit 500b433

Browse files
committed
Tests for NH3641
1 parent 54fe758 commit 500b433

File tree

4 files changed

+111
-0
lines changed

4 files changed

+111
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using NHibernate.Proxy;
6+
using NHibernate.Proxy.DynamicProxy;
7+
8+
namespace NHibernate.Test.NHSpecificTest.NH3641
9+
{
10+
public interface IEntity
11+
{
12+
int Id { get; set; }
13+
bool Flag { get; set; }
14+
Entity ChildConcrete { get; set; }
15+
IEntity ChildInterface { get; set; }
16+
}
17+
18+
public class Entity : IEntity
19+
{
20+
public virtual int Id { get; set; }
21+
public virtual bool Flag { get; set; }
22+
public virtual Entity ChildConcrete { get; set; }
23+
public virtual IEntity ChildInterface { get; set; }
24+
}
25+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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.NH3641">
5+
6+
<class name="Entity" table="Entity" lazy="true">
7+
<id name="Id" access="property" column="Id" type="Int32" unsaved-value="0">
8+
<generator class="assigned" />
9+
</id>
10+
11+
<property name="Flag" type="Boolean">
12+
<column name="Flag" not-null="true" />
13+
</property>
14+
15+
<many-to-one name="ChildConcrete" access="property" class="Entity" column="ChildConcreteId" lazy="proxy" />
16+
<many-to-one name="ChildInterface" access="property" class="Entity" column="ChildInterfaceId" lazy="proxy" />
17+
</class>
18+
19+
</hibernate-mapping>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Reflection;
6+
using System.Text;
7+
using NHibernate.Linq;
8+
using NUnit.Framework;
9+
10+
namespace NHibernate.Test.NHSpecificTest.NH3641
11+
{
12+
public class TestFixture : BugTestCase
13+
{
14+
protected override void OnSetUp()
15+
{
16+
using (var session = OpenSession())
17+
using (var tx = session.BeginTransaction())
18+
{
19+
var child = new Entity { Id = 1, Flag = false };
20+
var parent = new Entity { Id = 2, ChildInterface = child, ChildConcrete = child };
21+
22+
session.Save(child);
23+
session.Save(parent);
24+
25+
tx.Commit();
26+
}
27+
}
28+
29+
protected override void OnTearDown()
30+
{
31+
using (var session = OpenSession())
32+
using (var tx = session.BeginTransaction())
33+
{
34+
DeleteAll<Entity>(session);
35+
tx.Commit();
36+
}
37+
}
38+
39+
private static void DeleteAll<T>(ISession session)
40+
{
41+
session.CreateQuery("delete from " + typeof(T).Name).ExecuteUpdate();
42+
}
43+
44+
[Test]
45+
public void TrueOrChildPropertyConcrete()
46+
{
47+
using (var session = OpenSession())
48+
{
49+
var result = session.Query<IEntity>().Where(x => true || x.ChildConcrete.Flag).ToList();
50+
Assert.That(result, Has.Count.EqualTo(2));
51+
}
52+
}
53+
54+
[Test]
55+
public void TrueOrChildPropertyInterface()
56+
{
57+
using (var session = OpenSession())
58+
{
59+
var result = session.Query<IEntity>().Where(x => true || ((Entity)x.ChildInterface).Flag).ToList();
60+
Assert.That(result, Has.Count.EqualTo(2));
61+
}
62+
}
63+
}
64+
}

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,8 @@
10331033
<Compile Include="NHSpecificTest\NH3145\Model.cs" />
10341034
<Compile Include="NHSpecificTest\NH2860\ClassA.cs" />
10351035
<Compile Include="NHSpecificTest\NH2860\SampleTest.cs" />
1036+
<Compile Include="NHSpecificTest\NH3641\Domain.cs" />
1037+
<Compile Include="NHSpecificTest\NH3641\TestFixture.cs" />
10361038
<Compile Include="NHSpecificTest\Properties\CompositePropertyRefTest.cs" />
10371039
<Compile Include="NHSpecificTest\Properties\DynamicEntityTest.cs" />
10381040
<Compile Include="NHSpecificTest\Properties\Model.cs" />
@@ -2883,6 +2885,7 @@
28832885
<EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" />
28842886
</ItemGroup>
28852887
<ItemGroup>
2888+
<EmbeddedResource Include="NHSpecificTest\NH3641\Mappings.hbm.xml" />
28862889
<EmbeddedResource Include="NHSpecificTest\NH3408\Mappings.hbm.xml" />
28872890
<EmbeddedResource Include="NHSpecificTest\NH2408\Mappings.hbm.xml" />
28882891
<EmbeddedResource Include="NHSpecificTest\NH2297\MappingsNames.hbm.xml" />

0 commit comments

Comments
 (0)