-
Notifications
You must be signed in to change notification settings - Fork 933
Unit test & Fix for GH1704 #1705
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
src/NHibernate.Test/Async/NHSpecificTest/GH1704/Fixture.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by AsyncGenerator. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
|
||
using System.Linq; | ||
using NUnit.Framework; | ||
using NHibernate.Linq; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH1704 | ||
{ | ||
using System.Threading.Tasks; | ||
[TestFixture] | ||
public class FixtureAsync : BugTestCase | ||
{ | ||
protected override void OnSetUp() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
var e1 = new Entity { Country = "Greece", City = "Athens", Budget = 100000m }; | ||
session.Save(e1); | ||
|
||
var e2 = new Entity { Country = "Greece", City = "Chania", Budget = 50000m }; | ||
session.Save(e2); | ||
|
||
var e3 = new Entity { Country = "Italy", City = "Rome", Budget = 200000m }; | ||
session.Save(e3); | ||
|
||
var e4 = new Entity { Country = "Italy", City = "Milan", Budget = 100000m }; | ||
session.Save(e4); | ||
|
||
var e5 = new Entity { Country = "France", City = "Paris", Budget = 300000m }; | ||
session.Save(e5); | ||
|
||
transaction.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
// The HQL delete does all the job inside the database without loading the entities, but it does | ||
// not handle delete order for avoiding violating constraints if any. Use | ||
// session.Delete("from System.Object"); | ||
// instead if in need of having NHbernate ordering the deletes, but this will cause | ||
// loading the entities in the session. | ||
session.CreateQuery("delete from System.Object").ExecuteUpdate(); | ||
|
||
transaction.Commit(); | ||
} | ||
} | ||
|
||
[Test(Description = "GH-1704")] | ||
public async Task GroupByCustomClassAsKeyAsync() | ||
{ | ||
using (var session = OpenSession()) | ||
using (session.BeginTransaction()) | ||
{ | ||
var result = await (session.Query<Entity>() | ||
.GroupBy(a => new GroupByEntity(a.Country)) | ||
.Select(a => new { groupby = a.Key, cnt = a.Count(), sum = a.Sum(o => o.Budget) }) | ||
.ToListAsync()); | ||
|
||
Assert.That(result, Has.Count.EqualTo(3)); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH1704 | ||
{ | ||
class Entity | ||
{ | ||
public virtual Guid Id { get; set; } | ||
public virtual string Country { get; set; } | ||
public virtual string City { get; set; } | ||
public virtual decimal Budget { get; set; } | ||
} | ||
|
||
class GroupByEntity | ||
{ | ||
public GroupByEntity(string country) | ||
{ | ||
Country = country; | ||
} | ||
public virtual string Country { get; set; } | ||
public virtual string City { get; set; } | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System.Linq; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH1704 | ||
{ | ||
[TestFixture] | ||
public class Fixture : BugTestCase | ||
{ | ||
protected override void OnSetUp() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
var e1 = new Entity { Country = "Greece", City = "Athens", Budget = 100000m }; | ||
session.Save(e1); | ||
|
||
var e2 = new Entity { Country = "Greece", City = "Chania", Budget = 50000m }; | ||
session.Save(e2); | ||
|
||
var e3 = new Entity { Country = "Italy", City = "Rome", Budget = 200000m }; | ||
session.Save(e3); | ||
|
||
var e4 = new Entity { Country = "Italy", City = "Milan", Budget = 100000m }; | ||
session.Save(e4); | ||
|
||
var e5 = new Entity { Country = "France", City = "Paris", Budget = 300000m }; | ||
session.Save(e5); | ||
|
||
transaction.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
// The HQL delete does all the job inside the database without loading the entities, but it does | ||
// not handle delete order for avoiding violating constraints if any. Use | ||
// session.Delete("from System.Object"); | ||
// instead if in need of having NHbernate ordering the deletes, but this will cause | ||
// loading the entities in the session. | ||
session.CreateQuery("delete from System.Object").ExecuteUpdate(); | ||
|
||
transaction.Commit(); | ||
} | ||
} | ||
|
||
[Test(Description = "GH-1704")] | ||
public void GroupByCustomClassAsKey() | ||
{ | ||
using (var session = OpenSession()) | ||
using (session.BeginTransaction()) | ||
{ | ||
var result = session.Query<Entity>() | ||
.GroupBy(a => new GroupByEntity(a.Country)) | ||
.Select(a => new { groupby = a.Key, cnt = a.Count(), sum = a.Sum(o => o.Budget) }) | ||
.ToList(); | ||
|
||
Assert.That(result, Has.Count.EqualTo(3)); | ||
} | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/NHibernate.Test/NHSpecificTest/GH1704/Mappings.hbm.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<hibernate-mapping | ||
xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" namespace="NHibernate.Test.NHSpecificTest.GH1704"> | ||
<class name="Entity"> | ||
<id name="Id" generator="guid.comb"/> | ||
<property name="Country"/> | ||
<property name="City"/> | ||
<property name="Budget"/> | ||
</class> | ||
</hibernate-mapping> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to the test nature, it appears to me no async code re-generation has been run, because for such a test, it should have generated an async counterpart. Please run the async generator. (See contributing.)