Skip to content

Commit f655785

Browse files
hazzikfredericDelaporte
authored andcommitted
Add tests for nhibernate#3609
1 parent 981348c commit f655785

File tree

4 files changed

+127
-1
lines changed

4 files changed

+127
-1
lines changed
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.GH3609
4+
{
5+
public class Order
6+
{
7+
public virtual long Id { get; set; }
8+
9+
public virtual string UniqueId { get; set; } = Guid.NewGuid().ToString();
10+
11+
public virtual DateTime CreatedDate { get; set; }
12+
}
13+
14+
public class LineItem
15+
{
16+
public virtual long Id { get; set; }
17+
18+
public virtual Order Order { get; set; }
19+
20+
public virtual string ItemName { get; set; }
21+
22+
public virtual decimal Amount { get; set; }
23+
}
24+
}

Diff for: src/NHibernate.Test/NHSpecificTest/GH3609/Fixture.cs

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using System;
2+
using System.Linq;
3+
using NUnit.Framework;
4+
5+
namespace NHibernate.Test.NHSpecificTest.GH3609
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+
16+
var order = new Order
17+
{
18+
UniqueId = "0ab92479-8a17-4dbc-9bef-ce4344940cec",
19+
CreatedDate = new DateTime(2024, 09, 24)
20+
};
21+
session.Save(order);
22+
23+
session.Save(new LineItem { Order = order, ItemName = "Bananas", Amount = 5 });
24+
25+
transaction.Commit();
26+
}
27+
}
28+
29+
protected override void OnTearDown()
30+
{
31+
using (var session = OpenSession())
32+
using (var transaction = session.BeginTransaction())
33+
{
34+
35+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
36+
37+
transaction.Commit();
38+
}
39+
}
40+
41+
[Test]
42+
public void QueryWithAny()
43+
{
44+
using (var session = OpenSession())
45+
using (var transaction = session.BeginTransaction())
46+
{
47+
// This form of query is how we first discovered the issue. This is a simplified reproduction of the
48+
// sort of Linq that we were using in our app. It seems to occur when we force an EXISTS( ... ) subquery.
49+
var validOrders = session.Query<Order>().Where(x => x.CreatedDate > new DateTime(2024, 9, 10));
50+
var orderCount = session.Query<LineItem>().Count(x => validOrders.Any(y => y == x.Order));
51+
52+
Assert.That(orderCount, Is.EqualTo(1));
53+
}
54+
}
55+
56+
[Test]
57+
public void QueryWithContains()
58+
{
59+
using (var session = OpenSession())
60+
using (var transaction = session.BeginTransaction())
61+
{
62+
var validOrders = session.Query<Order>().Where(x => x.CreatedDate > new DateTime(2024, 9, 10));
63+
var orderCount = session.Query<LineItem>().Count(x => validOrders.Contains(x.Order));
64+
65+
Assert.That(orderCount, Is.EqualTo(1));
66+
}
67+
}
68+
69+
[Test]
70+
public void SimpleQueryForDataWhichWasInsertedViaAdoShouldProvideExpectedResults()
71+
{
72+
using (var session = OpenSession())
73+
using (var transaction = session.BeginTransaction())
74+
{
75+
// This style of equivalent query does not exhibit the problem. This test passes no matter which NH version.
76+
var lineItem = session.Query<LineItem>().FirstOrDefault(x => x.Order.CreatedDate > new DateTime(2024, 9, 10));
77+
Assert.That(lineItem, Is.Not.Null);
78+
}
79+
}
80+
}
81+
}
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" assembly="NHibernate.Test"
3+
namespace="NHibernate.Test.NHSpecificTest.GH3609">
4+
5+
<class name="Order" table="TheOrder">
6+
<id name="Id" generator="identity" />
7+
<property name="CreatedDate" />
8+
<property name="UniqueId" />
9+
</class>
10+
11+
<class name="LineItem">
12+
<id name="Id" generator="identity" />
13+
<property name="ItemName" />
14+
<property name="Amount" />
15+
<many-to-one name="Order"
16+
property-ref="UniqueId"
17+
not-found="ignore"
18+
column="OrderId" />
19+
</class>
20+
21+
</hibernate-mapping>

Diff for: src/NHibernate/Hql/Ast/ANTLR/Tree/DotNode.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public override void ResolveFirstChild()
153153
string propName = property.Text;
154154
_propertyName = propName;
155155

156-
// If the uresolved property path isn't set yet, just use the property name.
156+
// If the unresolved property path isn't set yet, just use the property name.
157157
if (_propertyPath == null)
158158
{
159159
_propertyPath = propName;

0 commit comments

Comments
 (0)