2 // SqlByteTest.cs - NUnit Test Cases for System.Data.SqlTypes.SqlByte
5 // Ville Palo (vi64pa@koti.soon.fi)
6 // Martin Willemoes Hansen (mwh@sysrq.dk)
9 // (C) 2003 Martin Willemoes Hansen
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using NUnit.Framework;
38 using System.Data.SqlTypes;
39 using System.Threading;
40 using System.Globalization;
42 namespace MonoTests.System.Data.SqlTypes
45 public class SqlByteTest
47 private const string Error = " does not work correctly";
52 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
60 SqlByte TestByte = new SqlByte(b);
61 Assert.AreEqual((byte)29, TestByte.Value, "Constructor 1 does not work correctly");
66 public void PublicFields()
68 Assert.AreEqual((SqlByte)255, SqlByte.MaxValue, "MaxValue field" + Error);
69 Assert.AreEqual((SqlByte)0, SqlByte.MinValue, "MinValue field" + Error);
70 Assert.IsTrue (SqlByte.Null.IsNull, "Null field" + Error);
71 Assert.AreEqual((byte)0, SqlByte.Zero.Value, "Zero field" + Error);
76 public void Properties()
79 SqlByte TestByte = new SqlByte(54);
80 SqlByte TestByte2 = new SqlByte(1);
82 Assert.IsTrue (SqlByte.Null.IsNull, "IsNull property" + Error);
83 Assert.AreEqual((byte)54, TestByte.Value, "Value property 1" + Error);
84 Assert.AreEqual((byte)1, TestByte2.Value, "Value property 2" + Error);
88 // PUBLIC STATIC METHODS
90 public void AddMethod()
93 SqlByte TestByte64 = new SqlByte(64);
94 SqlByte TestByte0 = new SqlByte(0);
95 SqlByte TestByte164 = new SqlByte(164);
96 SqlByte TestByte255 = new SqlByte(255);
98 Assert.AreEqual((byte)64, SqlByte.Add(TestByte64, TestByte0).Value, "AddMethod 1" + Error);
99 Assert.AreEqual((byte)228, SqlByte.Add(TestByte64, TestByte164).Value, "AddMethod 2" + Error);
100 Assert.AreEqual((byte)164, SqlByte.Add(TestByte0, TestByte164).Value, "AddMethod 3" + Error);
101 Assert.AreEqual((byte)255, SqlByte.Add(TestByte255, TestByte0).Value, "AddMethod 4" + Error);
104 SqlByte.Add(TestByte255, TestByte64);
105 Assert.Fail ("AddMethod 6" + Error);
106 } catch (Exception e) {
107 Assert.AreEqual(typeof(OverflowException), e.GetType(), "AddMethod 5" + Error);
113 public void BitwiseAndMethod()
116 SqlByte TestByte2 = new SqlByte(2);
117 SqlByte TestByte1 = new SqlByte(1);
118 SqlByte TestByte62 = new SqlByte(62);
119 SqlByte TestByte255 = new SqlByte(255);
121 Assert.AreEqual((byte)0, SqlByte.BitwiseAnd(TestByte2, TestByte1).Value, "BitwiseAnd method 1" + Error);
122 Assert.AreEqual((byte)0, SqlByte.BitwiseAnd(TestByte1, TestByte62).Value, "BitwiseAnd method 2" + Error);
123 Assert.AreEqual((byte)2, SqlByte.BitwiseAnd(TestByte62, TestByte2).Value, "BitwiseAnd method 3" + Error);
124 Assert.AreEqual((byte)1, SqlByte.BitwiseAnd(TestByte1, TestByte255).Value, "BitwiseAnd method 4" + Error);
125 Assert.AreEqual((byte)62, SqlByte.BitwiseAnd(TestByte62, TestByte255).Value, "BitwiseAnd method 5" + Error);
130 public void BitwiseOrMethod()
133 SqlByte TestByte2 = new SqlByte(2);
134 SqlByte TestByte1 = new SqlByte(1);
135 SqlByte TestByte62 = new SqlByte(62);
136 SqlByte TestByte255 = new SqlByte(255);
138 Assert.AreEqual((byte)3, SqlByte.BitwiseOr(TestByte2, TestByte1).Value, "BitwiseOr method 1" + Error);
139 Assert.AreEqual((byte)63, SqlByte.BitwiseOr(TestByte1, TestByte62).Value, "BitwiseOr method 2" + Error);
140 Assert.AreEqual((byte)62, SqlByte.BitwiseOr(TestByte62, TestByte2).Value, "BitwiseOr method 3" + Error);
141 Assert.AreEqual((byte)255, SqlByte.BitwiseOr(TestByte1, TestByte255).Value, "BitwiseOr method 4" + Error);
142 Assert.AreEqual((byte)255, SqlByte.BitwiseOr(TestByte62, TestByte255).Value, "BitwiseOr method 5" + Error);
147 public void CompareTo()
150 SqlByte TestByte13 = new SqlByte(13);
151 SqlByte TestByte10 = new SqlByte(10);
152 SqlByte TestByte10II = new SqlByte(10);
154 SqlString TestString = new SqlString("This is a test");
156 Assert.IsTrue (TestByte13.CompareTo(TestByte10) > 0, "CompareTo method 1" + Error);
157 Assert.IsTrue (TestByte10.CompareTo(TestByte13) < 0, "CompareTo method 2" + Error);
158 Assert.IsTrue (TestByte10.CompareTo(TestByte10II) == 0, "CompareTo method 3" + Error);
161 TestByte13.CompareTo(TestString);
162 Assert.Fail("CompareTo method 4" + Error);
163 } catch(Exception e) {
164 Assert.AreEqual(typeof(ArgumentException), e.GetType(), "Parse method 5" + Error);
170 public void DivideMethod()
173 SqlByte TestByte13 = new SqlByte(13);
174 SqlByte TestByte0 = new SqlByte(0);
176 SqlByte TestByte2 = new SqlByte(2);
177 SqlByte TestByte180 = new SqlByte(180);
178 SqlByte TestByte3 = new SqlByte(3);
180 Assert.AreEqual((byte)6, SqlByte.Divide(TestByte13, TestByte2).Value, "Divide method 1" + Error);
181 Assert.AreEqual((byte)90, SqlByte.Divide(TestByte180, TestByte2).Value, "Divide method 2" + Error);
182 Assert.AreEqual((byte)60, SqlByte.Divide(TestByte180, TestByte3).Value, "Divide method 3" + Error);
183 Assert.AreEqual((byte)0, SqlByte.Divide(TestByte13, TestByte180).Value, "Divide method 4" + Error);
184 Assert.AreEqual((byte)0, SqlByte.Divide(TestByte13, TestByte180).Value, "Divide method 5" + Error);
187 SqlByte.Divide(TestByte13, TestByte0);
188 Assert.Fail ("Divide method 6" + Error);
189 } catch(Exception e) {
190 Assert.AreEqual(typeof(DivideByZeroException), e.GetType(), "DivideByZeroException");
197 public void EqualsMethod()
200 SqlByte TestByte0 = new SqlByte(0);
201 SqlByte TestByte158 = new SqlByte(158);
202 SqlByte TestByte180 = new SqlByte(180);
203 SqlByte TestByte180II = new SqlByte(180);
205 Assert.IsTrue (!TestByte0.Equals(TestByte158), "Equals method 1" + Error);
206 Assert.IsTrue (!TestByte158.Equals(TestByte180), "Equals method 2" + Error);
207 Assert.IsTrue (!TestByte180.Equals(new SqlString("TEST")), "Equals method 3" + Error);
208 Assert.IsTrue (TestByte180.Equals(TestByte180II), "Equals method 4" + Error);
213 public void StaticEqualsMethod()
216 SqlByte TestByte34 = new SqlByte(34);
217 SqlByte TestByte34II = new SqlByte(34);
218 SqlByte TestByte15 = new SqlByte(15);
220 Assert.IsTrue (SqlByte.Equals(TestByte34, TestByte34II).Value, "static Equals method 1" + Error);
221 Assert.IsTrue (!SqlByte.Equals(TestByte34, TestByte15).Value, "static Equals method 2" + Error);
222 Assert.IsTrue (!SqlByte.Equals(TestByte15, TestByte34II).Value, "static Equals method 3" + Error);
227 public void GetHashCodeTest()
230 SqlByte TestByte15 = new SqlByte(15);
231 SqlByte TestByte216 = new SqlByte(216);
233 Assert.AreEqual(15, TestByte15.GetHashCode(), "GetHashCode method 1" + Error);
234 Assert.AreEqual(216, TestByte216.GetHashCode(), "GetHashCode method 2" + Error);
239 public void GetTypeTest()
242 SqlByte TestByte = new SqlByte(84);
244 Assert.AreEqual("System.Data.SqlTypes.SqlByte", TestByte.GetType().ToString(), "GetType method" + Error);
249 public void GreaterThan()
252 SqlByte TestByte10 = new SqlByte(10);
253 SqlByte TestByte10II = new SqlByte(10);
254 SqlByte TestByte110 = new SqlByte(110);
256 Assert.IsTrue (!SqlByte.GreaterThan(TestByte10, TestByte110).Value, "GreaterThan method 1" + Error);
257 Assert.IsTrue (SqlByte.GreaterThan(TestByte110, TestByte10).Value, "GreaterThan method 2" + Error);
258 Assert.IsTrue (!SqlByte.GreaterThan(TestByte10II, TestByte10).Value, "GreaterThan method 3" + Error);
263 public void GreaterThanOrEqual()
266 SqlByte TestByte10 = new SqlByte(10);
267 SqlByte TestByte10II = new SqlByte(10);
268 SqlByte TestByte110 = new SqlByte(110);
270 Assert.IsTrue (!SqlByte.GreaterThanOrEqual(TestByte10, TestByte110).Value, "GreaterThanOrEqual method 1" + Error);
272 Assert.IsTrue (SqlByte.GreaterThanOrEqual(TestByte110, TestByte10).Value, "GreaterThanOrEqual method 2" + Error);
274 Assert.IsTrue (SqlByte.GreaterThanOrEqual(TestByte10II, TestByte10).Value, "GreaterThanOrEqual method 3" + Error);
279 public void LessThan()
282 SqlByte TestByte10 = new SqlByte(10);
283 SqlByte TestByte10II = new SqlByte(10);
284 SqlByte TestByte110 = new SqlByte(110);
286 Assert.IsTrue (SqlByte.LessThan(TestByte10, TestByte110).Value, "LessThan method 1" + Error);
288 Assert.IsTrue (!SqlByte.LessThan(TestByte110, TestByte10).Value, "LessThan method 2" + Error);
290 Assert.IsTrue (!SqlByte.LessThan(TestByte10II, TestByte10).Value, "LessThan method 3" + Error);
295 public void LessThanOrEqual()
298 SqlByte TestByte10 = new SqlByte(10);
299 SqlByte TestByte10II = new SqlByte(10);
300 SqlByte TestByte110 = new SqlByte(110);
302 Assert.IsTrue (SqlByte.LessThanOrEqual(TestByte10, TestByte110).Value, "LessThanOrEqual method 1" + Error);
304 Assert.IsTrue (!SqlByte.LessThanOrEqual(TestByte110, TestByte10).Value, "LessThanOrEqual method 2" + Error);
306 Assert.IsTrue (SqlByte.LessThanOrEqual(TestByte10II, TestByte10).Value, "LessThanOrEqual method 3" + Error);
308 Assert.IsTrue (SqlByte.LessThanOrEqual(TestByte10II, SqlByte.Null).IsNull, "LessThanOrEqual method 4" + Error);
315 SqlByte TestByte132 = new SqlByte(132);
316 SqlByte TestByte10 = new SqlByte(10);
317 SqlByte TestByte200 = new SqlByte(200);
319 Assert.AreEqual((SqlByte)2, SqlByte.Mod(TestByte132, TestByte10), "Mod method 1" + Error);
320 Assert.AreEqual((SqlByte)10, SqlByte.Mod(TestByte10, TestByte200), "Mod method 2" + Error);
321 Assert.AreEqual((SqlByte)0, SqlByte.Mod(TestByte200, TestByte10), "Mod method 3" + Error);
322 Assert.AreEqual((SqlByte)68, SqlByte.Mod(TestByte200, TestByte132), "Mod method 4" + Error);
327 public void Multiply()
330 SqlByte TestByte12 = new SqlByte (12);
331 SqlByte TestByte2 = new SqlByte (2);
332 SqlByte TestByte128 = new SqlByte (128);
334 Assert.AreEqual ((byte)24, SqlByte.Multiply(TestByte12, TestByte2).Value, "Multiply method 1" + Error);
335 Assert.AreEqual ((byte)24, SqlByte.Multiply(TestByte2, TestByte12).Value, "Multiply method 2" + Error);
338 SqlByte.Multiply(TestByte128, TestByte2);
339 Assert.Fail ("Multiply method 3");
340 } catch(Exception e) {
342 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException" + Error);
348 public void NotEquals()
350 SqlByte TestByte12 = new SqlByte(12);
351 SqlByte TestByte128 = new SqlByte(128);
352 SqlByte TestByte128II = new SqlByte(128);
354 Assert.IsTrue (SqlByte.NotEquals(TestByte12, TestByte128).Value, "NotEquals method 1" + Error);
355 Assert.IsTrue (SqlByte.NotEquals(TestByte128, TestByte12).Value, "NotEquals method 2" + Error);
356 Assert.IsTrue (SqlByte.NotEquals(TestByte128II, TestByte12).Value, "NotEquals method 3" + Error);
357 Assert.IsTrue (!SqlByte.NotEquals(TestByte128II, TestByte128).Value, "NotEquals method 4" + Error);
358 Assert.IsTrue (!SqlByte.NotEquals(TestByte128, TestByte128II).Value, "NotEquals method 5" + Error);
363 public void OnesComplement()
366 SqlByte TestByte12 = new SqlByte(12);
367 SqlByte TestByte128 = new SqlByte(128);
369 Assert.AreEqual((SqlByte)243, SqlByte.OnesComplement(TestByte12), "OnesComplement method 1" + Error);
370 Assert.AreEqual((SqlByte)127, SqlByte.OnesComplement(TestByte128), "OnesComplement method 2" + Error);
379 Assert.Fail("Parse method 2" + Error);
381 catch (Exception e) {
382 Assert.AreEqual(typeof(ArgumentNullException), e.GetType(), "Parse method 3" + Error);
386 SqlByte.Parse("not-a-number");
387 Assert.Fail("Parse method 4" + Error);
389 catch (Exception e) {
390 Assert.AreEqual(typeof(FormatException), e.GetType(), "Parse method 5" + Error);
394 int OverInt = (int)SqlByte.MaxValue + 1;
395 SqlByte.Parse(OverInt.ToString());
396 Assert.Fail("Parse method 6" + Error);
398 catch (Exception e) {
399 Assert.AreEqual(typeof(OverflowException), e.GetType(), "Parse method 7" + Error);
402 Assert.AreEqual((byte)150, SqlByte.Parse("150").Value, "Parse method 8" + Error);
407 public void Subtract()
410 SqlByte TestByte12 = new SqlByte(12);
411 SqlByte TestByte128 = new SqlByte(128);
412 Assert.AreEqual((byte)116, SqlByte.Subtract(TestByte128, TestByte12).Value, "Subtract method 1" + Error);
415 SqlByte.Subtract(TestByte12, TestByte128);
416 } catch(Exception e) {
418 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException");
424 public void ToSqlBoolean()
427 SqlByte TestByte12 = new SqlByte(12);
428 SqlByte TestByte0 = new SqlByte(0);
429 SqlByte TestByteNull = SqlByte.Null;
431 Assert.IsTrue (TestByte12.ToSqlBoolean().Value, "ToSqlBoolean method 1" + Error);
432 Assert.IsTrue (!TestByte0.ToSqlBoolean().Value, "ToSqlBoolean method 2" + Error);
433 Assert.IsTrue (TestByteNull.ToSqlBoolean().IsNull, "ToSqlBoolean method 3" + Error);
437 public void ToSqlDecimal()
439 SqlByte TestByte12 = new SqlByte(12);
440 SqlByte TestByte0 = new SqlByte(0);
441 SqlByte TestByte228 = new SqlByte(228);
443 Assert.AreEqual((decimal)12, TestByte12.ToSqlDecimal().Value, "ToSqlDecimal method 1" + Error);
444 Assert.AreEqual((decimal)0, TestByte0.ToSqlDecimal().Value, "ToSqlDecimal method 2" + Error);
445 Assert.AreEqual((decimal)228, TestByte228.ToSqlDecimal().Value, "ToSqlDecimal method 3" + Error);
450 public void ToSqlDouble()
452 SqlByte TestByte12 = new SqlByte(12);
453 SqlByte TestByte0 = new SqlByte(0);
454 SqlByte TestByte228 = new SqlByte(228);
456 Assert.AreEqual((double)12, TestByte12.ToSqlDouble().Value, "ToSqlDouble method 1" + Error);
457 Assert.AreEqual((double)0, TestByte0.ToSqlDouble().Value, "ToSqlDouble method 2" + Error);
458 Assert.AreEqual((double)228, TestByte228.ToSqlDouble().Value, "ToSqlDouble method 3" + Error);
463 public void ToSqlInt16()
466 SqlByte TestByte12 = new SqlByte(12);
467 SqlByte TestByte0 = new SqlByte(0);
468 SqlByte TestByte228 = new SqlByte(228);
470 Assert.AreEqual((short)12, TestByte12.ToSqlInt16().Value, "ToSqInt16 method 1" + Error);
471 Assert.AreEqual((short)0, TestByte0.ToSqlInt16().Value, "ToSqlInt16 method 2" + Error);
472 Assert.AreEqual((short)228, TestByte228.ToSqlInt16().Value, "ToSqlInt16 method 3" + Error);
476 public void ToSqlInt32()
479 SqlByte TestByte12 = new SqlByte(12);
480 SqlByte TestByte0 = new SqlByte(0);
481 SqlByte TestByte228 = new SqlByte(228);
483 Assert.AreEqual((int)12, TestByte12.ToSqlInt32().Value, "ToSqInt32 method 1" + Error);
484 Assert.AreEqual((int)0, TestByte0.ToSqlInt32().Value, "ToSqlInt32 method 2" + Error);
485 Assert.AreEqual((int)228, TestByte228.ToSqlInt32().Value, "ToSqlInt32 method 3" + Error);
490 public void ToSqlInt64()
492 SqlByte TestByte12 = new SqlByte(12);
493 SqlByte TestByte0 = new SqlByte(0);
494 SqlByte TestByte228 = new SqlByte(228);
496 Assert.AreEqual((long)12, TestByte12.ToSqlInt64().Value, "ToSqInt64 method " + Error);
497 Assert.AreEqual((long)0, TestByte0.ToSqlInt64().Value, "ToSqlInt64 method 2" + Error);
498 Assert.AreEqual((long)228, TestByte228.ToSqlInt64().Value, "ToSqlInt64 method 3" + Error);
503 public void ToSqlMoney()
506 SqlByte TestByte12 = new SqlByte(12);
507 SqlByte TestByte0 = new SqlByte(0);
508 SqlByte TestByte228 = new SqlByte(228);
510 Assert.AreEqual(12.0000M, TestByte12.ToSqlMoney().Value, "ToSqMoney method 1" + Error);
511 Assert.AreEqual((decimal)0, TestByte0.ToSqlMoney().Value, "ToSqlMoney method 2" + Error);
512 Assert.AreEqual(228.0000M, TestByte228.ToSqlMoney().Value, "ToSqlMoney method 3" + Error);
516 public void ToSqlSingle()
519 SqlByte TestByte12 = new SqlByte(12);
520 SqlByte TestByte0 = new SqlByte(0);
521 SqlByte TestByte228 = new SqlByte(228);
523 Assert.AreEqual((float)12, TestByte12.ToSqlSingle().Value, "ToSqlSingle method 1" + Error);
524 Assert.AreEqual((float)0, TestByte0.ToSqlSingle().Value, "ToSqlSingle method 2" + Error);
525 Assert.AreEqual((float)228, TestByte228.ToSqlSingle().Value, "ToSqlSingle method 3" + Error);
530 public void ToSqlString()
533 SqlByte TestByte12 = new SqlByte(12);
534 SqlByte TestByte0 = new SqlByte(0);
535 SqlByte TestByte228 = new SqlByte(228);
537 Assert.AreEqual("12", TestByte12.ToSqlString().Value, "ToSqlString method 1" + Error);
538 Assert.AreEqual("0", TestByte0.ToSqlString().Value, "ToSqlString method 2" + Error);
539 Assert.AreEqual("228", TestByte228.ToSqlString().Value, "ToSqlString method 3" + Error);
544 public void ToStringTest()
547 SqlByte TestByte12 = new SqlByte(12);
548 SqlByte TestByte0 = new SqlByte(0);
549 SqlByte TestByte228 = new SqlByte(228);
551 Assert.AreEqual("12", TestByte12.ToString(), "ToString method 1" + Error);
552 Assert.AreEqual("0", TestByte0.ToString(), "ToString method 2" + Error);
553 Assert.AreEqual("228", TestByte228.ToString(), "ToString method 3" + Error);
557 public void TestXor()
560 SqlByte TestByte14 = new SqlByte(14);
561 SqlByte TestByte58 = new SqlByte(58);
562 SqlByte TestByte130 = new SqlByte(130);
564 Assert.AreEqual((byte)52, SqlByte.Xor(TestByte14, TestByte58).Value, "Xor method 1" + Error);
565 Assert.AreEqual((byte)140, SqlByte.Xor(TestByte14, TestByte130).Value, "Xor method 2" + Error);
566 Assert.AreEqual((byte)184, SqlByte.Xor(TestByte58, TestByte130).Value, "Xor method 3" + Error);
573 public void AdditionOperator()
576 SqlByte TestByte24 = new SqlByte(24);
577 SqlByte TestByte64 = new SqlByte(64);
578 SqlByte TestByte255 = new SqlByte(255);
580 Assert.AreEqual((SqlByte)88,TestByte24 + TestByte64, "Addition operator" + Error);
583 SqlByte result = TestByte64 + TestByte255;
584 Assert.Fail("Addition operator 1" + Error);
585 } catch (Exception e) {
586 Assert.AreEqual(typeof(OverflowException), e.GetType(), "Addition operator 2" + Error);
592 public void BitwiseAndOperator()
595 SqlByte TestByte2 = new SqlByte(2);
596 SqlByte TestByte4 = new SqlByte(4);
597 SqlByte TestByte255 = new SqlByte(255);
599 Assert.AreEqual((SqlByte)0,TestByte2 & TestByte4, "Bitwise and operator 1" + Error);
600 Assert.AreEqual((SqlByte)2, TestByte2 & TestByte255, "Bitwise and operaror 2" + Error);
604 public void BitwiseOrOperator()
607 SqlByte TestByte2 = new SqlByte(2);
608 SqlByte TestByte4 = new SqlByte(4);
609 SqlByte TestByte255 = new SqlByte(255);
611 Assert.AreEqual((SqlByte)6,TestByte2 | TestByte4, "Bitwise or operator 1" + Error);
612 Assert.AreEqual((SqlByte)255, TestByte2 | TestByte255, "Bitwise or operaror 2" + Error);
616 public void DivisionOperator()
619 SqlByte TestByte2 = new SqlByte(2);
620 SqlByte TestByte4 = new SqlByte(4);
621 SqlByte TestByte255 = new SqlByte(255);
622 SqlByte TestByte0 = new SqlByte(0);
624 Assert.AreEqual((SqlByte)2,TestByte4 / TestByte2, "Division operator 1" + Error);
625 Assert.AreEqual((SqlByte)127, TestByte255 / TestByte2, "Division operaror 2" + Error);
628 TestByte2 = TestByte255 / TestByte0;
629 Assert.Fail("Division operator 3" + Error);
630 } catch (Exception e) {
631 Assert.AreEqual(typeof(DivideByZeroException), e.GetType(), "DivideByZeroException");
637 public void EqualityOperator()
640 SqlByte TestByte15 = new SqlByte(15);
641 SqlByte TestByte15II = new SqlByte(15);
642 SqlByte TestByte255 = new SqlByte(255);
644 Assert.IsTrue ((TestByte15 == TestByte15II).Value, "== operator" + Error);
645 Assert.IsTrue (!(TestByte15 == TestByte255).Value, "== operator 2" + Error);
646 Assert.IsTrue (!(TestByte15 != TestByte15II).Value, "!= operator" + Error);
647 Assert.IsTrue ((TestByte15 != TestByte255).Value, "!= operator 2" + Error);
652 public void ExclusiveOrOperator()
655 SqlByte TestByte15 = new SqlByte(15);
656 SqlByte TestByte10 = new SqlByte(10);
657 SqlByte TestByte255 = new SqlByte(255);
659 Assert.AreEqual((SqlByte)5, (TestByte15 ^ TestByte10), "Exclusive or operator 1" + Error);
660 Assert.AreEqual((SqlByte)240, (TestByte15 ^ TestByte255), "Exclusive or operator 2" + Error);
664 public void ThanOrEqualOperators()
667 SqlByte TestByte165 = new SqlByte(165);
668 SqlByte TestByte100 = new SqlByte(100);
669 SqlByte TestByte100II = new SqlByte(100);
670 SqlByte TestByte255 = new SqlByte(255);
672 Assert.IsTrue ((TestByte165 > TestByte100).Value, "> operator 1" + Error);
673 Assert.IsTrue (!(TestByte165 > TestByte255).Value, "> operator 2" + Error);
674 Assert.IsTrue (!(TestByte100 > TestByte100II).Value, "> operator 3" + Error);
675 Assert.IsTrue (!(TestByte165 >= TestByte255).Value, ">= operator 1" + Error);
676 Assert.IsTrue ((TestByte255 >= TestByte165).Value, ">= operator 2" + Error);
677 Assert.IsTrue ((TestByte100 >= TestByte100II).Value, ">= operator 3" + Error);
679 Assert.IsTrue (!(TestByte165 < TestByte100).Value, "< operator 1" + Error);
680 Assert.IsTrue ((TestByte165 < TestByte255).Value, "< operator 2" + Error);
681 Assert.IsTrue (!(TestByte100 < TestByte100II).Value, "< operator 3" + Error);
682 Assert.IsTrue ((TestByte165 <= TestByte255).Value, "<= operator 1" + Error);
683 Assert.IsTrue (!(TestByte255 <= TestByte165).Value, "<= operator 2" + Error);
684 Assert.IsTrue ((TestByte100 <= TestByte100II).Value, "<= operator 3" + Error);
688 public void MultiplicationOperator()
691 SqlByte TestByte4 = new SqlByte(4);
692 SqlByte TestByte12 = new SqlByte(12);
693 SqlByte TestByte128 = new SqlByte(128);
695 Assert.AreEqual((SqlByte)48, TestByte4 * TestByte12, "Multiplication operator 1" + Error);
697 SqlByte test = (TestByte128 * TestByte4);
698 Assert.Fail("Multiplication operator 2" + Error);
699 } catch (Exception e) {
700 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException");
706 public void OnesComplementOperator()
709 SqlByte TestByte12 = new SqlByte(12);
710 SqlByte TestByte128 = new SqlByte(128);
712 Assert.AreEqual((SqlByte)243, ~TestByte12, "OnesComplement operator 1" + Error);
713 Assert.AreEqual((SqlByte)127, ~TestByte128, "OnesComplement operator 2" + Error);
718 public void SubtractionOperator()
721 SqlByte TestByte4 = new SqlByte(4);
722 SqlByte TestByte12 = new SqlByte(12);
723 SqlByte TestByte128 = new SqlByte(128);
725 Assert.AreEqual((SqlByte)8, TestByte12 - TestByte4, "Subtraction operator 1" + Error);
728 SqlByte test = TestByte4 - TestByte128;
729 Assert.Fail("Sybtraction operator 2" + Error);
731 } catch (Exception e) {
733 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException");
739 public void SqlBooleanToSqlByte()
741 SqlBoolean TestBoolean = new SqlBoolean(true);
744 TestByte = (SqlByte)TestBoolean;
746 Assert.AreEqual((byte)1, TestByte.Value, "SqlBooleanToSqlByte op" + Error);
750 public void SqlByteToByte()
752 SqlByte TestByte = new SqlByte(12);
753 byte test = (byte)TestByte;
754 Assert.AreEqual((byte)12, test, "SqlByteToByte" + Error);
758 public void SqlDecimalToSqlByte()
760 SqlDecimal TestDecimal64 = new SqlDecimal(64);
761 SqlDecimal TestDecimal900 = new SqlDecimal(900);
763 Assert.AreEqual((byte)64, ((SqlByte)TestDecimal64).Value, "SqlDecimalToByte" + Error);
766 SqlByte test = (SqlByte)TestDecimal900;
767 Assert.Fail("SqlDecimalToByte 2" + Error);
768 } catch (Exception e) {
770 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException");
776 public void SqlDoubleToSqlByte()
778 SqlDouble TestDouble64 = new SqlDouble(64);
779 SqlDouble TestDouble900 = new SqlDouble(900);
781 Assert.AreEqual((byte)64, ((SqlByte)TestDouble64).Value, "SqlDecimalToByte" + Error);
784 SqlByte test = (SqlByte)TestDouble900;
785 Assert.Fail("SqlDoubleToByte 2" + Error);
786 } catch (Exception e) {
788 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException");
794 public void SqlInt16ToSqlByte()
796 SqlInt16 TestInt1664 = new SqlInt16(64);
797 SqlInt16 TestInt16900 = new SqlInt16(900);
799 Assert.AreEqual((byte)64, ((SqlByte)TestInt1664).Value, "SqlInt16ToByte" + Error);
802 SqlByte test = (SqlByte)TestInt16900;
803 Assert.Fail("SqlInt16ToByte 2" + Error);
804 } catch (Exception e) {
806 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException");
812 public void SqlInt32ToSqlByte()
814 SqlInt32 TestInt3264 = new SqlInt32(64);
815 SqlInt32 TestInt32900 = new SqlInt32(900);
817 Assert.AreEqual((byte)64, ((SqlByte)TestInt3264).Value, "SqlInt32ToByte" + Error);
820 SqlByte test = (SqlByte)TestInt32900;
821 Assert.Fail("SqlInt32ToByte 2" + Error);
822 } catch (Exception e) {
824 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException");
830 public void SqlInt64ToSqlByte()
832 SqlInt64 TestInt6464 = new SqlInt64(64);
833 SqlInt64 TestInt64900 = new SqlInt64(900);
835 Assert.AreEqual((byte)64, ((SqlByte)TestInt6464).Value, "SqlInt64ToByte" + Error);
838 SqlByte test = (SqlByte)TestInt64900;
839 Assert.Fail("SqlInt64ToByte 2" + Error);
840 } catch (Exception e) {
842 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException");
848 public void SqlMoneyToSqlByte()
850 SqlMoney TestMoney64 = new SqlMoney(64);
851 SqlMoney TestMoney900 = new SqlMoney(900);
853 Assert.AreEqual((byte)64, ((SqlByte)TestMoney64).Value, "SqlMoneyToByte" + Error);
856 SqlByte test = (SqlByte)TestMoney900;
857 Assert.Fail("SqlMoneyToByte 2" + Error);
858 } catch (Exception e) {
860 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException");
866 public void SqlSingleToSqlByte()
868 SqlSingle TestSingle64 = new SqlSingle(64);
869 SqlSingle TestSingle900 = new SqlSingle(900);
871 Assert.AreEqual((byte)64, ((SqlByte)TestSingle64).Value, "SqlSingleToByte" + Error);
874 SqlByte test = (SqlByte)TestSingle900;
875 Assert.Fail("SqlSingleToByte 2" + Error);
876 } catch (Exception e) {
878 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException");
884 public void SqlStringToSqlByte()
886 SqlString TestString = new SqlString("Test string");
887 SqlString TestString100 = new SqlString("100");
888 SqlString TestString1000 = new SqlString("1000");
890 Assert.AreEqual ((byte)100, ((SqlByte)TestString100).Value, "SqlStringToByte 1" + Error);
893 SqlByte test = (SqlByte)TestString1000;
894 } catch(Exception e) {
896 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException");
900 SqlByte test = (SqlByte)TestString;
901 Assert.Fail("SqlStringToByte 2" + Error);
903 } catch(Exception e) {
904 Assert.AreEqual(typeof(FormatException), e.GetType(), "FormatException");
909 public void ByteToSqlByte()
912 Assert.AreEqual ((byte)14, ((SqlByte)TestByte).Value, "ByteToSqlByte" + Error);
916 public void GetXsdTypeTest ()
918 XmlQualifiedName qualifiedName = SqlByte.GetXsdType (null);
919 NUnit.Framework.Assert.AreEqual ("unsignedByte", qualifiedName.Name, "#A01");