2 // SqlCharsTest.cs - NUnit Test Cases for System.Data.SqlTypes.SqlChars
5 // Nagappan A (anagappan@novell.com)
8 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using NUnit.Framework;
35 using System.Data.SqlTypes;
36 using System.Threading;
37 using System.Globalization;
39 namespace MonoTests.System.Data.SqlTypes
42 public class SqlCharsTest
47 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
52 public void SqlCharsItem ()
54 SqlChars chars = new SqlChars ();
56 Assert.AreEqual (chars [0], 0, "#1 Should throw SqlNullValueException");
57 Assert.Fail ("Should throw SqlNullValueException");
58 } catch (Exception ex) {
59 Assert.AreEqual (typeof (SqlNullValueException), ex.GetType (), "Should throw SqlNullValueException");
62 chars = new SqlChars (b);
64 Assert.AreEqual (chars [0], 0, "#2 Should throw SqlNullValueException");
65 Assert.Fail ("Should throw SqlNullValueException");
66 } catch (Exception ex) {
67 Assert.AreEqual (typeof (SqlNullValueException), ex.GetType (), "Should throw SqlNullValueException");
70 chars = new SqlChars (b);
71 Assert.AreEqual (chars [0], 0, "");
73 Assert.AreEqual (chars [-1], 0, "");
74 Assert.Fail ("Should throw ArgumentOutOfRangeException");
75 } catch (Exception ex) {
76 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "Should throw ArgumentOutOfRangeException");
79 Assert.AreEqual (chars [10], 0, "");
80 Assert.Fail ("Should throw ArgumentOutOfRangeException");
81 } catch (Exception ex) {
82 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "Should throw ArgumentOutOfRangeException");
86 public void SqlCharsLength ()
89 SqlChars chars = new SqlChars ();
91 Assert.AreEqual (chars.Length, 0, "#1 Should throw SqlNullValueException");
92 Assert.Fail ("Should throw SqlNullValueException");
93 } catch (Exception ex) {
94 Assert.AreEqual (typeof (SqlNullValueException), ex.GetType (), "Should throw SqlNullValueException");
96 chars = new SqlChars (b);
98 Assert.AreEqual (chars.Length, 0, "#2 Should throw SqlNullValueException");
99 Assert.Fail ("Should throw SqlNullValueException");
100 } catch (Exception ex) {
101 Assert.AreEqual (typeof (SqlNullValueException), ex.GetType (), "Should throw SqlNullValueException");
104 chars = new SqlChars (b);
105 Assert.AreEqual (chars.Length, 10, "#3 Should be 10");
108 public void SqlCharsMaxLength ()
111 SqlChars chars = new SqlChars ();
112 Assert.AreEqual (chars.MaxLength, -1, "#1 Should return -1");
113 chars = new SqlChars (b);
114 Assert.AreEqual (chars.MaxLength, -1, "#2 Should return -1");
116 chars = new SqlChars (b);
117 Assert.AreEqual (chars.MaxLength, 10, "#3 Should return 10");
120 public void SqlCharsNull ()
123 SqlChars chars = SqlChars.Null;
124 Assert.AreEqual (chars.IsNull, true, "#1 Should return true");
127 public void SqlCharsStorage ()
130 SqlChars chars = new SqlChars ();
132 Assert.AreEqual (chars.Storage, StorageState.Buffer, "#1 Should throw SqlNullValueException");
133 Assert.Fail ("Should throw SqlNullValueException");
134 } catch (Exception ex) {
135 Assert.AreEqual (typeof (SqlNullValueException), ex.GetType (), "Should throw SqlNullValueException");
137 chars = new SqlChars (b);
139 Assert.AreEqual (chars.Storage, StorageState.Buffer, "#2 Should throw SqlNullValueException");
140 Assert.Fail ("Should throw SqlNullValueException");
141 } catch (Exception ex) {
142 Assert.AreEqual (typeof (SqlNullValueException), ex.GetType (), "Should throw SqlNullValueException");
145 chars = new SqlChars (b);
146 Assert.AreEqual (chars.Storage, StorageState.Buffer, "#3 Should be StorageState.Buffer");
149 public void SqlCharsValue ()
151 char [] b1 = new char [10];
152 SqlChars chars = new SqlChars (b1);
153 char [] b2 = chars.Value;
154 Assert.AreEqual (b1 [0], b2 [0], "#1 Should be same");
156 Assert.AreEqual (b1 [0], 0, "#2 Should be same");
157 Assert.AreEqual (b2 [0], '1', "#3 Should be same");
161 [Ignore ("Array.Resize(null) is not supported")]
163 public void SqlCharsSetLength ()
165 char [] b1 = new char [10];
166 SqlChars chars = new SqlChars ();
168 chars.SetLength (20);
169 Assert.Fail ("Should throw SqlTypeException");
170 } catch (Exception ex) {
171 Assert.AreEqual (typeof (SqlTypeException), ex.GetType (), "Should throw SqlTypeException");
173 chars = new SqlChars (b1);
174 Assert.AreEqual (chars.Length, 10, "#1 Should be same");
176 chars.SetLength (-1);
177 Assert.Fail ("Should throw ArgumentOutOfRangeException");
178 } catch (Exception ex) {
179 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "Should throw ArgumentOutOfRangeException");
182 chars.SetLength (11);
183 Assert.Fail ("Should throw ArgumentOutOfRangeException");
184 } catch (Exception ex) {
185 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "Should throw ArgumentOutOfRangeException");
188 Assert.AreEqual (chars.Length, 2, "#2 Should be same");
191 public void SqlCharsSetNull ()
193 char [] b1 = new char [10];
194 SqlChars chars = new SqlChars (b1);
195 Assert.AreEqual (chars.Length, 10, "#1 Should be same");
198 Assert.AreEqual (chars.Length, 10, "#1 Should not be same");
199 Assert.Fail ("Should throw SqlNullValueException");
200 } catch (Exception ex) {
201 Assert.AreEqual (typeof (SqlNullValueException), ex.GetType (), "Should throw SqlNullValueException");
203 Assert.AreEqual (true, chars.IsNull, "#2 Should be same");