Skip to content

Commit f71647d

Browse files
committed
Code review changes
1 parent 5dc8bc2 commit f71647d

28 files changed

+373
-126
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace NHibernate.DomainModel.Northwind.Entities
6+
{
7+
public interface INamedEntity
8+
{
9+
int Id { get; }
10+
11+
string Name { get; }
12+
}
13+
}

src/NHibernate.DomainModel/Northwind/Entities/Role.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace NHibernate.DomainModel.Northwind.Entities
22
{
3-
public class Role
3+
public class Role : INamedEntity
44
{
55
public virtual int Id { get; set; }
66
public virtual string Name { get; set; }

src/NHibernate.DomainModel/Northwind/Entities/User.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public interface IUser
2828
EnumStoredAsInt32 Enum2 { get; set; }
2929
}
3030

31-
public class User : IUser
31+
public class User : IUser, INamedEntity
3232
{
3333
public virtual int Id { get; set; }
3434

src/NHibernate.Test/Async/GenericTest/Methods/Fixture.cs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public async Task QueryListAsync()
103103
}
104104

105105
[Test]
106-
public async Task QueryAsyncEnumerable()
106+
public async Task QueryEnumerableAsync()
107107
{
108108
using (var s = OpenSession())
109109
using (var t = s.BeginTransaction())
@@ -134,36 +134,18 @@ public async Task FilterAsync()
134134

135135
[Test]
136136
public async Task FilterEnumerableAsync()
137-
{
138-
using( ISession s = OpenSession() )
139-
using( ITransaction t = s.BeginTransaction() )
140-
{
141-
One one2 = ( One ) await (s.CreateQuery( "from One" ).UniqueResultAsync());
142-
IEnumerable<Many> results = (await (s.CreateFilterAsync( one2.Manies, "where X = 10" )))
143-
.Enumerable<Many>();
144-
IEnumerator<Many> en = results.GetEnumerator();
145-
146-
Assert.IsTrue( en.MoveNext() );
147-
Assert.AreEqual( 10, en.Current.X );
148-
Assert.IsFalse( en.MoveNext() );
149-
await (t.CommitAsync());
150-
}
151-
}
152-
153-
[Test]
154-
public async Task FilterAsyncEnumerable()
155137
{
156138
using (var s = OpenSession())
157139
using (var t = s.BeginTransaction())
158140
{
159-
One one2 = (One) s.CreateQuery("from One").UniqueResult();
141+
One one2 = (One) await s.CreateQuery("from One").UniqueResultAsync();
160142
var results = s.CreateFilter(one2.Manies, "where X = 10").AsyncEnumerable<Many>();
161143
var en = results.GetAsyncEnumerator();
162144

163145
Assert.That(await en.MoveNextAsync(), Is.True);
164146
Assert.That(en.Current.X, Is.EqualTo(10));
165147
Assert.That(await en.MoveNextAsync(), Is.False);
166-
t.Commit();
148+
await t.CommitAsync();
167149
}
168150
}
169151
}

src/NHibernate.Test/Async/Legacy/FooBarTest.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
using NHibernate.Type;
2929
using NHibernate.Util;
3030
using NUnit.Framework;
31+
using System.Linq;
3132

3233
namespace NHibernate.Test.Legacy
3334
{
@@ -1222,10 +1223,7 @@ public async Task BatchLoadAsync()
12221223
await (s.DeleteAsync(baz2));
12231224
await (s.DeleteAsync(baz3));
12241225

1225-
IEnumerable en = new JoinedEnumerable(
1226-
new IEnumerable[] {baz.FooSet, baz2.FooSet});
1227-
1228-
foreach (object obj in en)
1226+
foreach (object obj in baz.FooSet.Concat(baz2.FooSet))
12291227
{
12301228
await (s.DeleteAsync(obj));
12311229
}
@@ -5279,10 +5277,9 @@ public async Task TransientOrphanDeleteAsync()
52795277
baz.FooBag = foos;
52805278
await (s.SaveAsync(baz));
52815279

5282-
IEnumerator enumer = new JoinedEnumerable(new IEnumerable[] {foos, bars}).GetEnumerator();
5283-
while (enumer.MoveNext())
5280+
foreach (var foo in foos.Concat(bars.Cast<Foo>()))
52845281
{
5285-
FooComponent cmp = ((Foo) enumer.Current).Component;
5282+
FooComponent cmp = foo.Component;
52865283
await (s.DeleteAsync(cmp.Glarch));
52875284
cmp.Glarch = null;
52885285
}

src/NHibernate.Test/GenericTest/Methods/Fixture.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void QueryEnumerable()
107107
}
108108

109109
[Test]
110-
public async Task QueryAsyncEnumerable()
110+
public async Task QueryEnumerableAsync()
111111
{
112112
using (var s = OpenSession())
113113
using (var t = s.BeginTransaction())
@@ -155,19 +155,19 @@ public void FilterEnumerable()
155155
}
156156

157157
[Test]
158-
public async Task FilterAsyncEnumerable()
158+
public async Task FilterEnumerableAsync()
159159
{
160160
using (var s = OpenSession())
161161
using (var t = s.BeginTransaction())
162162
{
163-
One one2 = (One) s.CreateQuery("from One").UniqueResult();
163+
One one2 = (One) await s.CreateQuery("from One").UniqueResultAsync();
164164
var results = s.CreateFilter(one2.Manies, "where X = 10").AsyncEnumerable<Many>();
165165
var en = results.GetAsyncEnumerator();
166166

167167
Assert.That(await en.MoveNextAsync(), Is.True);
168168
Assert.That(en.Current.X, Is.EqualTo(10));
169169
Assert.That(await en.MoveNextAsync(), Is.False);
170-
t.Commit();
170+
await t.CommitAsync();
171171
}
172172
}
173173
}

