DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
SqlBooleanTest.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 NUnit.Framework;
19 
20 namespace Deveel.Data.Sql.Objects {
21  [TestFixture]
22  [Category("SQL Objects")]
23  [Category("Booleans")]
24  public class SqlBooleanTest {
25  [Test]
26  public void CreateFromByte() {
27  var value = new SqlBoolean(1);
28  Assert.IsNotNull(value);
29  Assert.IsFalse(value.IsNull);
30  Assert.AreEqual(true, (bool)value);
31 
32  value = new SqlBoolean(0);
33  Assert.IsNotNull(value);
34  Assert.IsFalse(value.IsNull);
35  Assert.AreEqual(false, (bool)value);
36  }
37 
38  [Test]
39  public void CreateFromBoolean() {
40  var value = new SqlBoolean(true);
41  Assert.IsNotNull(value);
42  Assert.IsFalse(value.IsNull);
43  Assert.AreEqual(true, (bool)value);
44 
45  value = new SqlBoolean(false);
46  Assert.IsNotNull(value);
47  Assert.IsFalse(value.IsNull);
48  Assert.AreEqual(false, (bool)value);
49  }
50 
51  [Test]
52  [Category("Comparison")]
53  public void Compare_Equal() {
54  var value1 = SqlBoolean.True;
55  var value2 = new SqlBoolean(true);
56 
57  Assert.IsFalse(value1.IsNull);
58  Assert.IsFalse(value2.IsNull);
59 
60  Assert.IsTrue(value1.IsComparableTo(value2));
61 
62  int i = -2;
63  Assert.DoesNotThrow(() => i = value1.CompareTo(value2));
64  Assert.AreEqual(0, i);
65  }
66 
67  [Test]
68  [Category("Comparison")]
69  public void Compare_NotEqual() {
70  var value1 = SqlBoolean.False;
71  var value2 = new SqlBoolean(true);
72 
73  Assert.IsFalse(value1.IsNull);
74  Assert.IsFalse(value2.IsNull);
75 
76  Assert.IsTrue(value1.IsComparableTo(value2));
77 
78  int i = -2;
79  Assert.DoesNotThrow(() => i = value1.CompareTo(value2));
80  Assert.AreEqual(-1, i);
81  }
82 
83  [Test]
84  [Category("Comparison")]
85  public void Compare_ToBooleanNull() {
86  var value1 = SqlBoolean.True;
87  var value2 = SqlBoolean.Null;
88 
89  Assert.IsFalse(value1.IsNull);
90  Assert.IsTrue(value2.IsNull);
91 
92  Assert.IsTrue(value1.IsComparableTo(value2));
93 
94  int i = -2;
95  Assert.DoesNotThrow(() => i = value1.CompareTo(value2));
96  Assert.AreEqual(1, i);
97  }
98 
99  [Test]
100  [Category("Comparison")]
101  public void Compare_ToNull() {
102  var value1 = SqlBoolean.True;
103  var value2 = SqlNull.Value;
104 
105  Assert.IsFalse(value1.IsNull);
106  Assert.IsTrue(value2.IsNull);
107 
108  Assert.IsTrue(value1.IsComparableTo(value2));
109 
110  int i = -2;
111  Assert.DoesNotThrow(() => i = value1.CompareTo(value2));
112  Assert.AreEqual(1, i);
113  }
114 
115  [Test]
116  [Category("Comparison")]
117  [Category("Numbers")]
118  public void Compare_ToNumber_InRange() {
119  var value1 = SqlBoolean.True;
120  var value2 = SqlNumber.One;
121 
122  Assert.IsFalse(value1.IsNull);
123  Assert.IsFalse(value2.IsNull);
124 
125  Assert.IsTrue(value1.IsComparableTo(value2));
126 
127  int i = -2;
128  Assert.DoesNotThrow(() => i = value1.CompareTo(value2));
129  Assert.AreEqual(0, i);
130 
131  value2 = SqlNumber.Zero;
132 
133  Assert.IsFalse(value1.IsNull);
134  Assert.IsFalse(value2.IsNull);
135 
136  Assert.IsTrue(value1.IsComparableTo(value2));
137 
138  i = -2;
139  Assert.DoesNotThrow(() => i = value1.CompareTo(value2));
140  Assert.AreEqual(1, i);
141  }
142 
143  [Test]
144  [Category("Comparison")]
145  [Category("Numbers")]
147  var value1 = SqlBoolean.True;
148  var value2 = new SqlNumber(21);
149 
150  Assert.IsFalse(value1.IsNull);
151  Assert.IsFalse(value2.IsNull);
152 
153  Assert.IsFalse(value1.IsComparableTo(value2));
154 
155  int i = -2;
156  Assert.Throws<ArgumentOutOfRangeException>(() => i = value1.CompareTo(value2));
157  Assert.AreEqual(-2, i);
158  }
159 
160  [Test]
161  [Category("Operators")]
162  public void Equality_True() {
163  var value1 = SqlBoolean.True;
164  var value2 = SqlBoolean.True;
165 
166  Assert.IsTrue(value1 == value2);
167  }
168 
169  [Test]
170  [Category("Operators")]
171  public void Equality_False() {
172  var value1 = SqlBoolean.True;
173  var value2 = SqlBoolean.False;
174 
175  Assert.IsTrue(value1 != value2);
176 
177  value2 = SqlBoolean.Null;
178 
179  Assert.IsTrue(value1 != value2);
180  }
181 
182  [Test]
183  [Category("Operators")]
184  public void Equality_ToNull_True() {
185  var value1 = SqlBoolean.Null;
186  var value2 = SqlNull.Value;
187 
188  Assert.IsTrue(value1 == value2);
189  }
190 
191  [Test]
192  [Category("Conversion")]
193  public void Convert_ToString() {
194  var value = SqlBoolean.True;
195  Assert.AreEqual("true", value.ToString());
196 
197  value = SqlBoolean.False;
198  Assert.AreEqual("false", value.ToString());
199 
200  value = SqlBoolean.Null;
201  Assert.AreEqual("NULL", value.ToString());
202  }
203  }
204 }
static readonly SqlNull Value
Definition: SqlNull.cs:24
static readonly SqlNumber Zero
Definition: SqlNumber.cs:29
static readonly SqlNumber One
Definition: SqlNumber.cs:30
Deveel.Data.Sql.Objects.SqlBoolean SqlBoolean
Definition: DataObject.cs:26