DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
VariableTests.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2014 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 using System;
16 
18 using Deveel.Data.Sql.Variables;
19 using Deveel.Data.Types;
20 
21 using NUnit.Framework;
22 
23 namespace Deveel.Data.Sql {
24  [TestFixture]
26  protected override void OnSetUp(string testName) {
27  if (testName != "DeclareVariable")
28  Query.DeclareVariable("a", PrimitiveTypes.String());
29 
30  base.OnSetUp(testName);
31  }
32 
33  [Test]
34  public void DeclareVariable() {
35  Query.DeclareVariable("a", PrimitiveTypes.String());
36  }
37 
38  [Test]
39  public void GetVariable() {
40  var variable = Query.FindVariable("a");
41 
42  Assert.IsNotNull(variable);
43  Assert.IsInstanceOf<StringType>(variable.Type);
44  }
45 
46  [Test]
47  public void SetExistingVariable() {
48  Query.SetVariable("a", SqlExpression.Constant("test"));
49 
50  var variable = Query.FindVariable("a");
51  Assert.IsNotNull(variable);
52  Assert.IsInstanceOf<StringType>(variable.Type);
53  Assert.IsNotNull(variable.Value);
54  Assert.IsInstanceOf<StringType>(variable.Value.Type);
55  }
56 
57  [Test]
58  public void SetNotExistingVariable() {
59  Query.SetVariable("b", SqlExpression.Constant(23));
60 
61  var variable = Query.FindVariable("b");
62  Assert.IsNotNull(variable);
63  Assert.IsInstanceOf<NumericType>(variable.Type);
64  Assert.IsNotNull(variable.Value);
65  Assert.IsInstanceOf<NumericType>(variable.Value.Type);
66  }
67  }
68 }
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
override void OnSetUp(string testName)
Defines the base class for instances that represent SQL expression tree nodes.
static SqlConstantExpression Constant(object value)