OdbcCommandTest.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // OdbcCommandTest.cs - NUnit Test Cases for testing the
  3. // OdbcCommand class
  4. //
  5. // Authors:
  6. // Sureshkumar T ([email protected])
  7. // Umadevi S ([email protected])
  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. using System;
  32. using System.Data;
  33. using System.Data.Odbc;
  34. using NUnit.Framework;
  35. namespace MonoTests.System.Data.Odbc
  36. {
  37. [TestFixture]
  38. public class OdbcCommandTest : MySqlOdbcBaseClient
  39. {
  40. [SetUp]
  41. public void GetReady () {
  42. OpenConnection ();
  43. CreateTestSetup (); // create database & test tables
  44. }
  45. [TearDown]
  46. public void Clean () {
  47. CleanTestSetup (); // clean test database;
  48. CloseConnection ();
  49. }
  50. /// <summary>
  51. /// Test Execute Scalar Method
  52. /// </summary>
  53. [Test]
  54. public void ExecuteScalarTest ()
  55. {
  56. OdbcCommand cmd = conn.CreateCommand ();
  57. string query = "select count(*) from test order by col_int;";
  58. cmd.CommandText = query;
  59. object objCount = cmd.ExecuteScalar ();
  60. Assertion.AssertEquals( "ExecuteScalar does not return int type", 5, Convert.ToInt32(objCount));
  61. }
  62. /// <summary>
  63. /// Test String parameters to ODBC Command
  64. /// </summary>
  65. [Test]
  66. public void ExecuteStringParameterTest()
  67. {
  68. OdbcCommand dbcmd = new OdbcCommand();
  69. dbcmd.Connection = conn;
  70. dbcmd.CommandType = CommandType.Text;
  71. dbcmd.CommandText = "select count(*) from test where col_char=?;";
  72. string colvalue = "mono test#1";
  73. dbcmd.Parameters.Add("@un",colvalue);
  74. Object obj = dbcmd.ExecuteScalar();
  75. Assertion.AssertEquals( "String parameter not passed correctly",1, Convert.ToInt32(obj));
  76. }
  77. /// <summary>
  78. /// Test ExecuteNonQuery
  79. /// </summary>
  80. [Test]
  81. public void ExecuteNonQueryTest ()
  82. {
  83. OdbcCommand dbcmd = new OdbcCommand();
  84. dbcmd.Connection = conn;
  85. dbcmd.CommandType = CommandType.Text;
  86. dbcmd.CommandText = "select count(*) from test where col_char=?;";
  87. string colvalue = "mono test";
  88. dbcmd.Parameters.Add("@un",colvalue);
  89. int ret = dbcmd.ExecuteNonQuery();
  90. Assertion.AssertEquals( "ExecuteNonQuery not working",-1, ret);
  91. dbcmd = new OdbcCommand();
  92. dbcmd.Connection = conn;
  93. dbcmd.CommandType = CommandType.Text;
  94. dbcmd.CommandText = "delete from test where (col_int >257);";
  95. ret = dbcmd.ExecuteNonQuery();
  96. Assertion.AssertEquals("ExecuteNonQuery not working", 2, ret);
  97. }
  98. }
  99. }