* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / FirebirdSql.Data.Firebird / Test / GuidTest.cs
1 /*
2  *  Firebird ADO.NET Data provider for .NET and Mono 
3  * 
4  *     The contents of this file are subject to the Initial 
5  *     Developer's Public License Version 1.0 (the "License"); 
6  *     you may not use this file except in compliance with the 
7  *     License. You may obtain a copy of the License at 
8  *     http://www.firebirdsql.org/index.php?op=doc&id=idpl
9  *
10  *     Software distributed under the License is distributed on 
11  *     an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either 
12  *     express or implied.  See the License for the specific 
13  *     language governing rights and limitations under the License.
14  * 
15  *  Copyright (c) 2002, 2005 Carlos Guzman Alvarez
16  *  All Rights Reserved.
17  */
18
19 using System;
20 using System.Data;
21 using FirebirdSql.Data.Firebird;
22 using NUnit.Framework;
23
24 namespace FirebirdSql.Data.Firebird.Tests
25 {
26         /// <summary>
27         /// All the test in this TestFixture are using implicit transaction support.
28         /// </summary>
29         [TestFixture]
30         public class GuidTest : BaseTest
31         {
32                 public GuidTest() : base()
33                 {
34                 }
35
36                 [Test]
37                 public void InsertGuidTest()
38                 {
39                         FbCommand createTable = new FbCommand("CREATE TABLE GUID_TEST (GUID_FIELD CHAR(16) CHARACTER SET OCTETS)", Connection);
40                         createTable.ExecuteNonQuery();
41                         createTable.Dispose();
42
43                         Guid newGuid = Guid.Empty;
44                         Guid guidValue = Guid.NewGuid();
45
46                         // Insert the Guid
47                         FbCommand insert = new FbCommand("INSERT INTO GUID_TEST (GUID_FIELD) VALUES (@GuidValue)", Connection);
48                         insert.Parameters.Add("@GuidValue", FbDbType.Guid).Value = guidValue;
49                         insert.ExecuteNonQuery();
50                         insert.Dispose();
51
52                         // Select the value
53                         FbCommand select = new FbCommand("SELECT * FROM GUID_TEST", Connection);
54                         FbDataReader r = select.ExecuteReader();
55                         if (r.Read())
56                         {
57                                 newGuid = r.GetGuid(0);
58                         }
59
60                         Assert.AreEqual(guidValue, newGuid);
61                 }
62
63                 [Test]
64                 public void InsertNullGuidTest()
65                 {
66                         FbCommand createTable = new FbCommand("CREATE TABLE GUID_TEST (INT_FIELD INTEGER, GUID_FIELD CHAR(16) CHARACTER SET OCTETS)", Connection);
67                         createTable.ExecuteNonQuery();
68                         createTable.Dispose();
69
70                         // Insert the Guid
71                         FbCommand insert = new FbCommand("INSERT INTO GUID_TEST (INT_FIELD, GUID_FIELD) VALUES (@IntField, @GuidValue)", Connection);
72                         insert.Parameters.Add("@IntField", FbDbType.Integer).Value = this.GetId();
73                         insert.Parameters.Add("@GuidValue", FbDbType.Guid).Value = DBNull.Value;
74                         insert.ExecuteNonQuery();
75                         insert.Dispose();
76
77                         // Select the value
78                         FbCommand select = new FbCommand("SELECT * FROM GUID_TEST", Connection);
79                         FbDataReader r = select.ExecuteReader();
80                         if (r.Read())
81                         {
82                                 if (!r.IsDBNull(1))
83                                 {
84                                         throw new Exception();
85                                 }
86                         }
87                 }
88         }
89 }