|
| 1 | +//------------------------------------------------------------------------------ |
| 2 | +// <auto-generated> |
| 3 | +// This code was generated by AsyncGenerator. |
| 4 | +// |
| 5 | +// Changes to this file may cause incorrect behavior and will be lost if |
| 6 | +// the code is regenerated. |
| 7 | +// </auto-generated> |
| 8 | +//------------------------------------------------------------------------------ |
| 9 | + |
| 10 | + |
| 11 | +using System.Linq; |
| 12 | +using NUnit.Framework; |
| 13 | +using NHibernate.Linq; |
| 14 | + |
| 15 | +namespace NHibernate.Test.NHSpecificTest.GH1704 |
| 16 | +{ |
| 17 | + using System.Threading.Tasks; |
| 18 | + [TestFixture] |
| 19 | + public class FixtureAsync : BugTestCase |
| 20 | + { |
| 21 | + protected override void OnSetUp() |
| 22 | + { |
| 23 | + using (var session = OpenSession()) |
| 24 | + using (var transaction = session.BeginTransaction()) |
| 25 | + { |
| 26 | + var e1 = new Entity { Country = "Greece", City = "Athens", Budget = 100000m }; |
| 27 | + session.Save(e1); |
| 28 | + |
| 29 | + var e2 = new Entity { Country = "Greece", City = "Chania", Budget = 50000m }; |
| 30 | + session.Save(e2); |
| 31 | + |
| 32 | + var e3 = new Entity { Country = "Italy", City = "Rome", Budget = 200000m }; |
| 33 | + session.Save(e3); |
| 34 | + |
| 35 | + var e4 = new Entity { Country = "Italy", City = "Milan", Budget = 100000m }; |
| 36 | + session.Save(e4); |
| 37 | + |
| 38 | + var e5 = new Entity { Country = "France", City = "Paris", Budget = 300000m }; |
| 39 | + session.Save(e5); |
| 40 | + |
| 41 | + transaction.Commit(); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + protected override void OnTearDown() |
| 46 | + { |
| 47 | + using (var session = OpenSession()) |
| 48 | + using (var transaction = session.BeginTransaction()) |
| 49 | + { |
| 50 | + // The HQL delete does all the job inside the database without loading the entities, but it does |
| 51 | + // not handle delete order for avoiding violating constraints if any. Use |
| 52 | + // session.Delete("from System.Object"); |
| 53 | + // instead if in need of having NHbernate ordering the deletes, but this will cause |
| 54 | + // loading the entities in the session. |
| 55 | + session.CreateQuery("delete from System.Object").ExecuteUpdate(); |
| 56 | + |
| 57 | + transaction.Commit(); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + [Test(Description = "GH-1704")] |
| 62 | + public async Task GroupByCustomClassAsKeyAsync() |
| 63 | + { |
| 64 | + using (var session = OpenSession()) |
| 65 | + using (session.BeginTransaction()) |
| 66 | + { |
| 67 | + var result = await (session.Query<Entity>() |
| 68 | + .GroupBy(a => new GroupByEntity(a.Country)) |
| 69 | + .Select(a => new { groupby = a.Key, cnt = a.Count(), sum = a.Sum(o => o.Budget) }) |
| 70 | + .ToListAsync()); |
| 71 | + |
| 72 | + Assert.That(result, Has.Count.EqualTo(3)); |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | +} |
0 commit comments