DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
BooleanObjectTest.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 
18 using Deveel.Data.Sql.Objects;
19 
20 using NUnit.Framework;
21 
22 namespace Deveel.Data {
23  [TestFixture]
24  public class BooleanObjectTest {
25  [Test]
26  public void Create_True() {
27  var obj = DataObject.Boolean(true);
28  Assert.IsNotNull(obj);
29  Assert.IsInstanceOf<SqlBoolean>(obj.Value);
30  Assert.AreEqual(true, (bool)obj.AsBoolean());
31  }
32 
33  [Test]
34  public void Convert_True_ToNumber() {
35  var obj = DataObject.Boolean(true);
36  Assert.IsNotNull(obj);
37  Assert.IsInstanceOf<SqlBoolean>(obj.Value);
38  Assert.AreEqual(true, (bool)obj.AsBoolean());
39 
40  DataObject numObj = null;
41  Assert.DoesNotThrow(() => numObj = obj.AsInteger());
42  Assert.IsNotNull(numObj);
43  Assert.AreEqual(1, (int) numObj);
44  }
45 
46  [Test]
47  public void Create_False() {
48  var obj = DataObject.Boolean(false);
49  Assert.IsNotNull(obj);
50  Assert.IsInstanceOf<SqlBoolean>(obj.Value);
51  Assert.AreEqual(false, (bool)obj.AsBoolean());
52  }
53 
54  [Test]
55  public void Convert_False_ToNumber() {
56  var obj = DataObject.Boolean(false);
57  Assert.IsNotNull(obj);
58  Assert.IsInstanceOf<SqlBoolean>(obj.Value);
59  Assert.AreEqual(false, (bool)obj.AsBoolean());
60 
61  DataObject numObj = null;
62  Assert.DoesNotThrow(() => numObj = obj.AsInteger());
63  Assert.IsNotNull(numObj);
64  Assert.AreEqual(0, (int) numObj);
65  }
66 
67  [Test]
68  public void Create_Null() {
69  var obj = DataObject.BooleanNull;
70  Assert.IsNotNull(obj);
71  Assert.IsInstanceOf<SqlBoolean>(obj.Value);
72  Assert.IsTrue(obj.IsNull);
73  Assert.AreEqual(SqlNull.Value, obj.AsBoolean().Value);
74  }
75 
76  [Test]
77  public void Convert_Null_ToNumber() {
78  var obj = DataObject.BooleanNull;
79  Assert.IsNotNull(obj);
80  Assert.IsInstanceOf<SqlBoolean>(obj.Value);
81  Assert.AreEqual(SqlNull.Value, obj.AsBoolean().Value);
82 
83  DataObject numObj = null;
84  Assert.DoesNotThrow(() => numObj = obj.AsInteger());
85  Assert.IsNotNull(numObj);
86  Assert.IsTrue(numObj.IsNull);
87  Assert.AreEqual(SqlNull.Value, numObj.Value);
88  }
89  }
90 }
bool IsNull
Gets a value that indicates if this object is materialized as null.
Definition: DataObject.cs:91
ISqlObject Value
Gets the underlined value that is handled.
Definition: DataObject.cs:84
static DataObject Boolean(SqlBoolean value)
Definition: DataObject.cs:544
static readonly SqlNull Value
Definition: SqlNull.cs:24
static readonly DataObject BooleanNull
The null representation of a BOOLEAN object.
Definition: DataObject.cs:49
DataObject AsInteger()
Definition: DataObject.cs:520
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
Definition: DataObject.cs:35