forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMsSqlDialectFixture.cs
74 lines (66 loc) · 2.88 KB
/
MsSqlDialectFixture.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
using System;
using NHibernate.Dialect;
using NHibernate.SqlCommand;
using NHibernate.Type;
using NUnit.Framework;
namespace NHibernate.Test.DialectTest
{
/// <summary>
/// Summary description for MsSqlDialectFixture.
/// </summary>
[TestFixture]
public class MsSqlDialectFixture : DialectFixture
{
[SetUp]
public override void SetUp()
{
// Generic Dialect inherits all of the Quoting functions from
// Dialect (which is abstract)
d = new MsSql2000Dialect();
tableWithNothingToBeQuoted = new string[] {"plainname", "[plainname]"};
tableAlreadyQuoted = new string[] {"[Quote[d[Na]]$`]", "[Quote[d[Na]]$`]", "Quote[d[Na]$`"};
tableThatNeedsToBeQuoted = new string[] {"Quote[d[Na]$`", "[Quote[d[Na]]$`]", "Quote[d[Na]$`"};
}
[Test]
public void GetLimitString()
{
SqlStringBuilder builder = new SqlStringBuilder();
builder.Add("select id, col1, col2 from someTable");
SqlString limitedSql = d.GetLimitString(builder.ToSqlString(), null, new SqlString("100"));
Assert.AreEqual("select top 100 id, col1, col2 from someTable", limitedSql.ToString(),
"Bad limit SQL");
// test when building with SqlParts
builder = new SqlStringBuilder();
builder.Add("select").Add(" id, col1, col2 ").Add("from someTable");
limitedSql = d.GetLimitString(builder.ToSqlString(), null, new SqlString("100"));
Assert.AreEqual("select top 100 id, col1, col2 from someTable", limitedSql.ToString(),
"Bad limit SQL");
// now add a subselect to see if only one top gets added
builder.Add(" where id in (select id from othertable)");
limitedSql = d.GetLimitString(builder.ToSqlString(), null, new SqlString("100"));
Assert.AreEqual("select top 100 id, col1, col2 from someTable where id in (select id from othertable)",
limitedSql.ToString(),
"Bad limit SQL");
// now the distinct case
// first with simple string
builder = new SqlStringBuilder();
builder.Add("select distinct id, col1, col2 from someTable");
limitedSql = d.GetLimitString(builder.ToSqlString(), null, new SqlString("100"));
Assert.AreEqual("select distinct top 100 id, col1, col2 from someTable", limitedSql.ToString(),
"Bad limit SQL");
// now with parts
builder = new SqlStringBuilder();
builder.Add("select").Add(" distinct").Add(" id, col1, col2 from someTable");
limitedSql = d.GetLimitString(builder.ToSqlString(), null, new SqlString("100"));
Assert.AreEqual("select distinct top 100 id, col1, col2 from someTable", limitedSql.ToString(),
"Bad limit SQL");
}
[Test]
public void DateTimeRounding()
{
DateTime input = new DateTime(2000, 1, 1, 10, 11, 12, 13);
DateTime expected = new DateTime(2000, 1, 1, 10, 11, 12, 10);
Assert.AreEqual(expected, AbstractDateTimeType.Round(input, d.TimestampResolutionInTicks));
}
}
}