1 // SqlStringTest.cs - NUnit Test Cases for System.Data.SqlTypes.SqlString
4 // Ville Palo (vi64pa@koti.soon.fi)
5 // Martin Willemoes Hansen (mwh@sysrq.dk)
8 // (C) 2003 Martin Willemoes Hansen
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
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.
34 using System.Data.SqlTypes;
35 using System.Globalization;
39 using System.Threading;
42 using System.Xml.Serialization;
45 using NUnit.Framework;
47 namespace MonoTests.System.Data.SqlTypes
50 public class SqlStringTest
52 private SqlString Test1;
53 private SqlString Test2;
54 private SqlString Test3;
55 private CultureInfo originalCulture;
58 public void GetReady()
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");
68 public void TearDown ()
70 Thread.CurrentThread.CurrentCulture = originalCulture;
78 SqlString TestString = new SqlString ("Test");
79 Assert.AreEqual ("Test", TestString.Value, "#A01");
81 // SqlString (String, int)
82 TestString = new SqlString ("Test", 2057);
83 Assert.AreEqual (2057, TestString.LCID, "#A02");
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");
91 // SqlString(string, int, SqlCompareOptions)
92 TestString = new SqlString ("Test", 2057, SqlCompareOptions.IgnoreNonSpace);
93 Assert.IsTrue (!TestString.IsNull, "#A04");
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");
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");
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");
113 [ExpectedException(typeof (ArgumentOutOfRangeException))]
114 public void CtorArgumentOutOfRangeException1 ()
116 SqlString TestString = new SqlString (2057, SqlCompareOptions.BinarySort, new byte [2] {113, 100}, 2, 1);
120 [ExpectedException(typeof (ArgumentOutOfRangeException))]
121 public void CtorArgumentOutOfRangeException2 ()
123 SqlString TestString = new SqlString (2057, SqlCompareOptions.BinarySort, new byte [2] {113, 100}, 0, 4);
126 // Test public fields
128 public void PublicFields()
131 Assert.AreEqual (32768, SqlString.BinarySort, "#B01");
134 Assert.AreEqual (1, SqlString.IgnoreCase, "#B02");
137 Assert.AreEqual (8, SqlString.IgnoreKanaType, "#B03");
140 Assert.AreEqual (2, SqlString.IgnoreNonSpace, "#B04");
143 Assert.AreEqual (16, SqlString.IgnoreWidth, "#B05");
146 Assert.IsTrue (SqlString.Null.IsNull, "#B06");
151 public void Properties()
154 Assert.AreEqual (3081, Test1.CompareInfo.LCID, "#C01");
157 Assert.AreEqual (3081, Test1.CultureInfo.LCID, "#C02");
160 Assert.AreEqual (3081, Test1.LCID, "#C05");
163 Assert.IsTrue (!Test1.IsNull, "#C03");
164 Assert.IsTrue (SqlString.Null.IsNull, "#C04");
167 Assert.AreEqual ("IgnoreCase, IgnoreKanaType, IgnoreWidth",
168 Test1.SqlCompareOptions.ToString (), "#C06");
171 Assert.AreEqual ("First TestString", Test1.Value, "#C07");
177 [ExpectedException(typeof(ArgumentException))]
178 public void CompareToArgumentException ()
180 SqlByte Test = new SqlByte (1);
181 Test1.CompareTo (Test);
185 [ExpectedException(typeof(SqlTypeException))]
186 public void CompareToSqlTypeException ()
188 SqlString T1 = new SqlString ("test", 2057, SqlCompareOptions.IgnoreCase);
189 SqlString T2 = new SqlString ("TEST", 2057, SqlCompareOptions.None);
194 public void CompareTo()
196 SqlByte Test = new SqlByte (1);
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");
203 SqlString T1 = new SqlString ("test", 2057, SqlCompareOptions.IgnoreCase);
204 SqlString T2 = new SqlString ("TEST", 2057, SqlCompareOptions.None);
207 T1 = new SqlString ("test", 2057, SqlCompareOptions.IgnoreCase);
208 T2 = new SqlString ("TEST", 2057, SqlCompareOptions.IgnoreCase);
209 Assert.IsTrue (T2.CompareTo (T1) == 0, "#D09");
211 T1 = new SqlString ("test", 2057);
212 T2 = new SqlString ("TEST", 2057);
213 Assert.IsTrue (T2.CompareTo (T1) == 0, "#D10");
215 T1 = new SqlString ("test", 2057, SqlCompareOptions.None);
216 T2 = new SqlString ("TEST", 2057, SqlCompareOptions.None);
217 Assert.IsTrue (T2.CompareTo (T1) != 0, "#D11");
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");
224 T1 = new SqlString ("TESTñ", 2057, SqlCompareOptions.None);
225 T2 = new SqlString ("TESTn", 2057, SqlCompareOptions.None);
226 Assert.IsTrue (T2.CompareTo (T1) != 0, "#D13");
229 T1 = new SqlString ("01_", 2057, SqlCompareOptions.BinarySort);
230 T2 = new SqlString ("_01", 2057, SqlCompareOptions.BinarySort);
231 Assert.IsTrue (T1.CompareTo (T2) < 0, "#D14");
233 T1 = new SqlString ("01_", 2057, SqlCompareOptions.None);
234 T2 = new SqlString ("_01", 2057, SqlCompareOptions.None);
235 Assert.IsTrue (T1.CompareTo (T2) > 0, "#D15");
239 public void EqualsMethods()
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");
246 // Static Equals()-method
247 Assert.IsTrue (SqlString.Equals (Test2, Test3).Value, "#E05");
248 Assert.IsTrue (!SqlString.Equals (Test1, Test2).Value, "#E06");
252 public void GetHashCodeTest()
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");
262 public void GetTypeTest()
264 Assert.AreEqual ("System.Data.SqlTypes.SqlString",
265 Test1.GetType ().ToString (), "#G01");
266 Assert.AreEqual ("System.String",
267 Test1.Value.GetType ().ToString (), "#G02");
271 public void Greaters()
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");
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");
285 public void Lessers()
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");
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");
300 public void NotEquals()
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");
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");
316 Assert.AreEqual ((SqlString)"First TestStringThis is just a test SqlString",
317 SqlString.Concat (Test1, Test2), "#K01");
319 Assert.AreEqual (SqlString.Null,
320 SqlString.Concat (Test1, SqlString.Null), "#K02");
326 SqlString TestSqlString = Test1.Clone ();
327 Assert.AreEqual (Test1, TestSqlString, "#L01");
331 public void CompareOptionsFromSqlCompareOptions()
333 Assert.AreEqual (CompareOptions.IgnoreCase,
334 SqlString.CompareOptionsFromSqlCompareOptions (
335 SqlCompareOptions.IgnoreCase), "#M01");
336 Assert.AreEqual (CompareOptions.IgnoreCase,
337 SqlString.CompareOptionsFromSqlCompareOptions (
338 SqlCompareOptions.IgnoreCase), "#M02");
340 CompareOptions test = SqlString.CompareOptionsFromSqlCompareOptions (
341 SqlCompareOptions.BinarySort);
342 Assert.Fail ("#M03");
343 } catch (ArgumentOutOfRangeException e) {
344 Assert.AreEqual (typeof (ArgumentOutOfRangeException), e.GetType (), "#M04");
349 public void UnicodeBytes()
351 Assert.AreEqual ((byte)105, Test1.GetNonUnicodeBytes () [1], "#N01");
352 Assert.AreEqual ((byte)32, Test1.GetNonUnicodeBytes () [5], "#N02");
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");
365 Assert.AreEqual ((byte)105, Test1.GetUnicodeBytes () [2], "#N04");
368 byte test = Test1.GetUnicodeBytes () [105];
369 Assert.Fail ("#N05");
370 } catch (Exception e) {
371 Assert.AreEqual (typeof (IndexOutOfRangeException), e.GetType(), "#N06");
376 [ExpectedException(typeof (FormatException))]
377 public void ConversionBoolFormatException1 ()
379 bool test = Test1.ToSqlBoolean ().Value;
383 [ExpectedException(typeof (FormatException))]
384 public void ConversionByteFormatException ()
386 byte test = Test1.ToSqlByte ().Value;
390 [ExpectedException(typeof (FormatException))]
391 public void ConversionDecimalFormatException1 ()
393 Decimal d = Test1.ToSqlDecimal ().Value;
397 [ExpectedException(typeof (FormatException))]
398 public void ConversionDecimalFormatException2 ()
400 SqlString String9E300 = new SqlString ("9E+300");
401 SqlDecimal test = String9E300.ToSqlDecimal ();
405 [ExpectedException(typeof (FormatException))]
406 public void ConversionGuidFormatException ()
408 SqlString String9E300 = new SqlString ("9E+300");
409 SqlGuid test = String9E300.ToSqlGuid ();
413 [ExpectedException(typeof (FormatException))]
414 public void ConversionInt16FormatException ()
416 SqlString String9E300 = new SqlString ("9E+300");
417 SqlInt16 test = String9E300.ToSqlInt16().Value;
421 [ExpectedException(typeof (FormatException))]
422 public void ConversionInt32FormatException1 ()
424 SqlString String9E300 = new SqlString ("9E+300");
425 SqlInt32 test = String9E300.ToSqlInt32 ().Value;
429 [ExpectedException(typeof (FormatException))]
430 public void ConversionInt32FormatException2 ()
432 SqlInt32 test = Test1.ToSqlInt32 ().Value;
436 [ExpectedException(typeof (FormatException))]
437 public void ConversionInt64FormatException ()
439 SqlString String9E300 = new SqlString ("9E+300");
440 SqlInt64 test = String9E300.ToSqlInt64 ().Value;
444 [ExpectedException(typeof (FormatException))]
445 public void ConversionIntMoneyFormatException2 ()
447 SqlString String9E300 = new SqlString ("9E+300");
448 SqlMoney test = String9E300.ToSqlMoney ().Value;
452 [ExpectedException(typeof(OverflowException))]
453 public void ConversionByteOverflowException ()
455 SqlByte b = (new SqlString ("2500")).ToSqlByte ();
459 [ExpectedException(typeof(OverflowException))]
460 public void ConversionDoubleOverflowException ()
462 SqlDouble test = (new SqlString ("4e400")).ToSqlDouble ();
466 [ExpectedException(typeof(OverflowException))]
467 public void ConversionSingleOverflowException ()
469 SqlString String9E300 = new SqlString ("9E+300");
470 SqlSingle test = String9E300.ToSqlSingle().Value;
474 public void Conversions()
476 SqlString String250 = new SqlString ("250");
477 SqlString String9E300 = new SqlString ("9E+300");
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");
487 Assert.AreEqual ((byte)250, String250.ToSqlByte ().Value, "#O08");
491 (new SqlString ("2002-10-10")).ToSqlDateTime ().Value.Day, "#O11");
494 Assert.AreEqual ((decimal)250, String250.ToSqlDecimal ().Value, "#O16");
497 Assert.AreEqual ((SqlDouble)9E+300, String9E300.ToSqlDouble (), "#O19");
500 SqlString TestGuid = new SqlString("11111111-1111-1111-1111-111111111111");
501 Assert.AreEqual (new SqlGuid("11111111-1111-1111-1111-111111111111"), TestGuid.ToSqlGuid (), "#O22");
504 Assert.AreEqual ((short)250, String250.ToSqlInt16 ().Value, "#O24");
507 Assert.AreEqual ((int)250, String250.ToSqlInt32 ().Value, "#O27");
510 Assert.AreEqual ((long)250, String250.ToSqlInt64 ().Value, "#O32");
513 Assert.AreEqual (250.0000M, String250.ToSqlMoney ().Value, "#O35");
516 Assert.AreEqual ((float)250, String250.ToSqlSingle ().Value, "#O38");
519 Assert.AreEqual ("First TestString", Test1.ToString (), "#O41");
525 public void ArithmeticOperators()
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");
535 public void ThanOrEqualOperators()
538 Assert.IsTrue ((Test2 == Test3).Value, "#Q01");
539 Assert.IsTrue (!(Test1 == Test2).Value, "#Q02");
540 Assert.IsTrue ((Test1 == SqlString.Null).IsNull, "#Q03");
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");
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");
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");
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");
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");
574 public void SqlBooleanToSqlString()
576 SqlBoolean TestBoolean = new SqlBoolean (true);
577 SqlBoolean TestBoolean2 = new SqlBoolean (false);
580 Result = (SqlString)TestBoolean;
581 Assert.AreEqual ("True", Result.Value, "#R01");
583 Result = (SqlString)TestBoolean2;
584 Assert.AreEqual ("False", Result.Value, "#R02");
586 Result = (SqlString)SqlBoolean.Null;
587 Assert.IsTrue (Result.IsNull, "#R03");
591 public void SqlByteToBoolean()
593 SqlByte TestByte = new SqlByte (250);
594 Assert.AreEqual ("250", ((SqlString)TestByte).Value, "#S01");
596 SqlString test = ((SqlString)SqlByte.Null).Value;
597 Assert.Fail ("#S02");
598 } catch (SqlNullValueException e) {
599 Assert.AreEqual (typeof (SqlNullValueException), e.GetType (), "#S03");
604 public void SqlDateTimeToSqlString()
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");
611 public void SqlDecimalToSqlString()
613 SqlDecimal TestDecimal = new SqlDecimal (1000.2345);
614 Assert.AreEqual ("1000.2345000000000", ((SqlString)TestDecimal).Value, "#U01");
618 public void SqlDoubleToSqlString()
620 SqlDouble TestDouble = new SqlDouble (64E+64);
621 Assert.AreEqual ("6.4E+65", ((SqlString)TestDouble).Value, "#V01");
625 public void SqlGuidToSqlString()
627 byte [] b = new byte [16];
630 SqlGuid TestGuid = new SqlGuid (b);
632 Assert.AreEqual ("00004064-0000-0000-0000-000000000000",
633 ((SqlString)TestGuid).Value, "#W01");
635 SqlString test = ((SqlString)SqlGuid.Null).Value;
636 Assert.Fail ("#W02");
637 } catch (SqlNullValueException e) {
638 Assert.AreEqual (typeof (SqlNullValueException), e.GetType(), "#W03");
643 public void SqlInt16ToSqlString()
645 SqlInt16 TestInt = new SqlInt16(20012);
646 Assert.AreEqual ("20012", ((SqlString)TestInt).Value, "#X01");
648 SqlString test = ((SqlString)SqlInt16.Null).Value;
649 Assert.Fail ("#X02");
650 } catch (SqlNullValueException e) {
651 Assert.AreEqual (typeof (SqlNullValueException), e.GetType (), "#X03");
656 public void SqlInt32ToSqlString()
658 SqlInt32 TestInt = new SqlInt32(-12456);
659 Assert.AreEqual ("-12456", ((SqlString)TestInt).Value, "#Y01");
661 SqlString test = ((SqlString)SqlInt32.Null).Value;
662 Assert.Fail ("#Y02");
663 } catch (SqlNullValueException e) {
664 Assert.AreEqual (typeof (SqlNullValueException), e.GetType (), "#Y03");
669 public void SqlInt64ToSqlString()
671 SqlInt64 TestInt = new SqlInt64(10101010);
672 Assert.AreEqual ("10101010", ((SqlString)TestInt).Value, "#Z01");
676 public void SqlMoneyToSqlString()
678 SqlMoney TestMoney = new SqlMoney (646464.6464);
679 Assert.AreEqual ("646464.6464", ((SqlString)TestMoney).Value, "#AA01");
683 public void SqlSingleToSqlString()
685 SqlSingle TestSingle = new SqlSingle (3E+20);
686 Assert.AreEqual ("3E+20", ((SqlString)TestSingle).Value, "#AB01");
690 public void SqlStringToString()
692 Assert.AreEqual ("First TestString",(String)Test1, "#AC01");
696 public void StringToSqlString()
698 String TestString = "Test String";
699 Assert.AreEqual ("Test String", ((SqlString)TestString).Value, "#AD01");
704 public void AddSqlString()
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");
712 public void GetXsdTypeTest ()
714 XmlQualifiedName qualifiedName = SqlString.GetXsdType (null);
715 NUnit.Framework.Assert.AreEqual ("string", qualifiedName.Name, "#A01");
718 internal void ReadWriteXmlTestInternal (string xml,
730 test = new SqlString (testval);
731 ser = new XmlSerializer(typeof(SqlString));
732 sw = new StringWriter ();
733 xw = new XmlTextWriter (sw);
735 ser.Serialize (xw, test);
737 Assert.AreEqual (xml, sw.ToString (), unit_test_id);
739 sr = new StringReader (xml);
740 xr = new XmlTextReader (sr);
741 test1 = (SqlString)ser.Deserialize (xr);
743 Assert.AreEqual (testval, test1.Value, unit_test_id);
747 public void ReadWriteXmlTest ()
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";
754 ReadWriteXmlTestInternal (xml1, strtest1, "BA01");
755 ReadWriteXmlTestInternal (xml2, strtest2.ToString (), "BA02");