forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFixture.cs
76 lines (64 loc) · 2.26 KB
/
Fixture.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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));
}
}
}
}