Repository navigation
Expand file tree
/
Copy pathSetOptionTest.cs
More file actions
134 lines (100 loc) · 8.11 KB
/
Copy pathSetOptionTest.cs
File metadata and controls
134 lines (100 loc) · 8.11 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using System;
using Microsoft.SqlServer.TransactSql.ScriptDom;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SqlStudio.Tests.AssemblyTools.TestCategory;
namespace SqlStudio.Tests.UTSqlScriptDom
{
/// <summary>
/// Tests the Set statement fragments
/// </summary>
public partial class SqlDomTests
{
private const string Statistics = "STATISTICS";
private static readonly string QuotedIdentifierStatement = EstablishTestStatement(CodeGenerationSupporter.QuotedIdentifier, true);
private static readonly string ConcatNullYieldsNullStatement = EstablishTestStatement(CodeGenerationSupporter.ConcatNullYieldsNull, false);
private static readonly string CursorCloseOnCommitStatement = EstablishTestStatement(CodeGenerationSupporter.CursorCloseOnCommit, false);
private static readonly string ArithAbortStatement = EstablishTestStatement(CodeGenerationSupporter.ArithAbort, true);
private static readonly string ArithIgnoreStatement = EstablishTestStatement(CodeGenerationSupporter.ArithIgnore, false);
private static readonly string FmtOnlyStatement = EstablishTestStatement(CodeGenerationSupporter.FmtOnly, true);
private static readonly string NoCountStatement = EstablishTestStatement(CodeGenerationSupporter.NoCount, false);
private static readonly string NoExecStatement = EstablishTestStatement(CodeGenerationSupporter.NoExec, true);
private static readonly string NumericRoundAbortStatement = EstablishTestStatement(CodeGenerationSupporter.NumericRoundAbort, false);
private static readonly string ParseOnlyStatement = EstablishTestStatement(CodeGenerationSupporter.ParseOnly, true);
private static readonly string AnsiDefaultsStatement = EstablishTestStatement(CodeGenerationSupporter.AnsiDefaults, true);
private static readonly string AnsiNullDfltOffStatement = EstablishTestStatement(CodeGenerationSupporter.AnsiNullDfltOff, false);
private static readonly string AnsiNullDfltOnStatement = EstablishTestStatement(CodeGenerationSupporter.AnsiNullDfltOn, true);
private static readonly string AnsiNullsStatement = EstablishTestStatement(CodeGenerationSupporter.AnsiNulls, false);
private static readonly string AnsiPaddingStatement = EstablishTestStatement(CodeGenerationSupporter.AnsiPadding, true);
private static readonly string AnsiWarningsStatement = EstablishTestStatement(CodeGenerationSupporter.AnsiWarnings, true);
private static readonly string ForcePlanStatement = EstablishTestStatement(CodeGenerationSupporter.ForcePlan, false);
private static readonly string ShowPlanAllStatement = EstablishTestStatement(CodeGenerationSupporter.ShowPlanAll, true);
private static readonly string ShowPlanTextStatement = EstablishTestStatement(CodeGenerationSupporter.ShowPlanText, false);
private static readonly string ShowPlanXmlStatement = EstablishTestStatement(CodeGenerationSupporter.ShowPlanXml, false);
private static readonly string StatisticsIOStatement = EstablishTestStatement(Statistics + " " + CodeGenerationSupporter.IO, true);
private static readonly string StatisticsProfileStatement = EstablishTestStatement(Statistics + " " + CodeGenerationSupporter.Profile, false);
private static readonly string StatisticsTimeStatement = EstablishTestStatement(Statistics + " " + CodeGenerationSupporter.Time, true);
private static readonly string ImplicitTransactionsStatement = EstablishTestStatement(CodeGenerationSupporter.ImplicitTransactions, false);
private static readonly string RemoteProcTransactionsStatement = EstablishTestStatement(CodeGenerationSupporter.RemoteProcTransactions, true);
private static readonly string XactAbortStatement = EstablishTestStatement(CodeGenerationSupporter.XactAbort, false);
private static string EstablishTestStatement(string option, bool isOn)
{
return String.Format("{0} {1} {2}", "SET", option, isOn ? "ON" : "OFF");
}
[TestMethod]
[Priority(0)]
[SqlStudioTestCategory(Category.UnitTest)]
public void TestPredicateStates()
{
ParserTestUtils.ExecuteTestForAllParsers(delegate(TSqlParser parser)
{
AssertPredicateState(parser, QuotedIdentifierStatement, SetOptions.QuotedIdentifier, true);
AssertPredicateState(parser, ConcatNullYieldsNullStatement, SetOptions.ConcatNullYieldsNull, false);
AssertPredicateState(parser, CursorCloseOnCommitStatement, SetOptions.CursorCloseOnCommit, false);
AssertPredicateState(parser, ArithAbortStatement, SetOptions.ArithAbort, true);
AssertPredicateState(parser, ArithIgnoreStatement, SetOptions.ArithIgnore, false);
AssertPredicateState(parser, FmtOnlyStatement, SetOptions.FmtOnly, true);
AssertPredicateState(parser, NoCountStatement, SetOptions.NoCount, false);
AssertPredicateState(parser, NoExecStatement, SetOptions.NoExec, true);
AssertPredicateState(parser, NumericRoundAbortStatement, SetOptions.NumericRoundAbort, false);
AssertPredicateState(parser, ParseOnlyStatement, SetOptions.ParseOnly, true);
AssertPredicateState(parser, AnsiDefaultsStatement, SetOptions.AnsiDefaults, true);
AssertPredicateState(parser, AnsiNullDfltOffStatement, SetOptions.AnsiNullDfltOff, false);
AssertPredicateState(parser, AnsiNullDfltOnStatement, SetOptions.AnsiNullDfltOn, true);
AssertPredicateState(parser, AnsiNullsStatement, SetOptions.AnsiNulls, false);
AssertPredicateState(parser, AnsiPaddingStatement, SetOptions.AnsiPadding, true);
AssertPredicateState(parser, AnsiWarningsStatement, SetOptions.AnsiWarnings, true);
AssertPredicateState(parser, ForcePlanStatement, SetOptions.ForcePlan, false);
AssertPredicateState(parser, ShowPlanAllStatement, SetOptions.ShowPlanAll, true);
AssertPredicateState(parser, ShowPlanTextStatement, SetOptions.ShowPlanText, false);
AssertPredicateState(parser, ShowPlanXmlStatement, SetOptions.ShowPlanXml, false);
AssertSetStatementState(parser, StatisticsIOStatement, SetStatisticsOptions.IO, true);
AssertSetStatementState(parser, StatisticsProfileStatement, SetStatisticsOptions.Profile, false);
AssertSetStatementState(parser, StatisticsTimeStatement, SetStatisticsOptions.Time, true);
AssertPredicateState(parser, ImplicitTransactionsStatement, SetOptions.ImplicitTransactions, false);
AssertPredicateState(parser, XactAbortStatement, SetOptions.XactAbort, false);
}, true);
}
private PredicateSetStatement AssertPredicateState(TSqlParser parser, string strStatement, SetOptions option, bool isOn)
{
TSqlScript script = (TSqlScript)ParserTestUtils.ParseStringNoErrors(parser, strStatement);
TSqlBatch batch = script.Batches[0];
Assert.IsTrue(batch.Statements.Count == 1);
Assert.IsTrue(batch.Statements[0] is PredicateSetStatement);
PredicateSetStatement statement = batch.Statements[0] as PredicateSetStatement;
Assert.IsTrue(statement.Options == option);
Assert.IsTrue(isOn == true ? statement.IsOn : statement.IsOn == false);
return statement;
}
private SetStatisticsStatement AssertSetStatementState(TSqlParser parser, string strStatement, SetStatisticsOptions option, bool isOn)
{
TSqlScript script = (TSqlScript)ParserTestUtils.ParseStringNoErrors(parser, strStatement);
TSqlBatch batch = script.Batches[0];
Assert.IsTrue(batch.Statements.Count == 1);
Assert.IsTrue(batch.Statements[0] is SetStatisticsStatement);
SetStatisticsStatement statement = batch.Statements[0] as SetStatisticsStatement;
Assert.IsTrue(statement.Options == option);
Assert.IsTrue(isOn == true ? statement.IsOn : statement.IsOn == false);
return statement;
}
}
}