Skip to content

Commit 0813546

Browse files
Regenerate Async.
1 parent bf9794a commit 0813546

File tree

10 files changed

+463
-36
lines changed

10 files changed

+463
-36
lines changed

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ protected override void OnTearDown()
6565
base.OnTearDown();
6666
}
6767

68+
[Test]
69+
public async Task FutureOfCriteriaFallsBackToListImplementationWhenQueryBatchingIsNotSupportedAsync()
70+
{
71+
using (var session = Sfi.OpenSession())
72+
{
73+
var results = session.CreateCriteria<Person>().Future<Person>();
74+
(await (results.GetEnumerableAsync())).GetEnumerator().MoveNext();
75+
}
76+
}
77+
6878
[Test]
6979
public async Task FutureValueOfCriteriaCanGetSingleEntityWhenQueryBatchingIsNotSupportedAsync()
7080
{
@@ -93,6 +103,16 @@ public async Task FutureValueOfCriteriaCanGetScalarValueWhenQueryBatchingIsNotSu
93103
}
94104
}
95105

106+
[Test]
107+
public async Task FutureOfQueryFallsBackToListImplementationWhenQueryBatchingIsNotSupportedAsync()
108+
{
109+
using (var session = Sfi.OpenSession())
110+
{
111+
var results = session.CreateQuery("from Person").Future<Person>();
112+
(await (results.GetEnumerableAsync())).GetEnumerator().MoveNext();
113+
}
114+
}
115+
96116
[Test]
97117
public async Task FutureValueOfQueryCanGetSingleEntityWhenQueryBatchingIsNotSupportedAsync()
98118
{
@@ -120,6 +140,16 @@ public async Task FutureValueOfQueryCanGetScalarValueWhenQueryBatchingIsNotSuppo
120140
}
121141
}
122142

