[Cleanup] Removed TARGET_JVM
[mono.git] / mcs / class / System.Data / Test / System.Data.SqlTypes / SqlByteTest.cs
1 //
2 // SqlByteTest.cs - NUnit Test Cases for System.Data.SqlTypes.SqlByte
3 //
4 // Authors:
5 //   Ville Palo (vi64pa@koti.soon.fi)
6 //   Martin Willemoes Hansen (mwh@sysrq.dk)
7 //
8 // (C) 2002 Ville Palo
9 // (C) 2003 Martin Willemoes Hansen
10 // 
11
12 //
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 //
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:
22 // 
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 // 
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.
33 //
34
35 using NUnit.Framework;
36 using System;
37 using System.Xml;
38 using System.Data.SqlTypes;
39 using System.Threading;
40 using System.Globalization;
41
42 namespace MonoTests.System.Data.SqlTypes
43 {
44         [TestFixture]
45         public class SqlByteTest
46         {
47                 private const string Error = " does not work correctly";
48
49                 [SetUp]
50                 public void SetUp ()
51                 {
52                         Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
53                 }
54
55                 // Test constructor
56                 [Test]
57                 public void Create()
58                 {
59                         byte b = 29;
60                         SqlByte TestByte = new SqlByte(b);
61                         Assert.AreEqual((byte)29, TestByte.Value, "Constructor 1 does not work correctly");
62                 }
63
64                 // Test public fields
65                 [Test]
66                 public void PublicFields()
67                 {
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);
72                 }
73
74                 // Test properties
75                 [Test]
76                 public void Properties()
77                 {
78
79                         SqlByte TestByte = new SqlByte(54);
80                         SqlByte TestByte2 = new SqlByte(1);
81
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);
85
86                 }
87
88                 // PUBLIC STATIC METHODS
89                 [Test]
90                 public void AddMethod()
91                 {
92
93                         SqlByte TestByte64 = new SqlByte(64);
94                         SqlByte TestByte0 = new SqlByte(0);
95                         SqlByte TestByte164 = new SqlByte(164);
96                         SqlByte TestByte255 = new SqlByte(255);
97
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);
102
103                         try {
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);
108                         }
109
110                 }
111
112                 [Test]
113                 public void BitwiseAndMethod()
114                 {
115
116                         SqlByte TestByte2 = new SqlByte(2);
117                         SqlByte TestByte1 = new SqlByte(1);
118                         SqlByte TestByte62 = new SqlByte(62);
119                         SqlByte TestByte255 = new SqlByte(255);
120
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);
126
127                 }
128
129                 [Test]
130                 public void BitwiseOrMethod()
131                 {
132
133                         SqlByte TestByte2 = new SqlByte(2);
134                         SqlByte TestByte1 = new SqlByte(1);
135                         SqlByte TestByte62 = new SqlByte(62);
136                         SqlByte TestByte255 = new SqlByte(255);
137
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);
143
144                 }
145
146                 [Test]
147                 public void CompareTo()
148                 {
149
150                         SqlByte TestByte13 = new SqlByte(13);
151                         SqlByte TestByte10 = new SqlByte(10);
152                         SqlByte TestByte10II = new SqlByte(10);
153
154                         SqlString TestString = new SqlString("This is a test");
155                         
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);
159                         
160                         try {
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);
165                         }
166                         
167                 }
168
169                 [Test]
170                 public void DivideMethod()
171                 {
172
173                         SqlByte TestByte13 = new SqlByte(13);
174                         SqlByte TestByte0 = new SqlByte(0);
175
176                         SqlByte TestByte2 = new SqlByte(2);
177                         SqlByte TestByte180 = new SqlByte(180);
178                         SqlByte TestByte3 = new SqlByte(3);
179
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);
185
186                         try {
187                                 SqlByte.Divide(TestByte13, TestByte0);
188                                 Assert.Fail ("Divide method 6" + Error);
189                         } catch(Exception e) {
190                                 Assert.AreEqual(typeof(DivideByZeroException), e.GetType(), "DivideByZeroException");
191
192                         }
193
194                 }
195
196                 [Test]
197                 public void EqualsMethod()
198                 {
199
200                         SqlByte TestByte0 = new SqlByte(0);
201                         SqlByte TestByte158 = new SqlByte(158);
202                         SqlByte TestByte180 = new SqlByte(180);
203                         SqlByte TestByte180II = new SqlByte(180);
204
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);
209
210                 }
211
212                 [Test]
213                 public void StaticEqualsMethod()
214                 {
215
216                         SqlByte TestByte34 = new SqlByte(34);
217                         SqlByte TestByte34II = new SqlByte(34);
218                         SqlByte TestByte15 = new SqlByte(15);
219                         
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);
223
224                 }
225
226                 [Test]
227                 public void GetHashCodeTest()
228                 {
229
230                         SqlByte TestByte15 = new SqlByte(15);
231                         SqlByte TestByte216 = new SqlByte(216);
232                         
233                         Assert.AreEqual(15, TestByte15.GetHashCode(), "GetHashCode method 1" + Error);
234                         Assert.AreEqual(216, TestByte216.GetHashCode(), "GetHashCode method 2" + Error);
235
236                 }
237
238                 [Test]
239                 public void GetTypeTest()
240                 {
241
242                         SqlByte TestByte = new SqlByte(84);
243
244                         Assert.AreEqual("System.Data.SqlTypes.SqlByte", TestByte.GetType().ToString(), "GetType method" + Error);
245                         
246                 }
247
248                 [Test]
249                 public void GreaterThan()
250                 {
251
252                         SqlByte TestByte10 = new SqlByte(10);
253                         SqlByte TestByte10II = new SqlByte(10);
254                         SqlByte TestByte110 = new SqlByte(110);
255
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);
259
260                 }
261
262                 [Test]
263                 public void GreaterThanOrEqual()
264                 {
265
266                         SqlByte TestByte10 = new SqlByte(10);
267                         SqlByte TestByte10II = new SqlByte(10);
268                         SqlByte TestByte110 = new SqlByte(110);
269
270                         Assert.IsTrue (!SqlByte.GreaterThanOrEqual(TestByte10, TestByte110).Value, "GreaterThanOrEqual method 1" + Error);
271
272                         Assert.IsTrue (SqlByte.GreaterThanOrEqual(TestByte110, TestByte10).Value, "GreaterThanOrEqual method 2" + Error);
273
274                         Assert.IsTrue (SqlByte.GreaterThanOrEqual(TestByte10II, TestByte10).Value, "GreaterThanOrEqual method 3" + Error);
275
276                 }
277
278                 [Test]
279                 public void LessThan()
280                 {
281
282                         SqlByte TestByte10 = new SqlByte(10);
283                         SqlByte TestByte10II = new SqlByte(10);
284                         SqlByte TestByte110 = new SqlByte(110);
285
286                         Assert.IsTrue (SqlByte.LessThan(TestByte10, TestByte110).Value, "LessThan method 1" + Error);
287
288                         Assert.IsTrue (!SqlByte.LessThan(TestByte110, TestByte10).Value, "LessThan method 2" + Error);
289
290                         Assert.IsTrue (!SqlByte.LessThan(TestByte10II, TestByte10).Value, "LessThan method 3" + Error);
291
292                 }
293
294                 [Test]
295                 public void LessThanOrEqual()
296                 {
297
298                         SqlByte TestByte10 = new SqlByte(10);
299                         SqlByte TestByte10II = new SqlByte(10);
300                         SqlByte TestByte110 = new SqlByte(110);
301
302                         Assert.IsTrue (SqlByte.LessThanOrEqual(TestByte10, TestByte110).Value, "LessThanOrEqual method 1" + Error);
303
304                         Assert.IsTrue (!SqlByte.LessThanOrEqual(TestByte110, TestByte10).Value, "LessThanOrEqual method 2" + Error);
305
306                         Assert.IsTrue (SqlByte.LessThanOrEqual(TestByte10II, TestByte10).Value, "LessThanOrEqual method 3" + Error);
307
308                         Assert.IsTrue (SqlByte.LessThanOrEqual(TestByte10II, SqlByte.Null).IsNull, "LessThanOrEqual method 4" + Error);
309                 }
310
311                 [Test]
312                 public void Mod()
313                 {
314
315                         SqlByte TestByte132 = new SqlByte(132);
316                         SqlByte TestByte10 = new SqlByte(10);
317                         SqlByte TestByte200 = new SqlByte(200);
318
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);
323
324                 }
325
326                 [Test]
327                 public void Multiply()
328                 {
329
330                         SqlByte TestByte12 = new SqlByte (12);
331                         SqlByte TestByte2 = new SqlByte (2);
332                         SqlByte TestByte128 = new SqlByte (128);
333
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);
336                         
337                         try {
338                                 SqlByte.Multiply(TestByte128, TestByte2);
339                                 Assert.Fail ("Multiply method 3");
340                         } catch(Exception e) {
341
342                                 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException" + Error);
343                         }
344
345                 }
346
347                 [Test]
348                 public void NotEquals()
349                 {
350                         SqlByte TestByte12 = new SqlByte(12);
351                         SqlByte TestByte128 = new SqlByte(128);
352                         SqlByte TestByte128II = new SqlByte(128);
353
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);
359
360                 }
361
362                 [Test]
363                 public void OnesComplement()
364                 {
365
366                         SqlByte TestByte12 = new SqlByte(12);
367                         SqlByte TestByte128 = new SqlByte(128);
368
369                         Assert.AreEqual((SqlByte)243, SqlByte.OnesComplement(TestByte12), "OnesComplement method 1" + Error);
370                         Assert.AreEqual((SqlByte)127, SqlByte.OnesComplement(TestByte128), "OnesComplement method 2" + Error);
371
372                 }
373
374                 [Test]
375                 public void Parse()
376                 {
377                         try {
378                                 SqlByte.Parse(null);
379                                 Assert.Fail("Parse method 2" + Error);
380                         }
381                         catch (Exception e) {
382                                 Assert.AreEqual(typeof(ArgumentNullException), e.GetType(), "Parse method 3" + Error);
383                         }
384
385                         try {
386                                 SqlByte.Parse("not-a-number");
387                                 Assert.Fail("Parse method 4" + Error);
388                         }
389                         catch (Exception e) {
390                                 Assert.AreEqual(typeof(FormatException), e.GetType(), "Parse method 5" + Error);
391                         }
392
393                         try {
394                                 int OverInt = (int)SqlByte.MaxValue + 1;
395                                 SqlByte.Parse(OverInt.ToString());
396                                 Assert.Fail("Parse method 6" + Error);
397                         }
398                         catch (Exception e) {
399                                 Assert.AreEqual(typeof(OverflowException), e.GetType(), "Parse method 7" + Error);
400                         }
401
402                         Assert.AreEqual((byte)150, SqlByte.Parse("150").Value, "Parse method 8" + Error);
403
404                 }
405
406                 [Test]
407                 public void Subtract()
408                 {
409
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);
413
414                         try {
415                                 SqlByte.Subtract(TestByte12, TestByte128);
416                         } catch(Exception e) {
417
418                                 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException");
419                         }
420
421                 }
422
423                 [Test]
424                 public void ToSqlBoolean()
425                 {
426
427                         SqlByte TestByte12 = new SqlByte(12);
428                         SqlByte TestByte0 = new SqlByte(0);
429                         SqlByte TestByteNull = SqlByte.Null;
430
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);
434                 }
435
436                 [Test]
437                 public void ToSqlDecimal()
438                 {
439                         SqlByte TestByte12 = new SqlByte(12);
440                         SqlByte TestByte0 = new SqlByte(0);
441                         SqlByte TestByte228 = new SqlByte(228);
442
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);
446                         
447                 }
448
449                 [Test]
450                 public void ToSqlDouble()
451                 {
452                         SqlByte TestByte12 = new SqlByte(12);
453                         SqlByte TestByte0 = new SqlByte(0);
454                         SqlByte TestByte228 = new SqlByte(228);
455
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);
459
460                 }
461
462                 [Test]
463                 public void ToSqlInt16()
464                 {
465
466                         SqlByte TestByte12 = new SqlByte(12);
467                         SqlByte TestByte0 = new SqlByte(0);
468                         SqlByte TestByte228 = new SqlByte(228);
469
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);
473                 }
474
475                 [Test]
476                 public void ToSqlInt32()
477                 {
478
479                         SqlByte TestByte12 = new SqlByte(12);
480                         SqlByte TestByte0 = new SqlByte(0);
481                         SqlByte TestByte228 = new SqlByte(228);
482                         
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);
486
487                 }
488
489                 [Test]
490                 public void ToSqlInt64()
491                 {
492                         SqlByte TestByte12 = new SqlByte(12);
493                         SqlByte TestByte0 = new SqlByte(0);
494                         SqlByte TestByte228 = new SqlByte(228);
495
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);
499
500                 }
501
502                 [Test]
503                 public void ToSqlMoney()
504                 {
505
506                         SqlByte TestByte12 = new SqlByte(12);
507                         SqlByte TestByte0 = new SqlByte(0);
508                         SqlByte TestByte228 = new SqlByte(228);
509
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);
513                 }
514
515                 [Test]
516                 public void ToSqlSingle()
517                 {
518             
519                         SqlByte TestByte12 = new SqlByte(12);
520                         SqlByte TestByte0 = new SqlByte(0);
521                         SqlByte TestByte228 = new SqlByte(228);
522
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);
526
527                 }
528
529                 [Test]
530                 public void ToSqlString()
531                 {
532
533                         SqlByte TestByte12 = new SqlByte(12);
534                         SqlByte TestByte0 = new SqlByte(0);
535                         SqlByte TestByte228 = new SqlByte(228);
536
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);
540
541                 }
542
543                 [Test]
544                 public void ToStringTest()
545                 {
546
547                         SqlByte TestByte12 = new SqlByte(12);
548                         SqlByte TestByte0 = new SqlByte(0);
549                         SqlByte TestByte228 = new SqlByte(228);
550                         
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);
554                 }
555
556                 [Test]
557                 public void TestXor()
558                 {
559
560                         SqlByte TestByte14 = new SqlByte(14);
561                         SqlByte TestByte58 = new SqlByte(58);
562                         SqlByte TestByte130 = new SqlByte(130);
563
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);
567
568                 }
569
570                 // OPERATORS
571                 
572                 [Test]
573                 public void AdditionOperator()
574                 {
575
576                         SqlByte TestByte24 = new SqlByte(24);
577                         SqlByte TestByte64 = new SqlByte(64);
578                         SqlByte TestByte255 = new SqlByte(255);
579
580                         Assert.AreEqual((SqlByte)88,TestByte24 + TestByte64, "Addition operator" + Error);
581
582                         try {
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);
587                         }
588                         
589                 }
590
591                 [Test]
592                 public void BitwiseAndOperator()
593                 {
594
595                         SqlByte TestByte2 = new SqlByte(2);
596                         SqlByte TestByte4 = new SqlByte(4);
597                         SqlByte TestByte255 = new SqlByte(255);
598
599                         Assert.AreEqual((SqlByte)0,TestByte2 & TestByte4, "Bitwise and operator 1" + Error);
600                         Assert.AreEqual((SqlByte)2, TestByte2 & TestByte255, "Bitwise and operaror 2" + Error);
601                 }
602
603                 [Test]
604                 public void BitwiseOrOperator()
605                 {
606
607                         SqlByte TestByte2 = new SqlByte(2);
608                         SqlByte TestByte4 = new SqlByte(4);
609                         SqlByte TestByte255 = new SqlByte(255);
610
611                         Assert.AreEqual((SqlByte)6,TestByte2 | TestByte4, "Bitwise or operator 1" + Error);
612                         Assert.AreEqual((SqlByte)255, TestByte2 | TestByte255, "Bitwise or operaror 2" + Error);
613                 }
614
615                 [Test]
616                 public void DivisionOperator()
617                 {
618
619                         SqlByte TestByte2 = new SqlByte(2);
620                         SqlByte TestByte4 = new SqlByte(4);
621                         SqlByte TestByte255 = new SqlByte(255);
622                         SqlByte TestByte0 = new SqlByte(0);
623
624                         Assert.AreEqual((SqlByte)2,TestByte4 / TestByte2, "Division operator 1" + Error);
625                         Assert.AreEqual((SqlByte)127, TestByte255 / TestByte2, "Division operaror 2" + Error);
626
627                         try {
628                                 TestByte2 = TestByte255 / TestByte0;
629                                 Assert.Fail("Division operator 3" + Error);
630                         } catch (Exception e) {
631                                 Assert.AreEqual(typeof(DivideByZeroException), e.GetType(), "DivideByZeroException");
632                         }
633
634                 }
635
636                 [Test]
637                 public void EqualityOperator()
638                 {
639
640                         SqlByte TestByte15 = new SqlByte(15);
641                         SqlByte TestByte15II = new SqlByte(15);
642                         SqlByte TestByte255 = new SqlByte(255);
643
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);
648
649                 }
650
651                 [Test]
652                 public void ExclusiveOrOperator()
653                 {
654
655                         SqlByte TestByte15 = new SqlByte(15);
656                         SqlByte TestByte10 = new SqlByte(10);
657                         SqlByte TestByte255 = new SqlByte(255);
658
659                         Assert.AreEqual((SqlByte)5, (TestByte15 ^ TestByte10), "Exclusive or operator 1" + Error);
660                         Assert.AreEqual((SqlByte)240, (TestByte15 ^ TestByte255), "Exclusive or operator 2" + Error);
661                 }
662
663                 [Test]
664                 public void ThanOrEqualOperators()
665                 {
666
667                         SqlByte TestByte165 = new SqlByte(165);
668                         SqlByte TestByte100 = new SqlByte(100);
669                         SqlByte TestByte100II = new SqlByte(100);
670                         SqlByte TestByte255 = new SqlByte(255);
671
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);
678
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);
685                 }
686
687                 [Test]
688                 public void MultiplicationOperator()
689                 {
690
691                         SqlByte TestByte4 = new SqlByte(4);
692                         SqlByte TestByte12 = new SqlByte(12);
693                         SqlByte TestByte128 = new SqlByte(128);
694
695                         Assert.AreEqual((SqlByte)48, TestByte4 * TestByte12, "Multiplication operator 1" + Error);
696                         try {
697                                 SqlByte test = (TestByte128 * TestByte4);
698                                 Assert.Fail("Multiplication operator 2" + Error);
699                         } catch (Exception e) {
700                                 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException");
701                         }
702
703                 }
704
705                 [Test]
706                 public void OnesComplementOperator()
707                 {
708
709                         SqlByte TestByte12 = new SqlByte(12);
710                         SqlByte TestByte128 = new SqlByte(128);
711
712                         Assert.AreEqual((SqlByte)243, ~TestByte12, "OnesComplement operator 1" + Error);
713                         Assert.AreEqual((SqlByte)127, ~TestByte128, "OnesComplement operator 2" + Error);
714
715                 }
716
717                 [Test]
718                 public void SubtractionOperator()
719                 {
720
721                         SqlByte TestByte4 = new SqlByte(4);
722                         SqlByte TestByte12 = new SqlByte(12);
723                         SqlByte TestByte128 = new SqlByte(128);
724
725                         Assert.AreEqual((SqlByte)8, TestByte12 - TestByte4, "Subtraction operator 1" + Error);
726                         try {
727                                 
728                                 SqlByte test = TestByte4 - TestByte128;
729                                 Assert.Fail("Sybtraction operator 2" + Error);
730
731                         } catch (Exception e) {
732
733                                 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException");
734                         }
735
736                 }
737
738                 [Test]
739                 public void SqlBooleanToSqlByte()
740                 {
741                         SqlBoolean TestBoolean = new SqlBoolean(true);
742                         SqlByte TestByte;
743
744                         TestByte = (SqlByte)TestBoolean;
745                         
746                         Assert.AreEqual((byte)1, TestByte.Value, "SqlBooleanToSqlByte op" + Error);
747                 }
748
749                 [Test]
750                 public void SqlByteToByte()
751                 {
752                         SqlByte TestByte = new SqlByte(12);
753                         byte test = (byte)TestByte;
754                         Assert.AreEqual((byte)12, test, "SqlByteToByte" + Error);
755                 }
756
757                 [Test]
758                 public void SqlDecimalToSqlByte()
759                 {
760                         SqlDecimal TestDecimal64 = new SqlDecimal(64);
761                         SqlDecimal TestDecimal900 = new SqlDecimal(900);
762
763                         Assert.AreEqual((byte)64, ((SqlByte)TestDecimal64).Value, "SqlDecimalToByte" + Error);
764
765                         try {
766                                 SqlByte test = (SqlByte)TestDecimal900;
767                                 Assert.Fail("SqlDecimalToByte 2" + Error);
768                         } catch (Exception e) {
769
770                                 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException");
771                         }
772
773                 }
774
775                 [Test]
776                 public void SqlDoubleToSqlByte()
777                 {
778                         SqlDouble TestDouble64 = new SqlDouble(64);
779                         SqlDouble TestDouble900 = new SqlDouble(900);
780
781                         Assert.AreEqual((byte)64, ((SqlByte)TestDouble64).Value, "SqlDecimalToByte" + Error);
782
783                         try {
784                                 SqlByte test = (SqlByte)TestDouble900;
785                                 Assert.Fail("SqlDoubleToByte 2" + Error);
786                         } catch (Exception e) {
787
788                                 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException");
789                         }
790
791                 }
792
793                 [Test]
794                 public void SqlInt16ToSqlByte()
795                 {
796                         SqlInt16 TestInt1664 = new SqlInt16(64);
797                         SqlInt16 TestInt16900 = new SqlInt16(900);
798                         
799                         Assert.AreEqual((byte)64, ((SqlByte)TestInt1664).Value, "SqlInt16ToByte" + Error);
800
801                         try {
802                                 SqlByte test = (SqlByte)TestInt16900;
803                                 Assert.Fail("SqlInt16ToByte 2" + Error);
804                         } catch (Exception e) {
805
806                                 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException");
807                         }
808
809                 }
810
811                 [Test]
812                 public void SqlInt32ToSqlByte()
813                 {
814                         SqlInt32 TestInt3264 = new SqlInt32(64);
815                         SqlInt32 TestInt32900 = new SqlInt32(900);
816
817                         Assert.AreEqual((byte)64, ((SqlByte)TestInt3264).Value, "SqlInt32ToByte" + Error);
818
819                         try {
820                                 SqlByte test = (SqlByte)TestInt32900;
821                                 Assert.Fail("SqlInt32ToByte 2" + Error);
822                         } catch (Exception e) {
823
824                                 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException");
825                         }
826
827                 }
828
829                 [Test]
830                 public void SqlInt64ToSqlByte()
831                 {
832                         SqlInt64 TestInt6464 = new SqlInt64(64);
833                         SqlInt64 TestInt64900 = new SqlInt64(900);
834
835                         Assert.AreEqual((byte)64, ((SqlByte)TestInt6464).Value, "SqlInt64ToByte" + Error);
836
837                         try {
838                                 SqlByte test = (SqlByte)TestInt64900;
839                                 Assert.Fail("SqlInt64ToByte 2" + Error);
840                         } catch (Exception e) {
841
842                                 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException");
843                         }
844
845                 }
846
847                 [Test]
848                 public void SqlMoneyToSqlByte()
849                 {
850                         SqlMoney TestMoney64 = new SqlMoney(64);
851                         SqlMoney TestMoney900 = new SqlMoney(900);
852
853                         Assert.AreEqual((byte)64, ((SqlByte)TestMoney64).Value, "SqlMoneyToByte" + Error);
854
855                         try {
856                                 SqlByte test = (SqlByte)TestMoney900;
857                                 Assert.Fail("SqlMoneyToByte 2" + Error);
858                         } catch (Exception e) {
859
860                                 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException");
861                         }
862
863                 }
864
865                 [Test]
866                 public void SqlSingleToSqlByte()
867                 {
868                         SqlSingle TestSingle64 = new SqlSingle(64);
869                         SqlSingle TestSingle900 = new SqlSingle(900);
870
871                         Assert.AreEqual((byte)64, ((SqlByte)TestSingle64).Value, "SqlSingleToByte" + Error);
872
873                         try {
874                                 SqlByte test = (SqlByte)TestSingle900;
875                                 Assert.Fail("SqlSingleToByte 2" + Error);
876                         } catch (Exception e) {
877
878                                 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException");
879                         }
880
881                 }
882
883                 [Test]
884                 public void SqlStringToSqlByte()
885                 {
886                         SqlString TestString = new SqlString("Test string");
887                         SqlString TestString100 = new SqlString("100");
888                         SqlString TestString1000 = new SqlString("1000");
889
890                         Assert.AreEqual ((byte)100, ((SqlByte)TestString100).Value, "SqlStringToByte 1" + Error);
891
892                         try {
893                                 SqlByte test = (SqlByte)TestString1000;
894                         } catch(Exception e) {
895
896                                 Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException");
897                         }
898
899                         try {
900                                 SqlByte test = (SqlByte)TestString;
901                                 Assert.Fail("SqlStringToByte 2" + Error);
902                                 
903                         } catch(Exception e) {
904                                 Assert.AreEqual(typeof(FormatException), e.GetType(), "FormatException");
905                         }
906                 }
907
908                 [Test]
909                 public void ByteToSqlByte()
910                 {
911                         byte TestByte = 14;
912                         Assert.AreEqual ((byte)14, ((SqlByte)TestByte).Value, "ByteToSqlByte" + Error);
913                 }
914 #if NET_2_0
915                 [Test]
916                 public void GetXsdTypeTest ()
917                 {
918                         XmlQualifiedName qualifiedName = SqlByte.GetXsdType (null);
919                         NUnit.Framework.Assert.AreEqual ("unsignedByte", qualifiedName.Name, "#A01");
920                 }
921 #endif
922         }
923 }
924