DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
SystemFunctionTests.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 
17 using Deveel.Data;
18 using Deveel.Data.Sql;
20 using Deveel.Data.Sql.Objects;
21 using Deveel.Data.Types;
22 
23 using NUnit.Framework;
24 
25 namespace Deveel.Data.Routines {
26  [TestFixture]
28  private DataObject InvokeFunction(string name) {
29  return Query.InvokeSystemFunction(name);
30  }
31 
32  private DataObject InvokeFunction(string name, DataObject arg) {
34  }
35 
36  [Test]
38  IFunction function = null;
39  Assert.DoesNotThrow(() => function = Query.ResolveFunction(new ObjectName("user")));
40  Assert.IsNotNull(function);
41  Assert.AreEqual(SystemSchema.Name, function.FullName.ParentName);
42  Assert.AreEqual("user", function.FullName.Name);
43  }
44 
45  [Test]
47  IFunction function = null;
48  Assert.DoesNotThrow(() => function = Query.ResolveFunction(ObjectName.Parse("SYSTEM.user")));
49  Assert.IsNotNull(function);
50  Assert.AreEqual(SystemSchema.Name, function.FullName.ParentName);
51  Assert.AreEqual("user", function.FullName.Name);
52  }
53 
54  [Test]
55  public void InvokeUserFunction() {
56  DataObject result = null;
57  Assert.DoesNotThrow(() => result = InvokeFunction("user"));
58  Assert.IsNotNull(result);
59  Assert.AreEqual(AdminUserName, result.Value.ToString());
60  }
61 
62  [Test]
63  public void InvokeIntegerToString() {
64  var value = DataObject.Integer(455366);
65  DataObject result = null;
66  Assert.DoesNotThrow(() => result = InvokeFunction("TOSTRING", value));
67  Assert.IsNotNull(result);
68  Assert.IsInstanceOf<StringType>(result.Type);
69 
70  var stringResult = result.Value.ToString();
71  Assert.AreEqual("455366", stringResult);
72  }
73 
74  [Test]
75  public void InvokeDateToString() {
76  var value = DataObject.Date(new SqlDateTime(2015, 02, 10));
77  DataObject result = null;
78  Assert.DoesNotThrow(() => result = InvokeFunction("TOSTRING", value));
79  Assert.IsNotNull(result);
80  Assert.IsInstanceOf<StringType>(result.Type);
81 
82  var stringResult = result.Value.ToString();
83  Assert.AreEqual("2015-02-10", stringResult);
84  }
85 
86  [Test]
88  var value = DataObject.TimeStamp(new SqlDateTime(2015, 02, 10, 17, 15, 01,00));
89  DataObject result = null;
90  Assert.DoesNotThrow(() => result = InvokeFunction("TOSTRING", value));
91  Assert.IsNotNull(result);
92  Assert.IsInstanceOf<StringType>(result.Type);
93 
94  var stringResult = result.Value.ToString();
95  Assert.AreEqual("2015-02-10T17:15:01.000 +00:00", stringResult);
96  }
97  }
98 }
static DataObject Date(DateTimeOffset value)
Definition: DataObject.cs:600
static DataObject Integer(int value)
Definition: DataObject.cs:576
SqlType Type
Gets the SqlType that defines the object properties
Definition: DataObject.cs:78
static ObjectName Parse(string s)
Parses the given string into a ObjectName object.
Definition: ObjectName.cs:139
Defines a routine that is a function, that means it returns a value after its execution.
Definition: IFunction.cs:26
Describes the name of an object within a database.
Definition: ObjectName.cs:44
ISqlObject Value
Gets the underlined value that is handled.
Definition: DataObject.cs:84
DataObject InvokeFunction(string name, DataObject arg)
static DataObject InvokeSystemFunction(this IQuery query, string functionName, params SqlExpression[] args)
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
Definition: DataObject.cs:35
static DataObject TimeStamp(SqlDateTime value)
Definition: DataObject.cs:610
Provides utilities and properties for handling the SYSTEN schema of a database.
Definition: SystemSchema.cs:37
static IFunction ResolveFunction(this IQuery query, Invoke invoke)
Defines the base class for instances that represent SQL expression tree nodes.
const string Name
The name of the system schema that contains tables referring to system information.
static SqlConstantExpression Constant(object value)