Skip to content

Fix HQL and LINQ query by a type on <any/> with meta-types other than int #1803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 0 additions & 117 deletions src/NHibernate.Test/Async/NHSpecificTest/NH2328/Fixture.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.GH1774.Class
{
[TestFixture]
public class ClassMetaTypeFixture : FixtureBase
{
}
}
30 changes: 30 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH1774/Class/Mappings.hbm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
xmlns="urn:nhibernate-mapping-2.2"
assembly="NHibernate.Test"
namespace="NHibernate.Test.NHSpecificTest.GH1774">

<class name="ToyBox">
<id name="Id">
<generator class="native"/>
</id>
<property name="Name" />
<any name="Shape" id-type="int" meta-type="class">
<column name="s_object_id" />
<column name="object_id" />
</any>
</class>

<class name="Square">
<id name="Id">
<generator class="native"/>
</id>
</class>

<class name="Circle">
<id name="Id">
<generator class="native"/>
</id>
</class>

</hibernate-mapping>
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System.Linq;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.NH2328
namespace NHibernate.Test.NHSpecificTest.GH1774
{
[TestFixture]
public class Fixture : BugTestCase
public abstract class FixtureBase : BugTestCase
{
protected override bool AppliesTo(Dialect.Dialect dialect)
{
Expand All @@ -13,29 +12,25 @@ protected override bool AppliesTo(Dialect.Dialect dialect)

protected override void OnSetUp()
{
base.OnSetUp();

using (ISession s = OpenSession())
using (ITransaction t = s.BeginTransaction())
using (var s = OpenSession())
using (var t = s.BeginTransaction())
{
var circle = new Circle();
var square = new Square();

s.Save(circle);
s.Save(square);

s.Save(new ToyBox() { Name = "Box1", Shape = circle });
s.Save(new ToyBox() { Name = "Box2", Shape = square });
s.Save(new ToyBox { Name = "Box1", Shape = circle });
s.Save(new ToyBox { Name = "Box2", Shape = square });
t.Commit();
}
}

protected override void OnTearDown()
{
base.OnTearDown();

using (ISession s = OpenSession())
using (ITransaction t = s.BeginTransaction())
using (var s = OpenSession())
using (var t = s.BeginTransaction())
{
s.CreateQuery("delete from ToyBox").ExecuteUpdate();
s.CreateQuery("delete from Circle").ExecuteUpdate();
Expand All @@ -47,12 +42,13 @@ protected override void OnTearDown()
[Test]
public void AnyIs_QueryOver()
{
using (ISession s = OpenSession())
using (var s = OpenSession())
using (s.BeginTransaction())
{
var boxes =
s.QueryOver<ToyBox>()
.Where(t => t.Shape is Square)
.List();
.Where(t => t.Shape is Square)
.List();

Assert.That(boxes.Count, Is.EqualTo(1));
Assert.That(boxes[0].Name, Is.EqualTo("Box2"));
Expand All @@ -62,7 +58,8 @@ public void AnyIs_QueryOver()
[Test]
public void AnyIs_Linq()
{
using (ISession s = OpenSession())
using (var s = OpenSession())
using (s.BeginTransaction())
{
var boxes =
(from t in s.Query<ToyBox>()
Expand All @@ -77,11 +74,12 @@ where t.Shape is Square
[Test]
public void AnyIs_HqlWorksWithClassNameInTheRight()
{
using (ISession s = OpenSession())
using (var s = OpenSession())
using (s.BeginTransaction())
{
var boxes =
s.CreateQuery("from ToyBox t where t.Shape.class = Square")
.List<ToyBox>();
.List<ToyBox>();

Assert.That(boxes.Count, Is.EqualTo(1));
Assert.That(boxes[0].Name, Is.EqualTo("Box2"));
Expand All @@ -91,11 +89,44 @@ public void AnyIs_HqlWorksWithClassNameInTheRight()
[Test]
public void AnyIs_HqlWorksWithClassNameInTheLeft()
{
using (ISession s = OpenSession())
using (var s = OpenSession())
using (s.BeginTransaction())
{
var boxes =
s.CreateQuery("from ToyBox t where Square = t.Shape.class")
.List<ToyBox>();
.List<ToyBox>();

Assert.That(boxes.Count, Is.EqualTo(1));
Assert.That(boxes[0].Name, Is.EqualTo("Box2"));
}
}

[Test]
public void AnyIs_HqlWorksWithParameterInTheRight()
{
using (var s = OpenSession())
using (s.BeginTransaction())
{
var boxes =
s.CreateQuery("from ToyBox t where t.Shape.class = :c")
.SetParameter("c", typeof(Square).FullName)
.List<ToyBox>();

Assert.That(boxes.Count, Is.EqualTo(1));
Assert.That(boxes[0].Name, Is.EqualTo("Box2"));
}
}

[Test]
public void AnyIs_HqlWorksWithParameterInTheLeft()
{
using (var s = OpenSession())
using (s.BeginTransaction())
{
var boxes =
s.CreateQuery("from ToyBox t where :c = t.Shape.class")
.SetParameter("c", typeof(Square).FullName)
.List<ToyBox>();

Assert.That(boxes.Count, Is.EqualTo(1));
Assert.That(boxes[0].Name, Is.EqualTo("Box2"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.GH1774.Implicit
{
[TestFixture, Ignore("Not fixed yet")]
public class ImplicitMetaTypeFixture : FixtureBase
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
xmlns="urn:nhibernate-mapping-2.2"
assembly="NHibernate.Test"
namespace="NHibernate.Test.NHSpecificTest.GH1774">

<class name="ToyBox">
<id name="Id">
<generator class="native"/>
</id>
<property name="Name" />
<any name="Shape" id-type="int">
<column name="s_object_id" />
<column name="object_id" />
</any>
</class>

<class name="Square">
<id name="Id">
<generator class="native"/>
</id>
</class>

<class name="Circle">
<id name="Id">
<generator class="native"/>
</id>
</class>

</hibernate-mapping>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.GH1774.Int32
{
[TestFixture]
public class Int32MetaTypeFixture : FixtureBase
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<hibernate-mapping
xmlns="urn:nhibernate-mapping-2.2"
assembly="NHibernate.Test"
namespace="NHibernate.Test.NHSpecificTest.NH2328">
namespace="NHibernate.Test.NHSpecificTest.GH1774">

<class name="ToyBox">
<id name="Id">
Expand All @@ -29,4 +29,4 @@
</id>
</class>

</hibernate-mapping>
</hibernate-mapping>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace NHibernate.Test.NHSpecificTest.NH2328
namespace NHibernate.Test.NHSpecificTest.GH1774
{
public class ToyBox
{
Expand All @@ -20,4 +20,4 @@ public class Square : IShape
{
public virtual int Id { get; set; }
}
}
}
Loading