**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Data / Test / System.Data.Odbc / OdbcCommandTest.cs
blob78ebeb4ab72249b01df85225f0ec2bba256e8279
1 //
2 // OdbcCommandTest.cs - NUnit Test Cases for testing the
3 // OdbcCommand class
4 //
5 // Authors:
6 // Sureshkumar T (TSureshkumar@novell.com)
7 // Umadevi S (sumadevi@novell.com)
8 //
9 // Copyright (c) 2004 Novell Inc., and the individuals listed
10 // on the ChangeLog entries.
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:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
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.
33 using System;
34 using System.Data;
35 using System.Data.Odbc;
37 using NUnit.Framework;
39 namespace MonoTests.System.Data.Odbc
42 [TestFixture]
43 public class OdbcCommandTest : MySqlOdbcBaseClient
46 [SetUp]
47 public void GetReady () {
48 OpenConnection ();
49 CreateTestSetup (); // create database & test tables
52 [TearDown]
53 public void Clean () {
54 CleanTestSetup (); // clean test database;
55 CloseConnection ();
58 /// <summary>
59 /// Test Execute Scalar Method
60 /// </summary>
61 [Test]
62 public void ExecuteScalarTest ()
64 OdbcCommand cmd = conn.CreateCommand ();
65 string query = "select count(*) from test order by col_int;";
66 cmd.CommandText = query;
67 object objCount = cmd.ExecuteScalar ();
68 Assertion.AssertEquals( "ExecuteScalar does not return int type", 5, Convert.ToInt32(objCount));
71 /// <summary>
72 /// Test String parameters to ODBC Command
73 /// </summary>
74 [Test]
75 public void ExecuteStringParameterTest()
78 OdbcCommand dbcmd = new OdbcCommand();
79 dbcmd.Connection = conn;
80 dbcmd.CommandType = CommandType.Text;
81 dbcmd.CommandText = "select count(*) from test where col_char=?;";
82 string colvalue = "mono test#1";
83 dbcmd.Parameters.Add("@un",colvalue);
84 Object obj = dbcmd.ExecuteScalar();
85 Assertion.AssertEquals( "String parameter not passed correctly",1, Convert.ToInt32(obj));
90 /// <summary>
91 /// Test ExecuteNonQuery
92 /// </summary>
93 [Test]
94 public void ExecuteNonQueryTest ()
97 OdbcCommand dbcmd = new OdbcCommand();
98 dbcmd.Connection = conn;
99 dbcmd.CommandType = CommandType.Text;
100 dbcmd.CommandText = "select count(*) from test where col_char=?;";
101 string colvalue = "mono test";
102 dbcmd.Parameters.Add("@un",colvalue);
103 int ret = dbcmd.ExecuteNonQuery();
104 Assertion.AssertEquals( "ExecuteNonQuery not working",-1, ret);
105 dbcmd = new OdbcCommand();
106 dbcmd.Connection = conn;
107 dbcmd.CommandType = CommandType.Text;
108 dbcmd.CommandText = "delete from test where (col_int >257);";
109 ret = dbcmd.ExecuteNonQuery();
110 Assertion.AssertEquals("ExecuteNonQuery not working", 2, ret);