143+
[Test]
144+
public async Task FutureOfLinqFallsBackToListImplementationWhenQueryBatchingIsNotSupportedAsync()
145+
{
146+
using (var session = Sfi.OpenSession())
147+
{
148+
var results = session.Query<Person>().ToFuture();
149+
(await (results.GetEnumerableAsync())).GetEnumerator().MoveNext();
150+
}
151+
}
152+
123153
[Test]
124154
public async Task FutureValueOfLinqCanGetSingleEntityWhenQueryBatchingIsNotSupportedAsync()
125155
{
@@ -160,4 +190,4 @@ public async Task FutureValueWithSelectorOfLinqCanGetSingleEntityWhenQueryBatchi
160190
}
161191
}
162192
}
163-
}
193+
}

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

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,78 @@ namespace NHibernate.Test.Futures
1818
[TestFixture]
1919
public class FutureCriteriaFixtureAsync : FutureFixture
2020
{
21+
[Test]
22+
public async Task DefaultReadOnlyTestAsync()
23+
{
24+
//NH-3575
25+
using (var s = Sfi.OpenSession())
26+
{
27+
s.DefaultReadOnly = true;
28+
29+
var persons = s.CreateCriteria(typeof(Person)).Future<Person>();
30+
31+
Assert.IsTrue((await (persons.GetEnumerableAsync())).All(p => s.IsReadOnly(p)));
32+
}
33+
}
34+
35+
[Test]
36+
public async Task CanUseFutureCriteriaAsync()
37+
{
38+
using (var s = Sfi.OpenSession())
39+
{
40+
IgnoreThisTestIfMultipleQueriesArentSupportedByDriver();
41+
42+
var persons10 = s.CreateCriteria(typeof(Person))
43+
.SetMaxResults(10)
44+
.Future<Person>();
45+
var persons5 = s.CreateCriteria(typeof(Person))
46+
.SetMaxResults(5)
47+
.Future<int>();
48+
49+
using (var logSpy = new SqlLogSpy())
50+
{
51+
foreach (var person in await (persons5.GetEnumerableAsync()))
52+
{
53+
54+
}
55+
56+
foreach (var person in await (persons10.GetEnumerableAsync()))
57+
{
58+
59+
}
60+
61+
var events = logSpy.Appender.GetEvents();
62+
Assert.AreEqual(1, events.Length);
63+
}
64+
}
65+
}
66+
67+
[Test]
68+
public async Task TwoFuturesRunInTwoRoundTripsAsync()
69+
{
70+
using (var s = Sfi.OpenSession())
71+
{
72+
IgnoreThisTestIfMultipleQueriesArentSupportedByDriver();
73+
74+
using (var logSpy = new SqlLogSpy())
75+
{
76+
var persons10 = s.CreateCriteria(typeof(Person))
77+
.SetMaxResults(10)
78+
.Future<Person>();
79+
80+
foreach (var person in await (persons10.GetEnumerableAsync())) { } // fire first future round-trip
81+
82+
var persons5 = s.CreateCriteria(typeof(Person))
83+
.SetMaxResults(5)
84+
.Future<int>();
85+
86+
foreach (var person in await (persons5.GetEnumerableAsync())) { } // fire second future round-trip
87+
88+
var events = logSpy.Appender.GetEvents();
89+
Assert.AreEqual(2, events.Length);
90+
}
91+
}
92+
}
2193

2294
[Test]
2395
public async Task CanCombineSingleFutureValueWithEnumerableFuturesAsync()
@@ -38,7 +110,7 @@ public async Task CanCombineSingleFutureValueWithEnumerableFuturesAsync()
38110
{
39111
int count = await (personCount.GetValueAsync());
40112

41-
foreach (var person in persons)
113+
foreach (var person in await (persons.GetEnumerableAsync()))
42114
{
43115

44116
}

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

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,78 @@ namespace NHibernate.Test.Futures
1818
[TestFixture]
1919
public class FutureQueryFixtureAsync : FutureFixture
2020
{
21+
[Test]
22+
public async Task DefaultReadOnlyTestAsync()
23+
{
24+
//NH-3575
25+
using (var s = Sfi.OpenSession())
26+
{
27+
s.DefaultReadOnly = true;
28+
29+
var persons = s.CreateQuery("from Person").Future<Person>();
30+
31+
Assert.IsTrue((await (persons.GetEnumerableAsync())).All(p => s.IsReadOnly(p)));
32+
}
33+
}
34+
35+
[Test]
36+
public async Task CanUseFutureQueryAsync()
37+
{
38+
using (var s = Sfi.OpenSession())
39+
{
40+
IgnoreThisTestIfMultipleQueriesArentSupportedByDriver();
41+
42+
var persons10 = s.CreateQuery("from Person")
43+
.SetMaxResults(10)
44+
.Future<Person>();
45+
var persons5 = s.CreateQuery("from Person")
46+
.SetMaxResults(5)
47+
.Future<int>();
48+
49+
using (var logSpy = new SqlLogSpy())
50+
{
51+
foreach (var person in await (persons5.GetEnumerableAsync()))
52+
{
53+
54+
}
55+
56+
foreach (var person in await (persons10.GetEnumerableAsync()))
57+
{
58+
59+
}
60+
61+
var events = logSpy.Appender.GetEvents();
62+
Assert.AreEqual(1, events.Length);
63+
}
64+
}
65+
}
66+
67+
[Test]
68+
public async Task TwoFuturesRunInTwoRoundTripsAsync()
69+
{
70+
using (var s = Sfi.OpenSession())
71+
{
72+
IgnoreThisTestIfMultipleQueriesArentSupportedByDriver();
73+
74+
using (var logSpy = new SqlLogSpy())
75+
{
76+
var persons10 = s.CreateQuery("from Person")
77+
.SetMaxResults(10)
78+
.Future<Person>();
79+
80+
foreach (var person in await (persons10.GetEnumerableAsync())) { } // fire first future round-trip
81+
82+
var persons5 = s.CreateQuery("from Person")
83+
.SetMaxResults(5)
84+
.Future<int>();
85+
86+
foreach (var person in await (persons5.GetEnumerableAsync())) { } // fire second future round-trip
87+
88+
var events = logSpy.Appender.GetEvents();
89+
Assert.AreEqual(2, events.Length);
90+
}
91+
}
92+
}
2193

2294
[Test]
2395
public async Task CanCombineSingleFutureValueWithEnumerableFuturesAsync()
@@ -37,7 +109,7 @@ public async Task CanCombineSingleFutureValueWithEnumerableFuturesAsync()
37109
{
38110
long count = await (personCount.GetValueAsync());
39111

40-
foreach (var person in persons)
112+
foreach (var person in await (persons.GetEnumerableAsync()))
41113
{
42114
}
43115

@@ -66,7 +138,7 @@ public async Task CanExecuteMultipleQueryWithSameParameterNameAsync()
66138
{
67139
var me = await (meContainer.GetValueAsync());
68140

69-
foreach (var person in possiblefriends)
141+
foreach (var person in await (possiblefriends.GetEnumerableAsync()))
70142
{
71143
}
72144

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

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,82 @@ protected override void OnTearDown()
4040
}
4141
}
4242

43+
[Test]
44+
public async Task DefaultReadOnlyTestAsync()
45+
{
46+
//NH-3575
47+
using (var s = Sfi.OpenSession())
48+
{
49+
s.DefaultReadOnly = true;
50+
51+
var persons = s.QueryOver<Person>().Future<Person>();
52+
53+
Assert.IsTrue((await (persons.GetEnumerableAsync())).All(p => s.IsReadOnly(p)));
54+
}
55+
}
56+
57+
[Test]
58+
public async Task CanUseFutureCriteriaAsync()
59+
{
60+
using (var s = Sfi.OpenSession())
61+
{
62+
IgnoreThisTestIfMultipleQueriesArentSupportedByDriver();
63+
64+
var persons10 = s.QueryOver<Person>()
65+
.Take(10)
66+
.Future();
67+
var persons5 = s.QueryOver<Person>()
68+
.Select(p => p.Id)
69+
.Take(5)
70+
.Future<int>();
71+
72+
using (var logSpy = new SqlLogSpy())
73+
{
74+
int actualPersons5Count = 0;
75+
foreach (var person in await (persons5.GetEnumerableAsync()))
76+
actualPersons5Count++;
77+
78+
int actualPersons10Count = 0;
79+
foreach (var person in await (persons10.GetEnumerableAsync()))
80+
actualPersons10Count++;
81+
82+
var events = logSpy.Appender.GetEvents();
83+
Assert.AreEqual(1, events.Length);
84+
85+
Assert.That(actualPersons5Count, Is.EqualTo(1));
86+
Assert.That(actualPersons10Count, Is.EqualTo(1));
87+
}
88+
}
89+
}
90+
91+
[Test]
92+
public async Task TwoFuturesRunInTwoRoundTripsAsync()
93+
{
94+
using (var s = Sfi.OpenSession())
95+
{
96+
IgnoreThisTestIfMultipleQueriesArentSupportedByDriver();
97+
98+
using (var logSpy = new SqlLogSpy())
99+
{
100+
var persons10 = s.QueryOver<Person>()
101+
.Take(10)
102+
.Future();
103+
104+
foreach (var person in await (persons10.GetEnumerableAsync())) { } // fire first future round-trip
105+
106+
var persons5 = s.QueryOver<Person>()
107+
.Select(p => p.Id)
108+
.Take(5)
109+
.Future<int>();
110+
111+
foreach (var person in await (persons5.GetEnumerableAsync())) { } // fire second future round-trip
112+
113+
var events = logSpy.Appender.GetEvents();
114+
Assert.AreEqual(2, events.Length);
115+
}
116+
}
117+
}
118+
43119
[Test]
44120
public async Task CanCombineSingleFutureValueWithEnumerableFuturesAsync()
45121
{
@@ -63,7 +139,7 @@ public async Task CanCombineSingleFutureValueWithEnumerableFuturesAsync()
63139
Person singlePersonValue = await (singlePerson.GetValueAsync());
64140
int personId = await (personIds.GetValueAsync());
65141

66-
foreach (var person in persons)
142+
foreach (var person in await (persons.GetEnumerableAsync()))
67143
{
68144

69145
}

0 commit comments

Comments
 (0)