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 {
\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 Assert.Fail ("#A01 " + e);
\r
105 // Test public fields
\r
107 public void PublicFields()
\r
109 Assert.IsTrue (SqlGuid.Null.IsNull, "#B01");
\r
114 public void Properties()
\r
116 Guid ResultGuid = new Guid ("00000f64-0000-0000-0000-000000000000");
\r
117 Assert.IsTrue (!Test1.IsNull, "#C01");
\r
118 Assert.IsTrue (SqlGuid.Null.IsNull, "#C02");
\r
119 Assert.AreEqual (ResultGuid, Test2.Value, "#C03");
\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.IsTrue (Test1.CompareTo (Test3) < 0, "#D01");
\r
131 Assert.IsTrue (Test4.CompareTo (Test1) > 0, "#D02");
\r
132 Assert.IsTrue (Test3.CompareTo (Test2) == 0, "#D03");
\r
133 Assert.IsTrue (Test4.CompareTo (SqlGuid.Null) > 0, "#D04");
\r
134 Assert.IsTrue (test1.CompareTo (test2) > 0, "#D05");
\r
135 Assert.IsTrue (test3.CompareTo (test2) < 0, "#D06");
\r
138 Test1.CompareTo (TestString);
\r
139 Assert.Fail("#D05");
\r
140 } catch(Exception e) {
\r
141 Assert.AreEqual (typeof (ArgumentException), e.GetType (), "#D06");
\r
146 public void EqualsMethods()
\r
148 Assert.IsTrue (!Test1.Equals (Test2), "#E01");
\r
149 Assert.IsTrue (!Test2.Equals (Test4), "#E02");
\r
150 Assert.IsTrue (!Test2.Equals (new SqlString ("TEST")), "#E03");
\r
151 Assert.IsTrue (Test2.Equals (Test3), "#E04");
\r
153 // Static Equals()-method
\r
154 Assert.IsTrue (SqlGuid.Equals (Test2, Test3).Value, "#E05");
\r
155 Assert.IsTrue (!SqlGuid.Equals (Test1, Test2).Value, "#E06");
\r
159 public void GetHashCodeTest()
\r
161 Assert.AreEqual (Test1.GetHashCode (), Test1.GetHashCode (), "#F01");
\r
162 Assert.IsTrue (Test1.GetHashCode () != Test2.GetHashCode (), "#F02");
\r
163 Assert.AreEqual (Test3.GetHashCode (), Test2.GetHashCode (), "#F02");
\r
167 public void GetTypeTest()
\r
169 Assert.AreEqual ("System.Data.SqlTypes.SqlGuid", Test1.GetType ().ToString (), "#G01");
\r
170 Assert.AreEqual ("System.Guid", Test3.Value.GetType ().ToString (), "#G02");
\r
174 public void Greaters()
\r
177 Assert.IsTrue (!SqlGuid.GreaterThan (Test1, Test2).Value, "#H01");
\r
178 Assert.IsTrue (SqlGuid.GreaterThan (Test2, Test1).Value, "#H02");
\r
179 Assert.IsTrue (!SqlGuid.GreaterThan (Test2, Test3).Value, "#H03");
\r
180 // GreaterTharOrEqual ()
\r
181 Assert.IsTrue (!SqlGuid.GreaterThanOrEqual (Test1, Test2).Value, "#H04");
\r
182 Assert.IsTrue (SqlGuid.GreaterThanOrEqual (Test2, Test1).Value, "#H05");
\r
183 Assert.IsTrue (SqlGuid.GreaterThanOrEqual (Test2, Test3).Value, "#H06");
\r
187 public void Lessers()
\r
190 Assert.IsTrue (!SqlGuid.LessThan (Test2, Test3).Value, "#I01");
\r
191 Assert.IsTrue (!SqlGuid.LessThan (Test2, Test1).Value, "#I02");
\r
192 Assert.IsTrue (SqlGuid.LessThan (Test1, Test2).Value, "#I03");
\r
194 // LessThanOrEqual ()
\r
195 Assert.IsTrue (SqlGuid.LessThanOrEqual (Test1, Test2).Value, "#I04");
\r
196 Assert.IsTrue (!SqlGuid.LessThanOrEqual (Test2, Test1).Value, "#I05");
\r
197 Assert.IsTrue (SqlGuid.LessThanOrEqual (Test2, Test3).Value, "#I06");
\r
198 Assert.IsTrue (SqlGuid.LessThanOrEqual (Test4, SqlGuid.Null).IsNull, "#I07");
\r
202 public void NotEquals()
\r
204 Assert.IsTrue (SqlGuid.NotEquals (Test1, Test2).Value, "#J01");
\r
205 Assert.IsTrue (SqlGuid.NotEquals (Test2, Test1).Value, "#J02");
\r
206 Assert.IsTrue (SqlGuid.NotEquals (Test3, Test1).Value, "#J03");
\r
207 Assert.IsTrue (!SqlGuid.NotEquals (Test3, Test2).Value, "#J04");
\r
208 Assert.IsTrue (SqlGuid.NotEquals (SqlGuid.Null, Test2).IsNull, "#J05");
\r
212 public void Parse()
\r
215 SqlGuid.Parse (null);
\r
216 Assert.Fail ("#K01");
\r
217 } catch (Exception e) {
\r
218 Assert.AreEqual (typeof (ArgumentNullException), e.GetType (), "#K02");
\r
222 SqlGuid.Parse ("not-a-number");
\r
223 Assert.Fail ("#K03");
\r
224 } catch (Exception e) {
\r
225 Assert.AreEqual (typeof (FormatException), e.GetType (), "#K04");
\r
229 SqlGuid.Parse ("9e400");
\r
230 Assert.Fail ("#K05");
\r
231 } catch (Exception e) {
\r
232 Assert.AreEqual (typeof (FormatException), e.GetType (), "#K06");
\r
235 Assert.AreEqual(new Guid("87654321-0000-0000-0000-000000000000"), SqlGuid.Parse ("87654321-0000-0000-0000-000000000000").Value, "#K07");
\r
239 public void Conversions()
\r
242 Assert.AreEqual ((byte)1, Test1.ToByteArray () [0], "#L01");
\r
243 Assert.AreEqual ((byte)15, Test2.ToByteArray () [1], "#L02");
\r
246 byte [] b = new byte [2];
\r
250 Assert.AreEqual (new SqlBinary (b), Test3.ToSqlBinary (), "#L03");
\r
253 Assert.AreEqual ("00000a01-0000-0000-0000-000000000000", Test1.ToSqlString ().Value, "#L04");
\r
254 Assert.AreEqual ("0000fafa-0000-0000-0000-000000000000", Test4.ToSqlString ().Value, "#L05");
\r
257 Assert.AreEqual ("00000a01-0000-0000-0000-000000000000", Test1.ToString (), "#L06");
\r
258 Assert.AreEqual ("0000fafa-0000-0000-0000-000000000000", Test4.ToString (), "#L07");
\r
264 public void ThanOrEqualOperators()
\r
267 Assert.IsTrue ((Test3 == Test2).Value, "#M01");
\r
268 Assert.IsTrue (!(Test1 == Test2).Value, "#M02");
\r
269 Assert.IsTrue ((Test1 == SqlGuid.Null).IsNull, "#M03");
\r
272 Assert.IsTrue (!(Test2 != Test3).Value, "#M04");
\r
273 Assert.IsTrue ((Test1 != Test3).Value, "#M05");
\r
274 Assert.IsTrue ((Test1 != SqlGuid.Null).IsNull, "#M06");
\r
277 Assert.IsTrue ((Test2 > Test1).Value, "#M07");
\r
278 Assert.IsTrue (!(Test1 > Test3).Value, "#M08");
\r
279 Assert.IsTrue (!(Test3 > Test2).Value, "#M09");
\r
280 Assert.IsTrue ((Test1 > SqlGuid.Null).IsNull, "#M10");
\r
283 Assert.IsTrue (!(Test1 >= Test3).Value, "#M12");
\r
284 Assert.IsTrue ((Test3 >= Test1).Value, "#M13");
\r
285 Assert.IsTrue ((Test3 >= Test2).Value, "#M14");
\r
286 Assert.IsTrue ((Test1 >= SqlGuid.Null).IsNull, "#M15");
\r
289 Assert.IsTrue (!(Test2 < Test1).Value, "#M16");
\r
290 Assert.IsTrue ((Test1 < Test3).Value, "#M17");
\r
291 Assert.IsTrue (!(Test2 < Test3).Value, "#M18");
\r
292 Assert.IsTrue ((Test1 < SqlGuid.Null).IsNull, "#M19");
\r
295 Assert.IsTrue ((Test1 <= Test3).Value, "#M20");
\r
296 Assert.IsTrue (!(Test3 <= Test1).Value, "#M21");
\r
297 Assert.IsTrue ((Test2 <= Test3).Value, "#M22");
\r
298 Assert.IsTrue ((Test1 <= SqlGuid.Null).IsNull, "#M23");
\r
302 public void SqlBinaryToSqlGuid()
\r
304 byte [] b = new byte [16];
\r
307 SqlBinary TestBinary = new SqlBinary (b);
\r
309 Assert.AreEqual (new Guid("0000c864-0000-0000-0000-000000000000"), ((SqlGuid)TestBinary).Value, "#N01");
\r
313 public void SqlGuidToGuid()
\r
315 Assert.AreEqual (new Guid("00000a01-0000-0000-0000-000000000000"), (Guid)Test1, "#O01");
\r
316 Assert.AreEqual (new Guid("00000f64-0000-0000-0000-000000000000"), (Guid)Test2, "#O02");
\r
320 public void SqlStringToSqlGuid()
\r
322 SqlString TestString = new SqlString ("Test string");
\r
323 SqlString TestString100 = new SqlString ("0000c864-0000-0000-0000-000000000000");
\r
325 Assert.AreEqual (new Guid("0000c864-0000-0000-0000-000000000000"), ((SqlGuid)TestString100).Value, "#P01");
\r
328 SqlGuid test = (SqlGuid)TestString;
\r
329 Assert.Fail ("#P02");
\r
330 } catch(Exception e) {
\r
331 Assert.AreEqual (typeof (FormatException), e.GetType (), "#P03");
\r
336 public void GuidToSqlGuid()
\r
338 Guid TestGuid = new Guid("0000c864-0000-0000-0000-000007650000");
\r
339 Assert.AreEqual (new SqlGuid("0000c864-0000-0000-0000-000007650000"), (SqlGuid)TestGuid, "#Q01");
\r
343 public void GetXsdTypeTest ()
\r
345 XmlQualifiedName qualifiedName = SqlGuid.GetXsdType (null);
\r
346 Assert.AreEqual ("string", qualifiedName.Name, "#A01");
\r