forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQLExpressionFixture.cs
64 lines (50 loc) · 1.63 KB
/
SQLExpressionFixture.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
using NHibernate.DomainModel;
using NHibernate.Criterion;
using NHibernate.SqlCommand;
using NUnit.Framework;
namespace NHibernate.Test.ExpressionTest
{
[TestFixture]
public class SQLExpressionFixture : BaseExpressionFixture
{
[Test]
public void StraightSqlTest()
{
using (ISession session = factory.OpenSession())
{
ICriterion sqlExpression = Expression.Sql("{alias}.address is not null");
CreateObjects(typeof(Simple), session);
SqlString sqlString = sqlExpression.ToSqlString(criteria, criteriaQuery);
string expectedSql = "sql_alias.address is not null";
CompareSqlStrings(sqlString, expectedSql);
}
}
[Test]
public void NoParamsSqlStringTest()
{
using (ISession session = factory.OpenSession())
{
ICriterion sqlExpression = Expression.Sql(new SqlString("{alias}.address is not null"));
CreateObjects(typeof(Simple), session);
SqlString sqlString = sqlExpression.ToSqlString(criteria, criteriaQuery);
string expectedSql = "sql_alias.address is not null";
CompareSqlStrings(sqlString, expectedSql);
}
}
[Test]
public void WithParameterTest()
{
using (ISession session = factory.OpenSession())
{
SqlStringBuilder builder = new SqlStringBuilder();
string expectedSql = "sql_alias.address = ?";
builder.Add("{alias}.address = ");
builder.AddParameter();
ICriterion sqlExpression = Expression.Sql(builder.ToSqlString(), "some address", NHibernateUtil.String);
CreateObjects(typeof(Simple), session);
SqlString sqlString = sqlExpression.ToSqlString(criteria, criteriaQuery);
CompareSqlStrings(sqlString, expectedSql, 1);
}
}
}
}