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