This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / mcs / class / System.Data / Test / System.Data.SqlTypes / SqlStringTest.cs
1 // SqlStringTest.cs - NUnit Test Cases for System.Data.SqlTypes.SqlString
2 //
3 // Authors:
4 //   Ville Palo (vi64pa@koti.soon.fi)
5 //   Martin Willemoes Hansen (mwh@sysrq.dk)
6 //
7 // (C) 2002 Ville Palo
8 // (C) 2003 Martin Willemoes Hansen
9 // 
10
11 //
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 // 
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 // 
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 //
33
34 using NUnit.Framework;
35 using System;
36 using System.Data.SqlTypes;
37 using System.Globalization;
38 using System.Threading;
39
40 namespace MonoTests.System.Data.SqlTypes
41 {
42         [TestFixture]
43         public class SqlStringTest : Assertion {
44
45                 private SqlString Test1 = null;
46                 private SqlString Test2 = null;
47                 private SqlString Test3 = null;
48
49                 [SetUp]
50                 public void GetReady()
51                 {
52                         Test1 = new SqlString ("First TestString");
53                         Test2 = new SqlString ("This is just a test SqlString");
54                         Test3 = new SqlString ("This is just a test SqlString");
55                         Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-AU");
56                 }
57
58                 // Test constructor
59                 [Test]
60                 public void Create()
61                 {
62
63                         // SqlString (String)
64                         SqlString  TestString = new SqlString ("Test");
65                         AssertEquals ("#A01", "Test", TestString.Value);
66
67                         // SqlString (String, int)
68                         TestString = new SqlString ("Test", 2057);
69                         AssertEquals ("#A02", 2057, TestString.LCID);
70
71                         // SqlString (int, SqlCompareOptions, byte[])
72                         TestString = new SqlString (2057,
73                                                     SqlCompareOptions.BinarySort|SqlCompareOptions.IgnoreCase,
74                                                     new byte [2] {123, 221});
75                         AssertEquals ("#A03", 2057, TestString.CompareInfo.LCID);
76                         
77                         // SqlString(string, int, SqlCompareOptions)
78                         TestString = new SqlString ("Test", 2057, SqlCompareOptions.IgnoreNonSpace);
79                         Assert ("#A04", !TestString.IsNull);
80                         
81                         // SqlString (int, SqlCompareOptions, byte[], bool)
82                         TestString = new SqlString (2057, SqlCompareOptions.BinarySort, new byte [4] {100, 100, 200, 45}, true);
83                         AssertEquals ("#A05", (byte)63, TestString.GetNonUnicodeBytes () [0]);
84                         TestString = new SqlString (2057, SqlCompareOptions.BinarySort, new byte [2] {113, 100}, false);
85                         AssertEquals ("#A06", (String)"qd", TestString.Value);
86                         
87                         // SqlString (int, SqlCompareOptions, byte[], int, int)
88                         TestString = new SqlString (2057, SqlCompareOptions.BinarySort, new byte [2] {113, 100}, 0, 2);
89                         Assert ("#A07", !TestString.IsNull);
90
91                         // SqlString (int, SqlCompareOptions, byte[], int, int, bool)
92                         TestString = new SqlString (2057, SqlCompareOptions.IgnoreCase, new byte [3] {100, 111, 50}, 1, 2, false);
93                         AssertEquals ("#A08", "o2", TestString.Value);
94                         TestString = new SqlString (2057, SqlCompareOptions.IgnoreCase, new byte [3] {123, 111, 222}, 1, 2, true);
95                         Assert ("#A09", !TestString.IsNull);                        
96                 }
97
98                 [Test]
99                 [ExpectedException(typeof (ArgumentOutOfRangeException))]
100                 public void CtorArgumentOutOfRangeException1 ()
101                 {
102                         SqlString TestString = new SqlString (2057, SqlCompareOptions.BinarySort, new byte [2] {113, 100}, 2, 1);
103                 }
104
105                 [Test]
106                 [ExpectedException(typeof (ArgumentOutOfRangeException))]
107                 public void CtorArgumentOutOfRangeException2 ()
108                 {
109                         SqlString TestString = new SqlString (2057, SqlCompareOptions.BinarySort, new byte [2] {113, 100}, 0, 4);
110                 }
111
112                 // Test public fields
113                 [Test]
114                 public void PublicFields()
115                 {
116                         // BinarySort
117                         AssertEquals ("#B01", 32768, SqlString.BinarySort);
118                         
119                         // IgnoreCase
120                         AssertEquals ("#B02", 1, SqlString.IgnoreCase);
121                                       
122                         // IgnoreKanaType
123                         AssertEquals ("#B03", 8, SqlString.IgnoreKanaType);
124
125                         // IgnoreNonSpace
126                         AssertEquals ("#B04", 2, SqlString.IgnoreNonSpace);
127                         
128                         // IgnoreWidth
129                         AssertEquals ("#B05", 16, SqlString.IgnoreWidth);
130                         
131                         // Null
132                         Assert ("#B06", SqlString.Null.IsNull);
133                 }
134
135                 // Test properties
136                 [Test]
137                 public void Properties()
138                 {
139 /* Comment out: This test will succeed only when you're in en-au culture.
140                         // CompareInfo
141                         AssertEquals ("#C01", 3081, Test1.CompareInfo.LCID);
142
143                         // CultureInfo
144                         AssertEquals ("#C02", 3081, Test1.CultureInfo.LCID);             
145
146                         // LCID
147                         AssertEquals ("#C05", 3081, Test1.LCID);                        
148 */   
149                         
150                         // IsNull
151                         Assert ("#C03", !Test1.IsNull);
152                         Assert ("#C04", SqlString.Null.IsNull);
153                                                 
154                         // SqlCompareOptions
155                         AssertEquals ("#C06", "IgnoreCase, IgnoreKanaType, IgnoreWidth", 
156                                       Test1.SqlCompareOptions.ToString ());
157
158                         // Value
159                         AssertEquals ("#C07", "First TestString", Test1.Value);
160
161                 }
162
163                 // PUBLIC METHODS
164
165                 [Test]
166                 [ExpectedException(typeof(ArgumentException))]
167                 public void CompareToArgumentException ()
168                 {
169                         SqlByte Test = new SqlByte (1);
170                         Test1.CompareTo (Test);
171                 }
172
173                 [Test]
174                 [ExpectedException(typeof(SqlTypeException))]
175                 public void CompareToSqlTypeException ()
176                 {
177                         SqlString T1 = new SqlString ("test", 2057, SqlCompareOptions.IgnoreCase);
178                         SqlString T2 = new SqlString ("TEST", 2057, SqlCompareOptions.None);
179                         T1.CompareTo (T2);
180                 }
181
182                 [Test]
183                 public void CompareTo()
184                 {
185                         SqlByte Test = new SqlByte (1);
186
187                         Assert ("#D01", Test1.CompareTo (Test3) < 0);
188                         Assert ("#D02", Test2.CompareTo (Test1) > 0);
189                         Assert ("#D03", Test2.CompareTo (Test3) == 0);
190                         Assert ("#D04", Test3.CompareTo (SqlString.Null) > 0);
191
192                         
193                         SqlString T1 = new SqlString ("test", 2057, SqlCompareOptions.IgnoreCase);
194                         SqlString T2 = new SqlString ("TEST", 2057, SqlCompareOptions.None);
195                                                 
196                         // IgnoreCase
197                         T1 = new SqlString ("test", 2057, SqlCompareOptions.IgnoreCase);
198                         T2 = new SqlString ("TEST", 2057, SqlCompareOptions.IgnoreCase);
199                         Assert ("#D09", T2.CompareTo (T1) == 0);
200                 
201                         T1 = new SqlString ("test", 2057);
202                         T2 = new SqlString ("TEST", 2057);
203                         Assert ("#D10", T2.CompareTo (T1) == 0);
204
205                         T1 = new SqlString ("test", 2057, SqlCompareOptions.None);
206                         T2 = new SqlString ("TEST", 2057, SqlCompareOptions.None);
207                         Assert ("#D11", T2.CompareTo (T1) != 0);
208
209                         // IgnoreNonSpace
210                         T1 = new SqlString ("TEST\xF1", 2057, SqlCompareOptions.IgnoreNonSpace);
211                         T2 = new SqlString ("TESTn", 2057, SqlCompareOptions.IgnoreNonSpace);
212                         Assert ("#D12", T2.CompareTo (T1) == 0);
213                 
214                         T1 = new SqlString ("TESTñ", 2057, SqlCompareOptions.None);
215                         T2 = new SqlString ("TESTn", 2057, SqlCompareOptions.None);
216                         Assert ("#D13", T2.CompareTo (T1) != 0);
217
218                         // BinarySort
219                         T1 = new SqlString ("01_", 2057, SqlCompareOptions.BinarySort);
220                         T2 = new SqlString ("_01", 2057, SqlCompareOptions.BinarySort);
221                         Assert ("#D14", T1.CompareTo (T2) < 0);
222                         
223                         T1 = new SqlString ("01_", 2057, SqlCompareOptions.None);
224                         T2 = new SqlString ("_01", 2057, SqlCompareOptions.None);
225                         Assert ("#D15", T1.CompareTo (T2) > 0);                 
226                 }
227
228                 [Test]
229                 public void EqualsMethods()
230                 {
231                         Assert ("#E01", !Test1.Equals (Test2));
232                         Assert ("#E02", !Test3.Equals (Test1));
233                         Assert ("#E03", !Test2.Equals (new SqlString ("TEST")));
234                         Assert ("#E04", Test2.Equals (Test3));
235
236                         // Static Equals()-method
237                         Assert ("#E05", SqlString.Equals (Test2, Test3).Value);
238                         Assert ("#E06", !SqlString.Equals (Test1, Test2).Value);
239                 }
240
241                 [Test]
242                 public void GetHashCodeTest()
243                 {
244                         // FIXME: Better way to test HashCode
245                         AssertEquals ("#F01", Test1.GetHashCode (), 
246                                       Test1.GetHashCode ());
247                         Assert ("#F02", Test1.GetHashCode () != Test2.GetHashCode ());
248                         Assert ("#F03", Test2.GetHashCode () == Test2.GetHashCode ());
249                 }
250
251                 [Test]
252                 public void GetTypeTest()
253                 {
254                         AssertEquals ("#G01", "System.Data.SqlTypes.SqlString", 
255                                       Test1.GetType ().ToString ());
256                         AssertEquals ("#G02", "System.String", 
257                                       Test1.Value.GetType ().ToString ());
258                 }
259
260                 [Test]
261                 public void Greaters()
262                 {
263
264                         // GreateThan ()
265                         Assert ("#H01", !SqlString.GreaterThan (Test1, Test2).Value);
266                         Assert ("#H02", SqlString.GreaterThan (Test2, Test1).Value);
267                         Assert ("#H03", !SqlString.GreaterThan (Test2, Test3).Value);
268
269                         // GreaterTharOrEqual ()
270                         Assert ("#H04", !SqlString.GreaterThanOrEqual (Test1, Test2).Value);
271                         Assert ("#H05", SqlString.GreaterThanOrEqual (Test2, Test1).Value);
272                         Assert ("#H06", SqlString.GreaterThanOrEqual (Test2, Test3).Value);
273                 }
274
275                 [Test]
276                 public void Lessers()
277                 {
278                         // LessThan()
279                         Assert ("#I01", !SqlString.LessThan (Test2, Test3).Value);
280                         Assert ("#I02", !SqlString.LessThan (Test2, Test1).Value);
281                         Assert ("#I03", SqlString.LessThan (Test1, Test2).Value);
282
283                         // LessThanOrEqual ()
284                         Assert ("#I04", SqlString.LessThanOrEqual (Test1, Test2).Value);
285                         Assert ("#I05", !SqlString.LessThanOrEqual (Test2, Test1).Value);
286                         Assert ("#I06", SqlString.LessThanOrEqual (Test3, Test2).Value);
287                         Assert ("#I07", SqlString.LessThanOrEqual (Test2, SqlString.Null).IsNull);
288                 }
289
290                 [Test]
291                 public void NotEquals()
292                 {
293                         Assert ("#J01", SqlString.NotEquals (Test1, Test2).Value);
294                         Assert ("#J02", SqlString.NotEquals (Test2, Test1).Value);
295                         Assert ("#J03", SqlString.NotEquals (Test3, Test1).Value);
296                         Assert ("#J04", !SqlString.NotEquals (Test2, Test3).Value);
297
298                         Assert ("#J05", SqlString.NotEquals (SqlString.Null, Test3).IsNull);
299                 }
300
301                 [Test]
302                 public void Concat()
303                 {
304                         Test1 = new SqlString ("First TestString");
305                         Test2 = new SqlString ("This is just a test SqlString");
306                         Test3 = new SqlString ("This is just a test SqlString");
307
308                         AssertEquals ("#K01", 
309                               (SqlString)"First TestStringThis is just a test SqlString", 
310                               SqlString.Concat (Test1, Test2));
311
312                         AssertEquals ("#K02", SqlString.Null, 
313                                       SqlString.Concat (Test1, SqlString.Null));
314                 }
315
316                 [Test]
317                 public void Clone()
318                 {
319                         SqlString TestSqlString  = Test1.Clone ();
320                         AssertEquals ("#L01", Test1, TestSqlString);
321                 }
322
323                 [Test]
324                 public void CompareOptionsFromSqlCompareOptions()
325                 {
326                         AssertEquals ("#M01", CompareOptions.IgnoreCase,
327                                     SqlString.CompareOptionsFromSqlCompareOptions (
328                                     SqlCompareOptions.IgnoreCase));
329                         AssertEquals ("#M02", CompareOptions.IgnoreCase,
330                                     SqlString.CompareOptionsFromSqlCompareOptions (
331                                     SqlCompareOptions.IgnoreCase));
332                         try {
333                                 
334                                 CompareOptions test = SqlString.CompareOptionsFromSqlCompareOptions (
335                                     SqlCompareOptions.BinarySort);
336                                 Fail ("#M03");
337                         } catch (Exception e) {
338                                 AssertEquals ("#M04", typeof (ArgumentOutOfRangeException), e.GetType ());
339                         }
340                 }
341
342                 [Test]
343                 public void UnicodeBytes()
344                 {
345                         AssertEquals ("#N01", (byte)105, Test1.GetNonUnicodeBytes () [1]);
346                         AssertEquals ("#N02", (byte)32, Test1.GetNonUnicodeBytes () [5]);
347
348                         AssertEquals ("#N03", (byte)70, Test1.GetUnicodeBytes () [0]);
349                         AssertEquals ("#N03b", (byte)70, Test1.GetNonUnicodeBytes () [0]);
350                         AssertEquals ("#N03c", (byte)0, Test1.GetUnicodeBytes () [1]);
351                         AssertEquals ("#N03d", (byte)105, Test1.GetNonUnicodeBytes () [1]);
352                         AssertEquals ("#N03e", (byte)105, Test1.GetUnicodeBytes () [2]);
353                         AssertEquals ("#N03f", (byte)114, Test1.GetNonUnicodeBytes () [2]);
354                         AssertEquals ("#N03g", (byte)0, Test1.GetUnicodeBytes () [3]);
355                         AssertEquals ("#N03h", (byte)115, Test1.GetNonUnicodeBytes () [3]);
356                         AssertEquals ("#N03i", (byte)114, Test1.GetUnicodeBytes () [4]);
357                         AssertEquals ("#N03j", (byte)116, Test1.GetNonUnicodeBytes () [4]);
358
359                         AssertEquals ("#N04", (byte)105, Test1.GetUnicodeBytes () [2]);
360
361                         try {
362                                 byte test = Test1.GetUnicodeBytes () [105];
363                                 Fail ("#N05");
364                         } catch (Exception e) {
365                                 AssertEquals ("#N06", typeof (IndexOutOfRangeException), e.GetType());                                
366                         }
367                 }
368                       
369                 [Test]
370                 [ExpectedException(typeof (FormatException))]
371                 public void ConversionBoolFormatException1 ()
372                 {
373                         bool test = Test1.ToSqlBoolean ().Value;                              
374                 }
375
376                 [Test]
377                 [ExpectedException(typeof (FormatException))]
378                 public void ConversionByteFormatException ()
379                 {
380                         byte test = Test1.ToSqlByte ().Value;
381                 }
382
383                 [Test]
384                 [ExpectedException(typeof (FormatException))]
385                 public void ConversionDecimalFormatException1 ()
386                 {
387                         Decimal d = Test1.ToSqlDecimal ().Value;
388                 }
389
390                 [Test]
391                 [ExpectedException(typeof (FormatException))]
392                 public void ConversionDecimalFormatException2 ()
393                 {
394                         SqlString String9E300 = new SqlString ("9E+300");
395                         SqlDecimal test = String9E300.ToSqlDecimal ();
396                 }
397
398                 [Test]
399                 [ExpectedException(typeof (FormatException))]
400                 public void ConversionGuidFormatException ()
401                 {
402                         SqlString String9E300 = new SqlString ("9E+300");
403                         SqlGuid test = String9E300.ToSqlGuid ();
404                 }
405
406                 [Test]
407                 [ExpectedException(typeof (FormatException))]
408                 public void ConversionInt16FormatException ()
409                 {
410                         SqlString String9E300 = new SqlString ("9E+300");
411                         SqlInt16 test = String9E300.ToSqlInt16().Value;
412                 }
413
414                 [Test]
415                 [ExpectedException(typeof (FormatException))]
416                 public void ConversionInt32FormatException1 ()
417                 {
418                         SqlString String9E300 = new SqlString ("9E+300");
419                         SqlInt32 test = String9E300.ToSqlInt32 ().Value;
420                 }
421
422                 [Test]
423                 [ExpectedException(typeof (FormatException))]
424                 public void ConversionInt32FormatException2 ()
425                 {
426                         SqlInt32 test = Test1.ToSqlInt32 ().Value;
427                 }
428
429                 [Test]
430                 [ExpectedException(typeof (FormatException))]
431                 public void ConversionInt64FormatException ()
432                 {
433                         SqlString String9E300 = new SqlString ("9E+300");
434                         SqlInt64 test = String9E300.ToSqlInt64 ().Value;
435                 }
436
437                 [Test]
438                 [ExpectedException(typeof (FormatException))]
439                 public void ConversionIntMoneyFormatException2 ()
440                 {
441                         SqlString String9E300 = new SqlString ("9E+300");
442                         SqlMoney test = String9E300.ToSqlMoney ().Value;
443                 }
444
445                 [Test]
446                 [ExpectedException(typeof(OverflowException))]
447                 public void ConversionByteOverflowException ()
448                 {
449                         SqlByte b = (new SqlString ("2500")).ToSqlByte ();
450                 }
451
452                 [Test]
453                 [ExpectedException(typeof(OverflowException))]
454                 public void ConversionDoubleOverflowException ()
455                 {
456                         SqlDouble test = (new SqlString ("4e400")).ToSqlDouble ();
457                 }
458
459                 [Test]
460                 [ExpectedException(typeof(OverflowException))]
461                 public void ConversionSingleOverflowException ()
462                 {
463                         SqlString String9E300 = new SqlString ("9E+300");
464                         SqlSingle test = String9E300.ToSqlSingle().Value;
465                 }
466
467                 [Test]          
468                 public void Conversions()
469                 {
470
471                         SqlString String250 = new SqlString ("250");
472                         SqlString String9E300 = new SqlString ("9E+300");
473
474                         // ToSqlBoolean ()                                
475                         Assert ("#O02", (new SqlString("1")).ToSqlBoolean ().Value);
476                         Assert ("#O03", !(new SqlString("0")).ToSqlBoolean ().Value);
477                         Assert ("#O04", (new SqlString("True")).ToSqlBoolean ().Value);
478                         Assert ("#O05", !(new SqlString("FALSE")).ToSqlBoolean ().Value);
479                         Assert ("#O06", SqlString.Null.ToSqlBoolean ().IsNull);
480
481                         // ToSqlByte ()
482                         AssertEquals ("#O08", (byte)250, String250.ToSqlByte ().Value);    
483
484                         // ToSqlDateTime
485                         AssertEquals ("#O11", 10, 
486                                       (new SqlString ("2002-10-10")).ToSqlDateTime ().Value.Day);
487                         
488                         // ToSqlDecimal ()
489                         AssertEquals ("#O16", (decimal)250, String250.ToSqlDecimal ().Value);
490
491                         // ToSqlDouble
492                         AssertEquals ("#O19", (SqlDouble)9E+300, String9E300.ToSqlDouble ());
493
494                         // ToSqlGuid
495                         SqlString TestGuid = new SqlString("11111111-1111-1111-1111-111111111111");
496                         AssertEquals ("#O22", new SqlGuid("11111111-1111-1111-1111-111111111111"), TestGuid.ToSqlGuid ());
497
498                         // ToSqlInt16 ()
499                         AssertEquals ("#O24", (short)250, String250.ToSqlInt16 ().Value);
500
501                         // ToSqlInt32 ()
502                         AssertEquals ("#O27", (int)250, String250.ToSqlInt32 ().Value);
503
504                         // ToSqlInt64 ()
505                         AssertEquals ("#O32", (long)250, String250.ToSqlInt64 ().Value);
506
507                         // ToSqlMoney ()
508                         AssertEquals ("#O35", 250.0000M, String250.ToSqlMoney ().Value);
509
510
511                         // ToSqlSingle ()
512                         AssertEquals ("#O38", (float)250, String250.ToSqlSingle ().Value);
513
514                         // ToString ()
515                         AssertEquals ("#O41", "First TestString", Test1.ToString ());
516                 }
517
518                 // OPERATORS
519
520                 [Test]
521                 public void ArithmeticOperators()
522                 {
523                         SqlString TestString = new SqlString ("...Testing...");
524                         AssertEquals ("#P01", (SqlString)"First TestString...Testing...",
525                                       Test1 + TestString);
526                         AssertEquals ("#P02", SqlString.Null,
527                                       Test1 + SqlString.Null);
528                 }
529
530                 [Test]
531                 public void ThanOrEqualOperators()
532                 {
533                         // == -operator
534                         Assert ("#Q01", (Test2 == Test3).Value);
535                         Assert ("#Q02", !(Test1 == Test2).Value);
536                         Assert ("#Q03", (Test1 == SqlString.Null).IsNull);
537                         
538                         // != -operator
539                         Assert ("#Q04", !(Test3 != Test2).Value);
540                         Assert ("#Q05", !(Test2 != Test3).Value);
541                         Assert ("#Q06", (Test1 != Test3).Value);
542                         Assert ("#Q07", (Test1 != SqlString.Null).IsNull);
543
544                         // > -operator
545                         Assert ("#Q08", (Test2 > Test1).Value);
546                         Assert ("#Q09", !(Test1 > Test3).Value);
547                         Assert ("#Q10", !(Test2 > Test3).Value);
548                         Assert ("#Q11", (Test1 > SqlString.Null).IsNull);
549
550                         // >=  -operator
551                         Assert ("#Q12", !(Test1 >= Test3).Value);
552                         Assert ("#Q13", (Test3 >= Test1).Value);
553                         Assert ("#Q14", (Test2 >= Test3).Value);
554                         Assert ("#Q15", (Test1 >= SqlString.Null).IsNull);
555
556                         // < -operator
557                         Assert ("#Q16", (Test1 < Test2).Value);
558                         Assert ("#Q17", (Test1 < Test3).Value);
559                         Assert ("#Q18", !(Test2 < Test3).Value);
560                         Assert ("#Q19", (Test1 < SqlString.Null).IsNull);
561
562                         // <= -operator
563                         Assert ("#Q20", (Test1 <= Test3).Value);
564                         Assert ("#Q21", !(Test3 <= Test1).Value);
565                         Assert ("#Q22", (Test2 <= Test3).Value);
566                         Assert ("#Q23", (Test1 <= SqlString.Null).IsNull);
567                 }
568
569                 [Test]
570                 public void SqlBooleanToSqlString()
571                 {
572                         SqlBoolean TestBoolean = new SqlBoolean (true);
573                         SqlBoolean TestBoolean2 = new SqlBoolean (false);
574                         SqlString Result;
575
576                         Result = (SqlString)TestBoolean;
577                         AssertEquals ("#R01", "True", Result.Value);
578                         
579                         Result = (SqlString)TestBoolean2;
580                         AssertEquals ("#R02", "False", Result.Value);
581                         
582                         Result = (SqlString)SqlBoolean.Null;
583                         Assert ("#R03", Result.IsNull);
584                 }
585
586                 [Test]
587                 public void SqlByteToBoolean()
588                 {
589                         SqlByte TestByte = new SqlByte (250);
590                         AssertEquals ("#S01", "250", ((SqlString)TestByte).Value);
591                         try {
592                                 SqlString test = ((SqlString)SqlByte.Null).Value;
593                                 Fail ("#S02");
594                         } catch (Exception e) {
595                                 AssertEquals ("#S03", typeof (SqlNullValueException), e.GetType ());
596                         }
597                 }
598
599                 [Test]
600                 public void SqlDateTimeToSqlString()
601                 {                        
602                         Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-AU");
603                         SqlDateTime TestTime = new SqlDateTime(2002, 10, 22, 9, 52, 30);
604                         AssertEquals ("#T01", "22/10/2002 9:52:30 AM", ((SqlString)TestTime).Value);                        
605                 }
606                 
607                 [Test]
608                 public void SqlDecimalToSqlString()
609                 {
610                         SqlDecimal TestDecimal = new SqlDecimal (1000.2345);
611                         AssertEquals ("#U01", "1000.2345000000000", ((SqlString)TestDecimal).Value);
612                 }
613                 
614                 [Test]
615                 public void SqlDoubleToSqlString()
616                 {
617                         SqlDouble TestDouble = new SqlDouble (64E+64);
618                         AssertEquals ("#V01", "6.4E+65", ((SqlString)TestDouble).Value);
619                 }
620
621                 [Test]
622                 public void SqlGuidToSqlString()
623                 {
624                         byte [] b = new byte [16];
625                         b [0] = 100;
626                         b [1] = 64;
627                         SqlGuid TestGuid = new SqlGuid (b);
628                         
629                         AssertEquals ("#W01", "00004064-0000-0000-0000-000000000000", 
630                                       ((SqlString)TestGuid).Value);
631                         try {
632                                 SqlString test = ((SqlString)SqlGuid.Null).Value;
633                                 Fail ("#W02");
634                         } catch (Exception e) {
635                                 AssertEquals ("#W03", typeof (SqlNullValueException), e.GetType());
636                         }
637                 }
638                 
639                 [Test]
640                 public void SqlInt16ToSqlString()
641                 {
642                         SqlInt16 TestInt = new SqlInt16(20012);
643                         AssertEquals ("#X01", "20012", ((SqlString)TestInt).Value);
644                         try {
645                                 SqlString test = ((SqlString)SqlInt16.Null).Value;
646                                 Fail ("#X02");
647                         } catch (Exception e) {
648                                 AssertEquals ("#X03", typeof (SqlNullValueException), e.GetType ());                                
649                         }
650                 }
651                 
652                 [Test]
653                 public void SqlInt32ToSqlString()
654                 {
655                         SqlInt32 TestInt = new SqlInt32(-12456);
656                         AssertEquals ("#Y01", "-12456", ((SqlString)TestInt).Value);
657                         try {
658                                 SqlString test = ((SqlString)SqlInt32.Null).Value;
659                                 Fail ("#Y02");
660                         } catch (Exception e) {
661                                 AssertEquals ("#Y03", typeof (SqlNullValueException), e.GetType ());                                
662                         }
663                 }
664                 
665                 [Test]
666                 public void SqlInt64ToSqlString()
667                 {
668                         SqlInt64 TestInt = new SqlInt64(10101010);
669                         AssertEquals ("#Z01", "10101010", ((SqlString)TestInt).Value);
670                 }
671                 
672                 [Test]
673                 public void SqlMoneyToSqlString()
674                 {
675                         SqlMoney TestMoney = new SqlMoney (646464.6464);
676                         AssertEquals ("#AA01", "646464.6464", ((SqlString)TestMoney).Value);
677                 }
678                 
679                 [Test]
680                 public void SqlSingleToSqlString()
681                 {
682                         SqlSingle TestSingle = new SqlSingle (3E+20);
683                         AssertEquals ("#AB01", "3E+20", ((SqlString)TestSingle).Value);
684                 }
685                       
686                 [Test]                        
687                 public void SqlStringToString()
688                 {
689                         AssertEquals ("#AC01", "First TestString",(String)Test1);                        
690                 }
691
692                 [Test]
693                 public void StringToSqlString()
694                 {
695                         String TestString = "Test String";
696                         AssertEquals ("#AD01", "Test String", ((SqlString)TestString).Value);                        
697                 }                
698         }
699 }
700