Skip to content

Commit 6bb0a10

Browse files
Add data required for failing on 5.3.16
1 parent 6b9ce7c commit 6bb0a10

File tree

2 files changed

+102
-2
lines changed

2 files changed

+102
-2
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using System;
12+
using System.Linq;
13+
using NUnit.Framework;
14+
using NHibernate.Linq;
15+
16+
namespace NHibernate.Test.NHSpecificTest.GH3609
17+
{
18+
using System.Threading.Tasks;
19+
[TestFixture]
20+
public class FixtureAsync : BugTestCase
21+
{
22+
protected override void OnSetUp()
23+
{
24+
using var session = OpenSession();
25+
using var transaction = session.BeginTransaction();
26+
27+
var order = new Order
28+
{
29+
UniqueId = "0ab92479-8a17-4dbc-9bef-ce4344940cec",
30+
CreatedDate = new DateTime(2024, 09, 24)
31+
};
32+
session.Save(order);
33+
session.Save(new LineItem { Order = order, ItemName = "Bananas", Amount = 5 });
34+
35+
order = new Order
36+
{
37+
UniqueId = "4ca17d84-97aa-489f-8701-302a3879a388",
38+
CreatedDate = new DateTime(2021, 09, 19)
39+
};
40+
session.Save(order);
41+
session.Save(new LineItem { Order = order, ItemName = "Apples", Amount = 10 });
42+
43+
transaction.Commit();
44+
}
45+
46+
protected override void OnTearDown()
47+
{
48+
using var session = OpenSession();
49+
using var transaction = session.BeginTransaction();
50+
51+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
52+
53+
transaction.Commit();
54+
}
55+
56+
[Test]
57+
public async Task QueryWithAnyAsync()
58+
{
59+
using var session = OpenSession();
60+
using var transaction = session.BeginTransaction();
61+
62+
// This form of query is how we first discovered the issue. This is a simplified reproduction of the
63+
// sort of Linq that we were using in our app. It seems to occur when we force an EXISTS( ... ) subquery.
64+
var validOrders = session.Query<Order>().Where(x => x.CreatedDate > new DateTime(2024, 9, 10));
65+
var orderCount = await (session.Query<LineItem>().CountAsync(x => validOrders.Any(y => y == x.Order)));
66+
67+
Assert.That(orderCount, Is.EqualTo(1));
68+
}
69+
70+
[Test]
71+
public async Task QueryWithContainsAsync()
72+
{
73+
using var session = OpenSession();
74+
using var transaction = session.BeginTransaction();
75+
76+
var validOrders = session.Query<Order>().Where(x => x.CreatedDate > new DateTime(2024, 9, 10));
77+
var orderCount = await (session.Query<LineItem>().CountAsync(x => validOrders.Contains(x.Order)));
78+
79+
Assert.That(orderCount, Is.EqualTo(1));
80+
}
81+
82+
[Test]
83+
public async Task SimpleQueryForDataWhichWasInsertedViaAdoShouldProvideExpectedResultsAsync()
84+
{
85+
using var session = OpenSession();
86+
using var transaction = session.BeginTransaction();
87+
88+
// This style of equivalent query does not exhibit the problem. This test passes no matter which NH version.
89+
var lineItem = await (session.Query<LineItem>().FirstOrDefaultAsync(x => x.Order.CreatedDate > new DateTime(2024, 9, 10)));
90+
Assert.That(lineItem, Is.Not.Null);
91+
}
92+
}
93+
}

src/NHibernate.Test/NHSpecificTest/GH3609/Fixture.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Linq;
33
using NUnit.Framework;
44

@@ -18,9 +18,16 @@ protected override void OnSetUp()
1818
CreatedDate = new DateTime(2024, 09, 24)
1919
};
2020
session.Save(order);
21-
2221
session.Save(new LineItem { Order = order, ItemName = "Bananas", Amount = 5 });
2322

23+
order = new Order
24+
{
25+
UniqueId = "4ca17d84-97aa-489f-8701-302a3879a388",
26+
CreatedDate = new DateTime(2021, 09, 19)
27+
};
28+
session.Save(order);
29+
session.Save(new LineItem { Order = order, ItemName = "Apples", Amount = 10 });
30+
2431
transaction.Commit();
2532
}
2633

0 commit comments

Comments
 (0)