DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
TableQueryTests.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 
16 using System;
17 using System.Collections.Generic;
18 using System.Linq;
19 
20 using Deveel.Data;
22 using Deveel.Data.Sql.Tables;
23 using Deveel.Data.Types;
24 
25 using NUnit.Framework;
26 
27 namespace Deveel.Data.Sql {
28  [TestFixture]
29  public class TableQueryTests {
30  private ITable table;
31 
32  private void AddRow(TemporaryTable tmpTable, long id, string name, DateTimeOffset date) {
33  var row = new DataObject[3];
34  row[0] = DataObject.BigInt(id);
35  row[1] = DataObject.String(name);
36  row[2] = DataObject.Date(date);
37  tmpTable.NewRow(row);
38  }
39 
40  [SetUp]
41  public void TestSetUp() {
42  var tableInfo = new TableInfo(new ObjectName("test_table"));
43  tableInfo.AddColumn("id", PrimitiveTypes.Numeric());
44  tableInfo.AddColumn("name", PrimitiveTypes.String());
45  tableInfo.AddColumn("date", PrimitiveTypes.DateTime());
46 
47  var cornerTime = DateTimeOffset.UtcNow;
48 
49  var tmpTable = new TemporaryTable(tableInfo);
50 
51  AddRow(tmpTable, 1, "test1", cornerTime);
52  AddRow(tmpTable, 2, "test2", cornerTime.AddSeconds(2));
53  AddRow(tmpTable, 3, "test3", cornerTime.AddSeconds(5));
54 
55  tmpTable.BuildIndexes();
56 
57  table = tmpTable;
58  }
59 
60  [TestCase(1, 0)]
61  [TestCase(3, 2)]
62  public void SelectRowsWhereStaticId(int id, int expectedRow) {
63  var result = table.SelectRows(0, SqlExpressionType.Equal, DataObject.BigInt(id));
64  var list = result.ToList();
65 
66  Assert.IsNotEmpty(list);
67  Assert.AreEqual(1, list.Count);
68  Assert.AreEqual(expectedRow, list[0]);
69  }
70 
71  [TestCase("test2", 1)]
72  [TestCase("test3", 2)]
73  public void SelectRowsWhereStaticName(string name, int expectedRow) {
74  var result = table.SelectRows(1, SqlExpressionType.Equal, DataObject.VarChar(name));
75  var list = result.ToList();
76 
77  Assert.IsNotEmpty(list);
78  Assert.AreEqual(1, list.Count);
79  Assert.AreEqual(expectedRow, list[0]);
80  }
81  }
82 }
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
static DataObject Date(DateTimeOffset value)
Definition: DataObject.cs:600
void SelectRowsWhereStaticId(int id, int expectedRow)
Defines the contract to access the data contained into a table of a database.
Definition: ITable.cs:40
void SelectRowsWhereStaticName(string name, int expectedRow)
Describes the name of an object within a database.
Definition: ObjectName.cs:44
static DataObject String(string s)
Definition: DataObject.cs:592
SqlExpressionType
All the possible type of SqlExpression supported
static NumericType Numeric()
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
Definition: DataObject.cs:35
static DataObject VarChar(string s)
Definition: DataObject.cs:622
static DataObject BigInt(long value)
Definition: DataObject.cs:580
void AddRow(TemporaryTable tmpTable, long id, string name, DateTimeOffset date)
Defines the metadata properties of a table existing within a database.
Definition: TableInfo.cs:41