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;
37 using System.Threading;
39 using System.Xml.Serialization;
41 using NUnit.Framework;
43 namespace MonoTests.System.Data.SqlTypes
46 public class SqlStringTest
48 private SqlString Test1;
49 private SqlString Test2;
50 private SqlString Test3;
51 private CultureInfo originalCulture;
54 public void GetReady()
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");
64 public void TearDown ()
66 Thread.CurrentThread.CurrentCulture = originalCulture;
74 SqlString TestString = new SqlString ("Test");
75 Assert.AreEqual ("Test", TestString.Value, "#A01");
77 // SqlString (String, int)
78 TestString = new SqlString ("Test", 2057);
79 Assert.AreEqual (2057, TestString.LCID, "#A02");
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");
87 // SqlString(string, int, SqlCompareOptions)
88 TestString = new SqlString ("Test", 2057, SqlCompareOptions.IgnoreNonSpace);
89 Assert.IsTrue (!TestString.IsNull, "#A04");
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");
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");
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");
109 [ExpectedException(typeof (ArgumentOutOfRangeException))]
110 public void CtorArgumentOutOfRangeException1 ()
112 SqlString TestString = new SqlString (2057, SqlCompareOptions.BinarySort, new byte [2] {113, 100}, 2, 1);
116 [ExpectedException(typeof (ArgumentOutOfRangeException))]
117 public void CtorArgumentOutOfRangeException2 ()
119 SqlString TestString = new SqlString (2057, SqlCompareOptions.BinarySort, new byte [2] {113, 100}, 0, 4);
122 // Test public fields
124 public void PublicFields()
127 Assert.AreEqual (32768, SqlString.BinarySort, "#B01");
130 Assert.AreEqual (1, SqlString.IgnoreCase, "#B02");
133 Assert.AreEqual (8, SqlString.IgnoreKanaType, "#B03");
136 Assert.AreEqual (2, SqlString.IgnoreNonSpace, "#B04");
139 Assert.AreEqual (16, SqlString.IgnoreWidth, "#B05");
142 Assert.IsTrue (SqlString.Null.IsNull, "#B06");
147 public void Properties()
150 Assert.AreEqual (3081, Test1.CompareInfo.LCID, "#C01");
153 Assert.AreEqual (3081, Test1.CultureInfo.LCID, "#C02");
156 Assert.AreEqual (3081, Test1.LCID, "#C05");
159 Assert.IsTrue (!Test1.IsNull, "#C03");
160 Assert.IsTrue (SqlString.Null.IsNull, "#C04");
163 Assert.AreEqual ("IgnoreCase, IgnoreKanaType, IgnoreWidth",
164 Test1.SqlCompareOptions.ToString (), "#C06");
167 Assert.AreEqual ("First TestString", Test1.Value, "#C07");
173 [ExpectedException(typeof(ArgumentException))]
174 public void CompareToArgumentException ()
176 SqlByte Test = new SqlByte (1);
177 Test1.CompareTo (Test);
181 [ExpectedException(typeof(SqlTypeException))]
182 public void CompareToSqlTypeException ()
184 SqlString T1 = new SqlString ("test", 2057, SqlCompareOptions.IgnoreCase);
185 SqlString T2 = new SqlString ("TEST", 2057, SqlCompareOptions.None);
190 public void CompareTo()
192 SqlByte Test = new SqlByte (1);
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");
199 SqlString T1 = new SqlString ("test", 2057, SqlCompareOptions.IgnoreCase);
200 SqlString T2 = new SqlString ("TEST", 2057, SqlCompareOptions.None);
203 T1 = new SqlString ("test", 2057, SqlCompareOptions.IgnoreCase);
204 T2 = new SqlString ("TEST", 2057, SqlCompareOptions.IgnoreCase);
205 Assert.IsTrue (T2.CompareTo (T1) == 0, "#D09");
207 T1 = new SqlString ("test", 2057);
208 T2 = new SqlString ("TEST", 2057);
209 Assert.IsTrue (T2.CompareTo (T1) == 0, "#D10");
211 T1 = new SqlString ("test", 2057, SqlCompareOptions.None);
212 T2 = new SqlString ("TEST", 2057, SqlCompareOptions.None);
213 Assert.IsTrue (T2.CompareTo (T1) != 0, "#D11");
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");
220 T1 = new SqlString ("TESTñ", 2057, SqlCompareOptions.None);
221 T2 = new SqlString ("TESTn", 2057, SqlCompareOptions.None);
222 Assert.IsTrue (T2.CompareTo (T1) != 0, "#D13");
225 T1 = new SqlString ("01_", 2057, SqlCompareOptions.BinarySort);
226 T2 = new SqlString ("_01", 2057, SqlCompareOptions.BinarySort);
227 Assert.IsTrue (T1.CompareTo (T2) < 0, "#D14");
229 T1 = new SqlString ("01_", 2057, SqlCompareOptions.None);
230 T2 = new SqlString ("_01", 2057, SqlCompareOptions.None);
231 Assert.IsTrue (T1.CompareTo (T2) > 0, "#D15");
235 public void EqualsMethods()
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");
242 // Static Equals()-method
243 Assert.IsTrue (SqlString.Equals (Test2, Test3).Value, "#E05");
244 Assert.IsTrue (!SqlString.Equals (Test1, Test2).Value, "#E06");
248 public void GetHashCodeTest()
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");
258 public void GetTypeTest()
260 Assert.AreEqual ("System.Data.SqlTypes.SqlString",
261 Test1.GetType ().ToString (), "#G01");
262 Assert.AreEqual ("System.String",
263 Test1.Value.GetType ().ToString (), "#G02");
267 public void Greaters()
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");
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");
281 public void Lessers()
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");
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");
296 public void NotEquals()
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");
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");
312 Assert.AreEqual ((SqlString)"First TestStringThis is just a test SqlString",
313 SqlString.Concat (Test1, Test2), "#K01");
315 Assert.AreEqual (SqlString.Null,
316 SqlString.Concat (Test1, SqlString.Null), "#K02");
322 SqlString TestSqlString = Test1.Clone ();
323 Assert.AreEqual (Test1, TestSqlString, "#L01");
327 public void CompareOptionsFromSqlCompareOptions()
329 Assert.AreEqual (CompareOptions.IgnoreCase,
330 SqlString.CompareOptionsFromSqlCompareOptions (
331 SqlCompareOptions.IgnoreCase), "#M01");
332 Assert.AreEqual (CompareOptions.IgnoreCase,
333 SqlString.CompareOptionsFromSqlCompareOptions (
334 SqlCompareOptions.IgnoreCase), "#M02");
336 CompareOptions test = SqlString.CompareOptionsFromSqlCompareOptions (
337 SqlCompareOptions.BinarySort);
338 Assert.Fail ("#M03");
339 } catch (ArgumentOutOfRangeException e) {
340 Assert.AreEqual (typeof (ArgumentOutOfRangeException), e.GetType (), "#M04");
345 public void UnicodeBytes()
347 Assert.AreEqual ((byte)105, Test1.GetNonUnicodeBytes () [1], "#N01");
348 Assert.AreEqual ((byte)32, Test1.GetNonUnicodeBytes () [5], "#N02");
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");
361 Assert.AreEqual ((byte)105, Test1.GetUnicodeBytes () [2], "#N04");
364 byte test = Test1.GetUnicodeBytes () [105];
365 Assert.Fail ("#N05");
366 } catch (Exception e) {
367 Assert.AreEqual (typeof (IndexOutOfRangeException), e.GetType(), "#N06");
372 [ExpectedException(typeof (FormatException))]
373 public void ConversionBoolFormatException1 ()
375 bool test = Test1.ToSqlBoolean ().Value;
379 [ExpectedException(typeof (FormatException))]
380 public void ConversionByteFormatException ()
382 byte test = Test1.ToSqlByte ().Value;
386 [ExpectedException(typeof (FormatException))]
387 public void ConversionDecimalFormatException1 ()
389 Decimal d = Test1.ToSqlDecimal ().Value;
393 [ExpectedException(typeof (FormatException))]
394 public void ConversionDecimalFormatException2 ()
396 SqlString String9E300 = new SqlString ("9E+300");
397 SqlDecimal test = String9E300.ToSqlDecimal ();
401 [ExpectedException(typeof (FormatException))]
402 public void ConversionGuidFormatException ()
404 SqlString String9E300 = new SqlString ("9E+300");
405 SqlGuid test = String9E300.ToSqlGuid ();
409 [ExpectedException(typeof (FormatException))]
410 public void ConversionInt16FormatException ()
412 SqlString String9E300 = new SqlString ("9E+300");
413 SqlInt16 test = String9E300.ToSqlInt16().Value;
417 [ExpectedException(typeof (FormatException))]
418 public void ConversionInt32FormatException1 ()
420 SqlString String9E300 = new SqlString ("9E+300");
421 SqlInt32 test = String9E300.ToSqlInt32 ().Value;
425 [ExpectedException(typeof (FormatException))]
426 public void ConversionInt32FormatException2 ()
428 SqlInt32 test = Test1.ToSqlInt32 ().Value;
432 [ExpectedException(typeof (FormatException))]
433 public void ConversionInt64FormatException ()
435 SqlString String9E300 = new SqlString ("9E+300");
436 SqlInt64 test = String9E300.ToSqlInt64 ().Value;
440 [ExpectedException(typeof (FormatException))]
441 public void ConversionIntMoneyFormatException2 ()
443 SqlString String9E300 = new SqlString ("9E+300");
444 SqlMoney test = String9E300.ToSqlMoney ().Value;
448 [ExpectedException(typeof(OverflowException))]
449 public void ConversionByteOverflowException ()
451 SqlByte b = (new SqlString ("2500")).ToSqlByte ();
455 [ExpectedException(typeof(OverflowException))]
456 public void ConversionDoubleOverflowException ()
458 SqlDouble test = (new SqlString ("4e400")).ToSqlDouble ();
462 [ExpectedException(typeof(OverflowException))]
463 public void ConversionSingleOverflowException ()
465 SqlString String9E300 = new SqlString ("9E+300");
466 SqlSingle test = String9E300.ToSqlSingle().Value;
470 public void Conversions()
472 SqlString String250 = new SqlString ("250");
473 SqlString String9E300 = new SqlString ("9E+300");
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");
483 Assert.AreEqual ((byte)250, String250.ToSqlByte ().Value, "#O08");
487 (new SqlString ("2002-10-10")).ToSqlDateTime ().Value.Day, "#O11");
490 Assert.AreEqual ((decimal)250, String250.ToSqlDecimal ().Value, "#O16");
493 Assert.AreEqual ((SqlDouble)9E+300, String9E300.ToSqlDouble (), "#O19");
496 SqlString TestGuid = new SqlString("11111111-1111-1111-1111-111111111111");
497 Assert.AreEqual (new SqlGuid("11111111-1111-1111-1111-111111111111"), TestGuid.ToSqlGuid (), "#O22");
500 Assert.AreEqual ((short)250, String250.ToSqlInt16 ().Value, "#O24");
503 Assert.AreEqual ((int)250, String250.ToSqlInt32 ().Value, "#O27");
506 Assert.AreEqual ((long)250, String250.ToSqlInt64 ().Value, "#O32");
509 Assert.AreEqual (250.0000M, String250.ToSqlMoney ().Value, "#O35");
512 Assert.AreEqual ((float)250, String250.ToSqlSingle ().Value, "#O38");
515 Assert.AreEqual ("First TestString", Test1.ToString (), "#O41");
521 public void ArithmeticOperators()
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");
531 public void ThanOrEqualOperators()
534 Assert.IsTrue ((Test2 == Test3).Value, "#Q01");
535 Assert.IsTrue (!(Test1 == Test2).Value, "#Q02");
536 Assert.IsTrue ((Test1 == SqlString.Null).IsNull, "#Q03");
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");
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");
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");
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");
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");
570 public void SqlBooleanToSqlString()
572 SqlBoolean TestBoolean = new SqlBoolean (true);
573 SqlBoolean TestBoolean2 = new SqlBoolean (false);
576 Result = (SqlString)TestBoolean;
577 Assert.AreEqual ("True", Result.Value, "#R01");
579 Result = (SqlString)TestBoolean2;
580 Assert.AreEqual ("False", Result.Value, "#R02");
582 Result = (SqlString)SqlBoolean.Null;
583 Assert.IsTrue (Result.IsNull, "#R03");
587 public void SqlByteToBoolean()
589 SqlByte TestByte = new SqlByte (250);
590 Assert.AreEqual ("250", ((SqlString)TestByte).Value, "#S01");
592 SqlString test = ((SqlString)SqlByte.Null).Value;
593 Assert.Fail ("#S02");
594 } catch (SqlNullValueException e) {
595 Assert.AreEqual (typeof (SqlNullValueException), e.GetType (), "#S03");
600 public void SqlDateTimeToSqlString()
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");
607 public void SqlDecimalToSqlString()
609 SqlDecimal TestDecimal = new SqlDecimal (1000.2345);
610 Assert.AreEqual ("1000.2345000000000", ((SqlString)TestDecimal).Value, "#U01");
614 public void SqlDoubleToSqlString()
616 SqlDouble TestDouble = new SqlDouble (64E+64);
617 Assert.AreEqual ("6.4E+65", ((SqlString)TestDouble).Value, "#V01");
621 public void SqlGuidToSqlString()
623 byte [] b = new byte [16];
626 SqlGuid TestGuid = new SqlGuid (b);
628 Assert.AreEqual ("00004064-0000-0000-0000-000000000000",
629 ((SqlString)TestGuid).Value, "#W01");
631 SqlString test = ((SqlString)SqlGuid.Null).Value;
632 Assert.Fail ("#W02");
633 } catch (SqlNullValueException e) {
634 Assert.AreEqual (typeof (SqlNullValueException), e.GetType(), "#W03");
639 public void SqlInt16ToSqlString()
641 SqlInt16 TestInt = new SqlInt16(20012);
642 Assert.AreEqual ("20012", ((SqlString)TestInt).Value, "#X01");
644 SqlString test = ((SqlString)SqlInt16.Null).Value;
645 Assert.Fail ("#X02");
646 } catch (SqlNullValueException e) {
647 Assert.AreEqual (typeof (SqlNullValueException), e.GetType (), "#X03");
652 public void SqlInt32ToSqlString()
654 SqlInt32 TestInt = new SqlInt32(-12456);
655 Assert.AreEqual ("-12456", ((SqlString)TestInt).Value, "#Y01");
657 SqlString test = ((SqlString)SqlInt32.Null).Value;
658 Assert.Fail ("#Y02");
659 } catch (SqlNullValueException e) {
660 Assert.AreEqual (typeof (SqlNullValueException), e.GetType (), "#Y03");
665 public void SqlInt64ToSqlString()
667 SqlInt64 TestInt = new SqlInt64(10101010);
668 Assert.AreEqual ("10101010", ((SqlString)TestInt).Value, "#Z01");
672 public void SqlMoneyToSqlString()
674 SqlMoney TestMoney = new SqlMoney (646464.6464);
675 Assert.AreEqual ("646464.6464", ((SqlString)TestMoney).Value, "#AA01");
679 public void SqlSingleToSqlString()
681 SqlSingle TestSingle = new SqlSingle (3E+20);
682 Assert.AreEqual ("3E+20", ((SqlString)TestSingle).Value, "#AB01");
686 public void SqlStringToString()
688 Assert.AreEqual ("First TestString",(String)Test1, "#AC01");
692 public void StringToSqlString()
694 String TestString = "Test String";
695 Assert.AreEqual ("Test String", ((SqlString)TestString).Value, "#AD01");
699 public void AddSqlString()
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");
707 public void GetXsdTypeTest ()
709 XmlQualifiedName qualifiedName = SqlString.GetXsdType (null);
710 NUnit.Framework.Assert.AreEqual ("string", qualifiedName.Name, "#A01");
713 internal void ReadWriteXmlTestInternal (string xml,
725 test = new SqlString (testval);
726 ser = new XmlSerializer(typeof(SqlString));
727 sw = new StringWriter ();
728 xw = new XmlTextWriter (sw);
730 ser.Serialize (xw, test);
732 Assert.AreEqual (xml, sw.ToString (), unit_test_id);
734 sr = new StringReader (xml);
735 xr = new XmlTextReader (sr);
736 test1 = (SqlString)ser.Deserialize (xr);
738 Assert.AreEqual (testval, test1.Value, unit_test_id);
742 public void ReadWriteXmlTest ()
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";
749 ReadWriteXmlTestInternal (xml1, strtest1, "BA01");
750 ReadWriteXmlTestInternal (xml2, strtest2.ToString (), "BA02");