| 
 | 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 | +			session.Save(new CleanLineItem { Order = order, ItemName = "Bananas", Amount = 5 });  | 
 | 35 | + | 
 | 36 | +			order = new Order  | 
 | 37 | +			{  | 
 | 38 | +				UniqueId = "4ca17d84-97aa-489f-8701-302a3879a388",  | 
 | 39 | +				CreatedDate = new DateTime(2021, 09, 19)  | 
 | 40 | +			};  | 
 | 41 | +			session.Save(order);  | 
 | 42 | +			session.Save(new LineItem { Order = order, ItemName = "Apples", Amount = 10 });  | 
 | 43 | +			session.Save(new CleanLineItem { Order = order, ItemName = "Apples", Amount = 10 });  | 
 | 44 | + | 
 | 45 | +			transaction.Commit();  | 
 | 46 | +		}  | 
 | 47 | + | 
 | 48 | +		protected override void OnTearDown()  | 
 | 49 | +		{  | 
 | 50 | +			using var session = OpenSession();  | 
 | 51 | +			using var transaction = session.BeginTransaction();  | 
 | 52 | + | 
 | 53 | +			session.CreateQuery("delete from CleanLineItem").ExecuteUpdate();  | 
 | 54 | +			session.CreateQuery("delete from System.Object").ExecuteUpdate();  | 
 | 55 | + | 
 | 56 | +			transaction.Commit();  | 
 | 57 | +		}  | 
 | 58 | + | 
 | 59 | +		[Test]  | 
 | 60 | +		public async Task QueryWithAnyAsync()  | 
 | 61 | +		{  | 
 | 62 | +			using var session = OpenSession();  | 
 | 63 | +			using var transaction = session.BeginTransaction();  | 
 | 64 | + | 
 | 65 | +			// This form of query is how we first discovered the issue.  This is a simplified reproduction of the  | 
 | 66 | +			// sort of Linq that we were using in our app.  It seems to occur when we force an EXISTS( ... ) subquery.  | 
 | 67 | +			var validOrders = session.Query<Order>().Where(x => x.CreatedDate > new DateTime(2024, 9, 10));  | 
 | 68 | +			var orderCount = await (session.Query<LineItem>().CountAsync(x => validOrders.Any(y => y == x.Order)));  | 
 | 69 | + | 
 | 70 | +			Assert.That(orderCount, Is.EqualTo(1));  | 
 | 71 | +			await (transaction.CommitAsync());  | 
 | 72 | +		}  | 
 | 73 | + | 
 | 74 | +		[Test]  | 
 | 75 | +		public async Task QueryWithAnyOnCleanLinesAsync()  | 
 | 76 | +		{  | 
 | 77 | +			using var session = OpenSession();  | 
 | 78 | +			using var transaction = session.BeginTransaction();  | 
 | 79 | + | 
 | 80 | +			// This form of query is how we first discovered the issue.  This is a simplified reproduction of the  | 
 | 81 | +			// sort of Linq that we were using in our app.  It seems to occur when we force an EXISTS( ... ) subquery.  | 
 | 82 | +			var validOrders = session.Query<Order>().Where(x => x.CreatedDate > new DateTime(2024, 9, 10));  | 
 | 83 | +			var orderCount = await (session.Query<CleanLineItem>().CountAsync(x => validOrders.Any(y => y == x.Order)));  | 
 | 84 | + | 
 | 85 | +			Assert.That(orderCount, Is.EqualTo(1));  | 
 | 86 | +			await (transaction.CommitAsync());  | 
 | 87 | +		}  | 
 | 88 | + | 
 | 89 | +		[Test]  | 
 | 90 | +		public async Task QueryWithContainsAsync()  | 
 | 91 | +		{  | 
 | 92 | +			using var session = OpenSession();  | 
 | 93 | +			using var transaction = session.BeginTransaction();  | 
 | 94 | + | 
 | 95 | +			var validOrders = session.Query<Order>().Where(x => x.CreatedDate > new DateTime(2024, 9, 10));  | 
 | 96 | +			var orderCount = await (session.Query<LineItem>().CountAsync(x => validOrders.Contains(x.Order)));  | 
 | 97 | + | 
 | 98 | +			Assert.That(orderCount, Is.EqualTo(1));  | 
 | 99 | +			await (transaction.CommitAsync());  | 
 | 100 | +		}  | 
 | 101 | + | 
 | 102 | +		[Test]  | 
 | 103 | +		public async Task SimpleQueryForDataWhichWasInsertedViaAdoShouldProvideExpectedResultsAsync()  | 
 | 104 | +		{  | 
 | 105 | +			using var session = OpenSession();  | 
 | 106 | +			using var transaction = session.BeginTransaction();  | 
 | 107 | + | 
 | 108 | +			// This style of equivalent query does not exhibit the problem.  This test passes no matter which NH version.  | 
 | 109 | +			var lineItem = await (session.Query<LineItem>().FirstOrDefaultAsync(x => x.Order.CreatedDate > new DateTime(2024, 9, 10)));  | 
 | 110 | +			Assert.That(lineItem, Is.Not.Null);  | 
 | 111 | +			await (transaction.CommitAsync());  | 
 | 112 | +		}  | 
 | 113 | +	}  | 
 | 114 | +}  | 
0 commit comments