2 // SqlGuidTest.cs - NUnit Test Cases for System.Data.SqlTypes.SqlGuid
\r
5 // Ville Palo (vi64pa@koti.soon.fi)
\r
6 // Martin Willemoes Hansen (mwh@sysrq.dk)
\r
8 // (C) 2002 Ville Palo
\r
9 // (C) 2003 Martin Willemoes Hansen
\r
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
\r
15 // Permission is hereby granted, free of charge, to any person obtaining
\r
16 // a copy of this software and associated documentation files (the
\r
17 // "Software"), to deal in the Software without restriction, including
\r
18 // without limitation the rights to use, copy, modify, merge, publish,
\r
19 // distribute, sublicense, and/or sell copies of the Software, and to
\r
20 // permit persons to whom the Software is furnished to do so, subject to
\r
21 // the following conditions:
\r
23 // The above copyright notice and this permission notice shall be
\r
24 // included in all copies or substantial portions of the Software.
\r
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
35 using NUnit.Framework;
\r
38 using System.Data.SqlTypes;
\r
40 namespace MonoTests.System.Data.SqlTypes
\r
43 public class SqlGuidTest : Assertion {
\r
45 // 00000a01-0000-0000-0000-000000000000
\r
46 private SqlGuid Test1;
\r
48 // 00000f64-0000-0000-0000-000000000000
\r
49 private SqlGuid Test2;
\r
50 private SqlGuid Test3;
\r
52 // 0000fafa-0000-0000-0000-000000000000
\r
53 private SqlGuid Test4;
\r
56 public void GetReady()
\r
58 byte [] b1 = new byte [16];
\r
59 byte [] b2 = new byte [16];
\r
60 byte [] b3 = new byte [16];
\r
61 byte [] b4 = new byte [16];
\r
72 Test1 = new SqlGuid (b1);
\r
73 Test2 = new SqlGuid (b2);
\r
74 Test3 = new SqlGuid (b3);
\r
75 Test4 = new SqlGuid (b4);
\r
80 public void Create()
\r
83 byte [] b = new byte [16];
\r
88 SqlGuid Test = new SqlGuid (b);
\r
91 Guid TestGuid = new Guid (b);
\r
92 Test = new SqlGuid (TestGuid);
\r
95 Test = new SqlGuid ("12345678-1234-1234-1234-123456789012");
\r
97 // SqlGuid (int, short, short, byte, byte, byte, byte, byte, byte, byte, byte)
\r
98 Test = new SqlGuid (10, 1, 2, 13, 14, 15, 16, 17, 19, 20 ,21);
\r
100 } catch (Exception e) {
\r
101 Fail ("#A01 " + e);
\r
105 // Test public fields
\r
107 public void PublicFields()
\r
109 Assert ("#B01", SqlGuid.Null.IsNull);
\r
114 public void Properties()
\r
116 Guid ResultGuid = new Guid ("00000f64-0000-0000-0000-000000000000");
\r
117 Assert ("#C01", !Test1.IsNull);
\r
118 Assert ("#C02", SqlGuid.Null.IsNull);
\r
119 AssertEquals ("#C03", ResultGuid, Test2.Value);
\r
124 public void CompareTo()
\r
126 String TestString = "This is a test string";
\r
127 SqlGuid test1 = new SqlGuid("1AAAAAAA-BBBB-CCCC-DDDD-3EEEEEEEEEEE");
\r
128 SqlGuid test2 = new SqlGuid("1AAAAAAA-BBBB-CCCC-DDDD-2EEEEEEEEEEE");
\r
129 SqlGuid test3 = new SqlGuid("1AAAAAAA-BBBB-CCCC-DDDD-1EEEEEEEEEEE");
\r
130 Assert ("#D01", Test1.CompareTo (Test3) < 0);
\r
131 Assert ("#D02", Test4.CompareTo (Test1) > 0);
\r
132 Assert ("#D03", Test3.CompareTo (Test2) == 0);
\r
133 Assert ("#D04", Test4.CompareTo (SqlGuid.Null) > 0);
\r
134 Assert ("#D05", test1.CompareTo (test2) > 0);
\r
135 Assert ("#D06", test3.CompareTo (test2) < 0);
\r
138 Test1.CompareTo (TestString);
\r
140 } catch(Exception e) {
\r
141 AssertEquals ("#D06", typeof (ArgumentException), e.GetType ());
\r
146 public void EqualsMethods()
\r
148 Assert ("#E01", !Test1.Equals (Test2));
\r
149 Assert ("#E02", !Test2.Equals (Test4));
\r
150 Assert ("#E03", !Test2.Equals (new SqlString ("TEST")));
\r
151 Assert ("#E04", Test2.Equals (Test3));
\r
153 // Static Equals()-method
\r
154 Assert ("#E05", SqlGuid.Equals (Test2, Test3).Value);
\r
155 Assert ("#E06", !SqlGuid.Equals (Test1, Test2).Value);
\r
159 public void GetHashCodeTest()
\r
161 AssertEquals ("#F01", Test1.GetHashCode (), Test1.GetHashCode ());
\r
162 Assert ("#F02", Test1.GetHashCode () != Test2.GetHashCode ());
\r
163 AssertEquals ("#F02", Test3.GetHashCode (), Test2.GetHashCode ());
\r
167 public void GetTypeTest()
\r
169 AssertEquals ("#G01", "System.Data.SqlTypes.SqlGuid", Test1.GetType ().ToString ());
\r
170 AssertEquals ("#G02", "System.Guid", Test3.Value.GetType ().ToString ());
\r
174 public void Greaters()
\r
177 Assert ("#H01", !SqlGuid.GreaterThan (Test1, Test2).Value);
\r
178 Assert ("#H02", SqlGuid.GreaterThan (Test2, Test1).Value);
\r
179 Assert ("#H03", !SqlGuid.GreaterThan (Test2, Test3).Value);
\r
180 // GreaterTharOrEqual ()
\r
181 Assert ("#H04", !SqlGuid.GreaterThanOrEqual (Test1, Test2).Value);
\r
182 Assert ("#H05", SqlGuid.GreaterThanOrEqual (Test2, Test1).Value);
\r
183 Assert ("#H06", SqlGuid.GreaterThanOrEqual (Test2, Test3).Value);
\r
187 public void Lessers()
\r
190 Assert ("#I01", !SqlGuid.LessThan (Test2, Test3).Value);
\r
191 Assert ("#I02", !SqlGuid.LessThan (Test2, Test1).Value);
\r
192 Assert ("#I03", SqlGuid.LessThan (Test1, Test2).Value);
\r
194 // LessThanOrEqual ()
\r
195 Assert ("#I04", SqlGuid.LessThanOrEqual (Test1, Test2).Value);
\r
196 Assert ("#I05", !SqlGuid.LessThanOrEqual (Test2, Test1).Value);
\r
197 Assert ("#I06", SqlGuid.LessThanOrEqual (Test2, Test3).Value);
\r
198 Assert ("#I07", SqlGuid.LessThanOrEqual (Test4, SqlGuid.Null).IsNull);
\r
202 public void NotEquals()
\r
204 Assert ("#J01", SqlGuid.NotEquals (Test1, Test2).Value);
\r
205 Assert ("#J02", SqlGuid.NotEquals (Test2, Test1).Value);
\r
206 Assert ("#J03", SqlGuid.NotEquals (Test3, Test1).Value);
\r
207 Assert ("#J04", !SqlGuid.NotEquals (Test3, Test2).Value);
\r
208 Assert ("#J05", SqlGuid.NotEquals (SqlGuid.Null, Test2).IsNull);
\r
212 public void Parse()
\r
215 SqlGuid.Parse (null);
\r
217 } catch (Exception e) {
\r
218 AssertEquals ("#K02", typeof (ArgumentNullException), e.GetType ());
\r
222 SqlGuid.Parse ("not-a-number");
\r
224 } catch (Exception e) {
\r
225 AssertEquals ("#K04", typeof (FormatException), e.GetType ());
\r
229 SqlGuid.Parse ("9e400");
\r
231 } catch (Exception e) {
\r
232 AssertEquals ("#K06", typeof (FormatException), e.GetType ());
\r
235 AssertEquals("#K07", new Guid("87654321-0000-0000-0000-000000000000"),
\r
236 SqlGuid.Parse ("87654321-0000-0000-0000-000000000000").Value);
\r
240 public void Conversions()
\r
243 AssertEquals ("#L01", (byte)1, Test1.ToByteArray () [0]);
\r
244 AssertEquals ("#L02", (byte)15, Test2.ToByteArray () [1]);
\r
247 byte [] b = new byte [2];
\r
251 AssertEquals ("#L03", new SqlBinary (b), Test3.ToSqlBinary ());
\r
254 AssertEquals ("#L04", "00000a01-0000-0000-0000-000000000000",
\r
255 Test1.ToSqlString ().Value);
\r
256 AssertEquals ("#L05", "0000fafa-0000-0000-0000-000000000000",
\r
257 Test4.ToSqlString ().Value);
\r
260 AssertEquals ("#L06", "00000a01-0000-0000-0000-000000000000",
\r
261 Test1.ToString ());
\r
262 AssertEquals ("#L07", "0000fafa-0000-0000-0000-000000000000",
\r
263 Test4.ToString ());
\r
269 public void ThanOrEqualOperators()
\r
272 Assert ("#M01", (Test3 == Test2).Value);
\r
273 Assert ("#M02", !(Test1 == Test2).Value);
\r
274 Assert ("#M03", (Test1 == SqlGuid.Null).IsNull);
\r
277 Assert ("#M04", !(Test2 != Test3).Value);
\r
278 Assert ("#M05", (Test1 != Test3).Value);
\r
279 Assert ("#M06", (Test1 != SqlGuid.Null).IsNull);
\r
282 Assert ("#M07", (Test2 > Test1).Value);
\r
283 Assert ("#M08", !(Test1 > Test3).Value);
\r
284 Assert ("#M09", !(Test3 > Test2).Value);
\r
285 Assert ("#M10", (Test1 > SqlGuid.Null).IsNull);
\r
288 Assert ("#M12", !(Test1 >= Test3).Value);
\r
289 Assert ("#M13", (Test3 >= Test1).Value);
\r
290 Assert ("#M14", (Test3 >= Test2).Value);
\r
291 Assert ("#M15", (Test1 >= SqlGuid.Null).IsNull);
\r
294 Assert ("#M16", !(Test2 < Test1).Value);
\r
295 Assert ("#M17", (Test1 < Test3).Value);
\r
296 Assert ("#M18", !(Test2 < Test3).Value);
\r
297 Assert ("#M19", (Test1 < SqlGuid.Null).IsNull);
\r
300 Assert ("#M20", (Test1 <= Test3).Value);
\r
301 Assert ("#M21", !(Test3 <= Test1).Value);
\r
302 Assert ("#M22", (Test2 <= Test3).Value);
\r
303 Assert ("#M23", (Test1 <= SqlGuid.Null).IsNull);
\r
307 public void SqlBinaryToSqlGuid()
\r
309 byte [] b = new byte [16];
\r
312 SqlBinary TestBinary = new SqlBinary (b);
\r
314 AssertEquals ("#N01", new Guid("0000c864-0000-0000-0000-000000000000"),
\r
315 ((SqlGuid)TestBinary).Value);
\r
319 public void SqlGuidToGuid()
\r
321 AssertEquals ("#O01", new Guid("00000a01-0000-0000-0000-000000000000"),
\r
323 AssertEquals ("#O02", new Guid("00000f64-0000-0000-0000-000000000000"),
\r
328 public void SqlStringToSqlGuid()
\r
330 SqlString TestString = new SqlString ("Test string");
\r
331 SqlString TestString100 = new SqlString ("0000c864-0000-0000-0000-000000000000");
\r
333 AssertEquals ("#P01", new Guid("0000c864-0000-0000-0000-000000000000"),
\r
334 ((SqlGuid)TestString100).Value);
\r
337 SqlGuid test = (SqlGuid)TestString;
\r
339 } catch(Exception e) {
\r
340 AssertEquals ("#P03", typeof (FormatException), e.GetType ());
\r
345 public void GuidToSqlGuid()
\r
347 Guid TestGuid = new Guid("0000c864-0000-0000-0000-000007650000");
\r
348 AssertEquals ("#Q01", new SqlGuid("0000c864-0000-0000-0000-000007650000"),
\r
349 (SqlGuid)TestGuid);
\r
353 public void GetXsdTypeTest ()
\r
355 XmlQualifiedName qualifiedName = SqlGuid.GetXsdType (null);
\r
356 NUnit.Framework.Assert.AreEqual ("string", qualifiedName.Name, "#A01");
\r