DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
CastTest.cs
Go to the documentation of this file.
1 using System;
2 
3 using Deveel.Data.Sql;
4 using Deveel.Data.Types;
5 
6 using NUnit.Framework;
7 
8 namespace Deveel.Data {
9  [TestFixture]
10  public class CastTest {
11  [TestCase("1980-10-06")]
12  [TestCase("2001 11 22")]
13  public void DateCast(object data) {
14  TObject obj = TObject.CreateAndCastFromObject(TType.GetDateType(SqlType.Date), data);
15  Assert.IsNotNull(obj);
16  Assert.AreEqual(obj.TType.SqlType, SqlType.Date);
17  }
18 
19  [TestCase("22:58:10.578")]
20  [TestCase("15:27:32")]
21  [TestCase("14:08:35 +2")]
22  [TestCase("19:02:11.478 +12")]
23  // TODO: Test against ticks
24  public void TimeCast(object data) {
25  TObject obj = TObject.CreateAndCastFromObject(TType.GetDateType(SqlType.Time), data);
26  Assert.IsNotNull(obj);
27  Assert.AreEqual(obj.TType.SqlType, SqlType.Time);
28  }
29 
30  [TestCase("1957-05-12T22:41:36.735 +5")]
31  [TestCase("2015-03-18T14:35:01.447")]
32  [TestCase("1478-01-01T17:10:05")]
33  [TestCase("1980-04-06 03:12:00")]
34  [TestCase("1957-12-01 07:18:14.556 +11")]
35  public void TimeStampCast(string data) {
36  TObject obj = TObject.CreateAndCastFromObject(TType.GetDateType(SqlType.TimeStamp), data);
37  Assert.IsNotNull(obj);
38  Assert.AreEqual(obj.TType.SqlType, SqlType.TimeStamp);
39  }
40 
41  [TestCase("true", true)]
42  [TestCase("false", false)]
43  [TestCase("0", false)]
44  [TestCase("1", true)]
45  [TestCase("True", true)]
46  public void CastToBoolean(object data, bool expected) {
47  TObject obj = TObject.CreateAndCastFromObject(TType.GetBooleanType(SqlType.Boolean), data);
48  Assert.IsNotNull(obj);
49  Assert.AreEqual(obj.TType.SqlType, SqlType.Boolean);
50  Assert.AreEqual(expected, obj.Object);
51  }
52  }
53 }
void TimeCast(object data)
Definition: CastTest.cs:24
void DateCast(object data)
Definition: CastTest.cs:13
void TimeStampCast(string data)
Definition: CastTest.cs:35
Defines the properties of a specific SQL Type and handles the values compatible.
Definition: SqlType.cs:33
void CastToBoolean(object data, bool expected)
Definition: CastTest.cs:46