Skip to content

Commit b95f88a

Browse files
authored
Merge pull request #1393 from fredericDelaporte/1387
Fix Linq Future aggregates failures. Fixes #1387, closes #1388.
2 parents 32adfd1 + de944c2 commit b95f88a

File tree

13 files changed

+1266
-477
lines changed

13 files changed

+1266
-477
lines changed

src/NHibernate.Test/Async/Futures/LinqToFutureValueFixture.cs

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//------------------------------------------------------------------------------
99

1010

11+
using System;
1112
using System.Linq;
1213
using NHibernate.Linq;
1314
using NUnit.Framework;
@@ -45,13 +46,71 @@ public async Task CanExecuteToFutureValueCountWithPredicateAsync()
4546
}
4647
}
4748

49+
[Test(Description = "https://github.com/nhibernate/nhibernate-core/issues/1387")]
50+
public async Task ToFutureValueWithSumReturnsResultAsync()
51+
{
52+
using (var s = OpenSession())
53+
{
54+
var personsSum = s.Query<Person>()
55+
.Select(x => x.Id)
56+
.ToFutureValue(x => x.Sum());
57+
58+
Assert.IsNotNull(personsSum);
59+
Assert.NotZero(await (personsSum.GetValueAsync()));
60+
}
61+
}
62+
63+
[Test]
64+
public void ToFutureValueWithSumOnEmptySetThrowsAsync()
65+
{
66+
using (var s = OpenSession())
67+
{
68+
var personsSum = s.Query<Person>()
69+
.Where(x => false) // make this an empty set
70+
.Select(x => x.Id)
71+
.ToFutureValue(x => x.Sum());
72+
73+
Assert.That(() => personsSum.GetValueAsync(), Throws.InnerException.TypeOf<InvalidOperationException>().Or.InnerException.TypeOf<ArgumentNullException>());
74+
}
75+
}
76+
77+
[Test]
78+
public async Task ToFutureValueWithNullableSumReturnsResultAsync()
79+
{
80+
using (var s = OpenSession())
81+
{
82+
var ageSum = s.Query<Person>()
83+
.Select(x => x.Age)
84+
.ToFutureValue(x => x.Sum());
85+
86+
Assert.IsNotNull(ageSum);
87+
Assert.IsNotNull(await (ageSum.GetValueAsync()));
88+
Assert.NotZero((await (ageSum.GetValueAsync())).Value);
89+
}
90+
}
91+
92+
[Test]
93+
public async Task ToFutureValueWithNullableSumOnEmptySetReturnsNullAsync()
94+
{
95+
using (var s = OpenSession())
96+
{
97+
var ageSum = s.Query<Person>()
98+
.Where(x => false) // make this an empty set
99+
.Select(x => x.Age)
100+
.ToFutureValue(x => x.Sum());
101+
102+
Assert.IsNotNull(ageSum);
103+
Assert.IsNull(await (ageSum.GetValueAsync()));
104+
}
105+
}
106+
48107
protected override void OnSetUp()
49108
{
50109
using (var session = OpenSession())
51110
using (var transaction = session.BeginTransaction())
52111
{
53-
session.Save(new Person {Name = "Test1"});
54-
session.Save(new Person {Name = "Test2"});
112+
session.Save(new Person {Name = "Test1", Age = 20});
113+
session.Save(new Person {Name = "Test2", Age = 30});
55114
session.Save(new Person {Name = "Test3"});
56115
session.Save(new Person {Name = "Test4"});
57116
transaction.Commit();

0 commit comments

Comments
 (0)