DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
SqlDateTimeTests.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("Date Time")]
24  public class SqlDateTimeTests {
25  [Test]
26  [Category("Day To Second Interval")]
27  public void Add_TimeSpan_NoDays() {
28  var value = new SqlDateTime(2001, 01, 03, 10, 22, 03, 0);
29  var ts = new SqlDayToSecond(0, 2, 03, 0);
30 
31  var result = new SqlDateTime();
32  Assert.DoesNotThrow(() => result = value.Add(ts));
33  Assert.IsFalse(result.IsNull);
34  Assert.AreEqual(2001, result.Year);
35  Assert.AreEqual(01, result.Month);
36  Assert.AreEqual(03, result.Day);
37  Assert.AreEqual(12, result.Hour);
38  Assert.AreEqual(25, result.Minute);
39  }
40 
41  [Test]
42  [Category("Day To Second Interval")]
43  public void Subtract_TimeSpan_NoDays() {
44  var value = new SqlDateTime(2001, 01, 03, 10, 22, 03, 0);
45  var ts = new SqlDayToSecond(0, 2, 03, 0);
46 
47  var result = new SqlDateTime();
48  Assert.DoesNotThrow(() => result = value.Subtract(ts));
49  Assert.IsFalse(result.IsNull);
50  Assert.AreEqual(2001, result.Year);
51  Assert.AreEqual(01, result.Month);
52  Assert.AreEqual(03, result.Day);
53  Assert.AreEqual(8, result.Hour);
54  Assert.AreEqual(19, result.Minute);
55  }
56 
57  [Test]
58  [Category("Year To Month")]
59  public void Add_MonthSpan() {
60  var value = new SqlDateTime(2001, 11, 03, 10, 22, 03, 0);
61  var ms = new SqlYearToMonth(1, 3);
62 
63  var result = new SqlDateTime();
64  Assert.DoesNotThrow(() => result = value.Add(ms));
65  Assert.IsFalse(result.IsNull);
66  Assert.AreEqual(2003, result.Year);
67  Assert.AreEqual(02, result.Month);
68  Assert.AreEqual(10, result.Hour);
69  Assert.AreEqual(22, result.Minute);
70  Assert.AreEqual(03, result.Second);
71  Assert.AreEqual(0, result.Millisecond);
72  }
73 
74  [Test]
75  [Category("Year To Month")]
76  public void Subtract_MonthSpan() {
77  var value = new SqlDateTime(2001, 11, 03, 10, 22, 03, 0);
78  var ms = new SqlYearToMonth(1, 3);
79 
80  var result = new SqlDateTime();
81  Assert.DoesNotThrow(() => result = value.Subtract(ms));
82  Assert.IsFalse(result.IsNull);
83  Assert.AreEqual(2000, result.Year);
84  Assert.AreEqual(08, result.Month);
85  Assert.AreEqual(10, result.Hour);
86  Assert.AreEqual(22, result.Minute);
87  Assert.AreEqual(03, result.Second);
88  Assert.AreEqual(0, result.Millisecond);
89  }
90 
91  [Test]
92  [Category("Operators")]
93  [Category("Day To Second Interval")]
94  public void Operator_Add_TimeSpan() {
95  var value = new SqlDateTime(2001, 01, 03, 10, 22, 03, 0);
96  var ts = new SqlDayToSecond(0, 2, 03, 0);
97 
98  var result = new SqlDateTime();
99  Assert.DoesNotThrow(() => result = value + ts);
100  Assert.IsFalse(result.IsNull);
101  Assert.AreEqual(2001, result.Year);
102  Assert.AreEqual(01, result.Month);
103  Assert.AreEqual(03, result.Day);
104  Assert.AreEqual(12, result.Hour);
105  Assert.AreEqual(25, result.Minute);
106  }
107 
108  [Test]
109  [Category("Day To Second Interval")]
110  [Category("Operators")]
112  var value = new SqlDateTime(2001, 01, 03, 10, 22, 03, 0);
113  var ts = new SqlDayToSecond(0, 2, 03, 0);
114 
115  var result = new SqlDateTime();
116  Assert.DoesNotThrow(() => result = value - ts);
117  Assert.IsFalse(result.IsNull);
118  Assert.AreEqual(2001, result.Year);
119  Assert.AreEqual(01, result.Month);
120  Assert.AreEqual(03, result.Day);
121  Assert.AreEqual(8, result.Hour);
122  Assert.AreEqual(19, result.Minute);
123  }
124 
125  [Test]
126  [Category("Operators")]
127  public void Equality_True() {
128  var value1 = new SqlDateTime(2030, 03, 01, 11, 05, 54, 0);
129  var value2 = new SqlDateTime(2030, 03, 01, 11, 05, 54, 0);
130 
131  Assert.IsTrue(value1 == value2);
132  }
133 
134  [Test]
135  [Category("Operators")]
136  public void Inequality_True() {
137  var value1 = new SqlDateTime(2030, 03, 01, 11, 05, 54, 0);
138  var value2 = new SqlDateTime(2020, 05, 01, 11, 05, 54, 0);
139 
140  Assert.IsTrue(value1 != value2);
141  }
142 
143  [Test]
144  [Category("Operators")]
145  public void Greater_True() {
146  var value1 = new SqlDateTime(2030, 03, 01, 11, 05, 54, 0);
147  var value2 = new SqlDateTime(2020, 05, 01, 11, 05, 54, 0);
148 
149  Assert.IsTrue(value1 > value2);
150  }
151  }
152 }
A month span representation of time.