forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPositionalParametersFixture.cs
118 lines (107 loc) · 2.5 KB
/
PositionalParametersFixture.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
112
113
114
115
116
117
118
using System;
using System.Collections;
using NUnit.Framework;
namespace NHibernate.Test.QueryTest
{
/// <summary>
/// Summary description for PositionalParametersFixture.
/// </summary>
[TestFixture]
public class PositionalParametersFixture : TestCase
{
protected override string[] Mappings
{
get { return new string[] {"Simple.hbm.xml"}; }
}
[Test]
public void TestMissingHQLParameters()
{
ISession s = OpenSession();
ITransaction t = s.BeginTransaction();
try
{
IQuery q = s.CreateQuery("from s in class Simple where s.Name=? and s.Count=?");
// Set the first property, but not the second
q.SetParameter(0, "Fred");
// Try to execute it
Assert.Throws<QueryException>(() => q.List());
}
finally
{
t.Rollback();
s.Close();
}
}
[Test]
public void TestMissingHQLParameters2()
{
ISession s = OpenSession();
ITransaction t = s.BeginTransaction();
try
{
IQuery q = s.CreateQuery("from s in class Simple where s.Name=? and s.Count=?");
// Set the second property, but not the first - should give a nice not found at position xxx error
q.SetParameter(1, "Fred");
// Try to execute it
Assert.Throws<QueryException>(() => q.List());
}
finally
{
t.Rollback();
s.Close();
}
}
[Test]
public void TestPositionOutOfBounds()
{
ISession s = OpenSession();
ITransaction t = s.BeginTransaction();
try
{
IQuery q = s.CreateQuery("from s in class Simple where s.Name=? and s.Count=?");
// Try to set the third positional parameter
Assert.Throws<ArgumentException>(() => q.SetParameter(3, "Fred"));
}
finally
{
t.Rollback();
s.Close();
}
}
[Test]
public void TestNoPositionalParameters()
{
ISession s = OpenSession();
ITransaction t = s.BeginTransaction();
try
{
IQuery q = s.CreateQuery("from s in class Simple where s.Name=:Name and s.Count=:Count");
// Try to set the first property
Assert.Throws<ArgumentException>(() => q.SetParameter(0, "Fred"));
}
finally
{
t.Rollback();
s.Close();
}
}
/// <summary>
/// Verifying that a <see langword="null" /> value passed into SetParameter(index, val) throws
/// an exception
/// </summary>
[Test]
public void TestNullIndexedParameter()
{
ISession s = OpenSession();
try
{
IQuery q = s.CreateQuery("from Simple as s where s.Name=?");
Assert.Throws<ArgumentNullException>(() => q.SetParameter(0, null));
}
finally
{
s.Close();
}
}
}
}