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