forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLimitClauseFixture.cs
111 lines (91 loc) · 3.53 KB
/
LimitClauseFixture.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate.Hql.Ast.ANTLR;
using NUnit.Framework;
namespace NHibernate.Test.Hql.Ast
{
[TestFixture]
public class LimitClauseFixture : BaseFixture
{
protected override void OnSetUp()
{
ISession session = OpenSession();
ITransaction txn = session.BeginTransaction();
var mother = new Human { BodyWeight = 10, Description = "mother" };
var father = new Human { BodyWeight = 15, Description = "father" };
var child1 = new Human { BodyWeight = 5, Description = "child1" };
var child2 = new Human { BodyWeight = 6, Description = "child2" };
var friend = new Human { BodyWeight = 20, Description = "friend" };
session.Save(mother);
session.Save(father);
session.Save(child1);
session.Save(child2);
session.Save(friend);
txn.Commit();
session.Close();
}
protected override void OnTearDown()
{
ISession session = OpenSession();
ITransaction txn = session.BeginTransaction();
session.Delete("from Animal");
txn.Commit();
session.Close();
}
[Test]
public void None()
{
ISession s = OpenSession();
ITransaction txn = s.BeginTransaction();
var actual = s.CreateQuery("from Human h order by h.bodyWeight").List<Human>().Select(h => h.BodyWeight).ToArray();
var expected = new[] { 5, 6, 10, 15, 20 };
CollectionAssert.AreEqual(expected, actual);
txn.Commit();
s.Close();
}
[Test]
public void Skip()
{
ISession s = OpenSession();
ITransaction txn = s.BeginTransaction();
var actual = s.CreateQuery("from Human h order by h.bodyWeight skip 2").List<Human>().Select(h => h.BodyWeight).ToArray();
var expected = new[] { 10, 15, 20 };
CollectionAssert.AreEqual(expected, actual);
txn.Commit();
s.Close();
}
[Test]
public void Take()
{
ISession s = OpenSession();
ITransaction txn = s.BeginTransaction();
var actual = s.CreateQuery("from Human h order by h.bodyWeight take 2").List<Human>().Select(h => h.BodyWeight).ToArray();
var expected = new[] { 5, 6 };
CollectionAssert.AreEqual(expected, actual);
txn.Commit();
s.Close();
}
[Test]
public void SkipTake()
{
ISession s = OpenSession();
ITransaction txn = s.BeginTransaction();
var actual = s.CreateQuery("from Human h order by h.bodyWeight skip 1 take 3").List<Human>().Select(h => h.BodyWeight).ToArray();
var expected = new[] { 6, 10, 15 };
CollectionAssert.AreEqual(expected, actual);
txn.Commit();
s.Close();
}
[Test]
public void TakeSkip()
{
ISession s = OpenSession();
ITransaction txn = s.BeginTransaction();
Assert.Throws<QuerySyntaxException>(() => s.CreateQuery("from Human h order by h.bodyWeight take 1 skip 2").List<Human>(), "take should not be allowed before skip");
txn.Commit();
s.Close();
}
}
}