src/NHibernate.Test/Legacy/FooBarTest.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using NHibernate.Type;
1919
using NHibernate.Util;
2020
using NUnit.Framework;
21+
using System.Linq;
2122

2223
namespace NHibernate.Test.Legacy
2324
{
@@ -1210,10 +1211,7 @@ public void BatchLoad()
12101211
s.Delete(baz2);
12111212
s.Delete(baz3);
12121213

1213-
IEnumerable en = new JoinedEnumerable(
1214-
new IEnumerable[] {baz.FooSet, baz2.FooSet});
1215-
1216-
foreach (object obj in en)
1214+
foreach (object obj in baz.FooSet.Concat(baz2.FooSet))
12171215
{
12181216
s.Delete(obj);
12191217
}
@@ -5267,10 +5265,9 @@ public void TransientOrphanDelete()
52675265
baz.FooBag = foos;
52685266
s.Save(baz);
52695267

5270-
IEnumerator enumer = new JoinedEnumerable(new IEnumerable[] {foos, bars}).GetEnumerator();
5271-
while (enumer.MoveNext())
5268+
foreach (var foo in foos.Concat(bars.Cast<Foo>()))
52725269
{
5273-
FooComponent cmp = ((Foo) enumer.Current).Component;
5270+
FooComponent cmp = foo.Component;
52745271
s.Delete(cmp.Glarch);
52755272
cmp.Glarch = null;
52765273
}

src/NHibernate.Test/Linq/ByMethod/AsAsyncEnumerableTests.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Linq;
22
using System.Threading.Tasks;
3+
using NHibernate.DomainModel.Northwind.Entities;
34
using NHibernate.Linq;
45
using NUnit.Framework;
56

@@ -9,12 +10,12 @@ namespace NHibernate.Test.Linq.ByMethod
910
public class AsAsyncEnumerableTests : LinqTestCase
1011
{
1112
[Test]
12-
public async Task MultipleEnumerationTest()
13+
public async Task MultipleEnumerationTestAsync()
1314
{
1415
var asyncEnumerable = db.Customers.Where(c => c.Address.City == "London").OrderBy(c => c.CustomerId).AsAsyncEnumerable();
1516
for (var i = 0; i < 3; i++)
1617
{
17-
await AssertByIds(asyncEnumerable, new[]
18+
await AssertByPropertyValueAsync(asyncEnumerable, new[]
1819
{
1920
"AROUT",
2021
"BSBEV",
@@ -25,5 +26,22 @@ await AssertByIds(asyncEnumerable, new[]
2526
}, x => x.CustomerId);
2627
}
2728
}
29+
30+
[Test]
31+
public async Task PolymorphismTestAsync()
32+
{
33+
var asyncEnumerable = session.Query<INamedEntity>().OrderBy(o => o.Name).AsAsyncEnumerable();
34+
for (var i = 0; i < 3; i++)
35+
{
36+
await AssertByPropertyValueAsync(asyncEnumerable, new[]
37+
{
38+
"Admin",
39+
"User",
40+
"ayende",
41+
"nhibernate",
42+
"rahien"
43+
}, x => x.Name);
44+
}
45+
}
2846
}
2947
}

src/NHibernate.Test/Linq/LinqTestCase.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,21 @@ public static void AssertByIds<TEntity, TId>(IEnumerable<TEntity> entities, TId[
7070
Assert.That(entities.Select(x => entityIdGetter(x)), Is.EquivalentTo(expectedIds));
7171
}
7272

73-
public static async Task AssertByIds<TEntity, TId>(IAsyncEnumerable<TEntity> entities, TId[] expectedIds, Converter<TEntity, TId> entityIdGetter)
73+
public static async Task AssertByPropertyValueAsync<TEntity, TId>(IAsyncEnumerable<TEntity> entities, TId[] expectedIds, Converter<TEntity, TId> propertyValueGetter)
7474
{
7575
var enumerator = entities.GetAsyncEnumerator();
7676
bool hasNext;
7777
for (var i = 0; i < expectedIds.Length; i++)
7878
{
7979
hasNext = await enumerator.MoveNextAsync();
8080
Assert.That(hasNext, Is.True, $"The collection contains less entities than expected (Expected: {expectedIds.Length}, but was: {i})");
81-
Assert.That(entityIdGetter(enumerator.Current), Is.EqualTo(expectedIds[i]), $"Not expected entity on index {i}.");
81+
Assert.That(propertyValueGetter(enumerator.Current), Is.EqualTo(expectedIds[i]), $"Not expected entity on index {i}.");
8282
}
8383

8484
hasNext = await enumerator.MoveNextAsync();
8585
Assert.That(hasNext, Is.False, $"The collection contains more entities than expected (Expected: {expectedIds.Length})");
86+
87+
await enumerator.DisposeAsync();
8688
}
8789
}
8890
}

0 commit comments

Comments
 (0)