Skip to content

WIP - Add support for IAsyncEnumerable #2274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
6 changes: 6 additions & 0 deletions src/AsyncGenerator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@
- conversion: Ignore
name: GetEnumerator
containingTypeName: IFutureEnumerable
- conversion: Ignore
name: AsyncEnumerable
- conversion: Ignore
name: AsyncEnumerableFilter
- conversion: ToAsync
name: ExecuteReader
containingTypeName: IBatcher
Expand Down Expand Up @@ -221,6 +225,8 @@
- conversion: Ignore
anyBaseTypeRule: IsTestCase
executionPhase: PostProviders
ignoreSearchForAsyncCounterparts:
- name: Enumerable
ignoreDocuments:
- filePathEndsWith: Linq/MathTests.cs
- filePathEndsWith: Linq/ExpressionSessionLeakTest.cs
Expand Down
13 changes: 13 additions & 0 deletions src/NHibernate.DomainModel/Northwind/Entities/INamedEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NHibernate.DomainModel.Northwind.Entities
{
public interface INamedEntity
{
int Id { get; }

string Name { get; }
}
}
2 changes: 1 addition & 1 deletion src/NHibernate.DomainModel/Northwind/Entities/Role.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace NHibernate.DomainModel.Northwind.Entities
{
public class Role
public class Role : INamedEntity
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate.DomainModel/Northwind/Entities/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface IUser
IUser ModifiedBy { get; set; }
}

public class User : IUser, IEntity
public class User : IUser, IEntity, INamedEntity
{
public virtual int Id { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public async Task BatchableRootEntityTestAsync()
using (var tx = s.BeginTransaction())
{
var enumerator =
(await (s.CreateQuery("from foo in class NHibernate.DomainModel.Foo order by foo.String").EnumerableAsync())).GetEnumerator();
s.CreateQuery("from foo in class NHibernate.DomainModel.Foo order by foo.String").Enumerable().GetEnumerator();
var i = 1;
while (enumerator.MoveNext())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public async Task CompositeIdsAsync()
{
Assert.AreEqual(2, stuff.Length);
}
iter = await (s.CreateQuery("from Order o join o.LineItems li").EnumerableAsync());
iter = s.CreateQuery("from Order o join o.LineItems li").Enumerable();
foreach (object[] stuff in iter)
{
Assert.AreEqual(2, stuff.Length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public async Task SerializationFailsOnAfterStatementAggressiveReleaseWithOpenRes
// both scroll() and iterate() cause the batcher to hold on
// to resources, which should make aggresive-Release not Release
// the connection (and thus cause serialization to fail)
IEnumerable en = await (s.CreateQuery("from Silly").EnumerableAsync());
var en = s.CreateQuery("from Silly").Enumerable().GetEnumerator();
en.MoveNext();

try
{
Expand Down Expand Up @@ -125,15 +126,15 @@ public async Task QueryIterationAsync()
await (s.SaveAsync(silly));
await (s.FlushAsync());

IEnumerable en = await (s.CreateQuery("from Silly").EnumerableAsync());
IEnumerable en = s.CreateQuery("from Silly").Enumerable();
IEnumerator itr = en.GetEnumerator();
Assert.IsTrue(itr.MoveNext());
Silly silly2 = (Silly) itr.Current;
Assert.AreEqual(silly, silly2);
NHibernateUtil.Close(itr);

itr = (await (s.CreateQuery("from Silly").EnumerableAsync())).GetEnumerator();
IEnumerator itr2 = (await (s.CreateQuery("from Silly where name = 'silly'").EnumerableAsync())).GetEnumerator();
itr = s.CreateQuery("from Silly").Enumerable().GetEnumerator();
IEnumerator itr2 = s.CreateQuery("from Silly where name = 'silly'").Enumerable().GetEnumerator();

Assert.IsTrue(itr.MoveNext());
Assert.AreEqual(silly, itr.Current);
Expand Down
42 changes: 7 additions & 35 deletions src/NHibernate.Test/Async/GenericTest/Methods/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@

using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using NHibernate.Criterion;
using NHibernate.DomainModel;
using NUnit.Framework;

namespace NHibernate.Test.GenericTest.Methods
{
using System.Threading.Tasks;
[TestFixture]
public class FixtureAsync : TestCase
{
protected override string[] Mappings
{
get
{
return new string[] { "One.hbm.xml", "Many.hbm.xml" };
return new string[] { "One.hbm.xml", "Many.hbm.xml", "Simple.hbm.xml" };
}
}

Expand All @@ -49,12 +49,15 @@ protected override void OnSetUp()
many2.One = one;
one.Manies.Add( many2 );

using( ISession s = OpenSession() )
var simple = new Simple(1) {Count = 1};

using ( ISession s = OpenSession() )
using( ITransaction t = s.BeginTransaction() )
{
s.Save( one );
s.Save( many1 );
s.Save( many2 );
s.Save(simple, 1);
t.Commit();
}
}
Expand All @@ -66,6 +69,7 @@ protected override void OnTearDown()
{
session.Delete( "from Many" );
session.Delete( "from One" );
session.Delete("from Simple");
tx.Commit();
}
base.OnTearDown();
Expand Down Expand Up @@ -102,20 +106,6 @@ public async Task QueryListAsync()
}
}

[Test]
public async Task QueryEnumerableAsync()
{
using( ISession s = OpenSession() )
using( ITransaction t = s.BeginTransaction() )
{
IEnumerable<One> results = await (s.CreateQuery( "from One" ).EnumerableAsync<One>());
IEnumerator<One> en = results.GetEnumerator();

Assert.IsTrue( en.MoveNext() );
Assert.IsFalse( en.MoveNext() );
}
}

[Test]
public async Task FilterAsync()
{
Expand All @@ -131,23 +121,5 @@ public async Task FilterAsync()
await (t.CommitAsync());
}
}

[Test]
public async Task FilterEnumerableAsync()
{
using( ISession s = OpenSession() )
using( ITransaction t = s.BeginTransaction() )
{
One one2 = ( One ) await (s.CreateQuery( "from One" ).UniqueResultAsync());
IEnumerable<Many> results = await ((await (s.CreateFilterAsync( one2.Manies, "where X = 10" )))
.EnumerableAsync<Many>());
IEnumerator<Many> en = results.GetEnumerator();

Assert.IsTrue( en.MoveNext() );
Assert.AreEqual( 10, en.Current.X );
Assert.IsFalse( en.MoveNext() );
await (t.CommitAsync());
}
}
}
}
Loading