svn path=/branches/mono-1-1-9/mcs/; revision=51216
[mono.git] / mcs / class / System.Data / Test / ProviderTests / System.Data.SqlClient / SqlDataReaderTest.cs
1 //
2 // SqlDataReaderTest.cs - NUnit Test Cases for testing the
3 //                          SqlDataReader class
4 // Author:
5 //      Umadevi S (sumadevi@novell.com)
6 //      Kornél Pál <http://www.kornelpal.hu/>
7 //      Sureshkumar T (tsureshkumar@novell.com)
8 //
9 // Copyright (c) 2004 Novell Inc., and the individuals listed
10 // on the ChangeLog entries.
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 using System;
33 using System.Data;
34 using System.Data.Common;
35 using System.Data.SqlClient;
36
37 using NUnit.Framework;
38
39 namespace MonoTests.System.Data.SqlClient
40 {
41
42         [TestFixture]
43         [Category ("sqlserver")]
44         public class SqlDataReaderTest 
45         {
46                 SqlConnection conn;
47                 
48                 [Test]
49                 public void ReadEmptyNTextFieldTest () {
50                         conn = (SqlConnection) ConnectionManager.Singleton.Connection;
51                         try {
52                                 ConnectionManager.Singleton.OpenConnection ();
53                                 DBHelper.ExecuteNonQuery (conn, "create table #tmp_monotest (name ntext)");
54                                 DBHelper.ExecuteNonQuery (conn, "insert into #tmp_monotest values ('')");
55                                 
56                                 SqlCommand cmd = (SqlCommand) conn.CreateCommand ();
57                                 cmd.CommandText = "select * from #tmp_monotest";
58                                 SqlDataReader dr = cmd.ExecuteReader ();
59                                 if (dr.Read()) {
60                                         Assert.AreEqual("System.String",dr["NAME"].GetType().FullName);
61                                 }
62                                 Assert.AreEqual (false, dr.Read (), "#2");
63                         } finally {
64                                 ConnectionManager.Singleton.CloseConnection ();
65                         }
66                 }               
67
68                 [Test]
69                 public void ReadBingIntTest() 
70                 {
71                         conn = (SqlConnection) ConnectionManager.Singleton.Connection;
72                         try {
73                                 ConnectionManager.Singleton.OpenConnection ();
74                                 string query = "SELECT CAST(548967465189498 AS bigint) AS Value";
75                                 SqlCommand cmd = new SqlCommand();
76                                 cmd.Connection = conn;
77                                 cmd.CommandText = query;
78                                 SqlDataReader r = cmd.ExecuteReader();
79                                 using (r) {
80                                         Assert.AreEqual (true, r.Read(), "#1");
81                                         long id = r.GetInt64(0);
82                                         Assert.AreEqual(548967465189498, id, "#2");
83                                         id = r.GetSqlInt64(0).Value;
84                                         Assert.AreEqual(548967465189498, id, "#3");
85                                 }
86                         } finally {
87                                 ConnectionManager.Singleton.CloseConnection ();
88                         }
89                 }
90         }
91 }