OdbcDataReaderTest.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // OdbcDataReaderTest.cs - NUnit Test Cases for testing the
  3. // OdbcDataReader class
  4. //
  5. // Author:
  6. // Sureshkumar T ([email protected])
  7. //
  8. // Copyright (c) 2004 Novell Inc., and the individuals listed
  9. // on the ChangeLog entries.
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System;
  31. using System.Data;
  32. using System.Data.Common;
  33. using System.Data.Odbc;
  34. using Mono.Data;
  35. using NUnit.Framework;
  36. namespace MonoTests.System.Data
  37. {
  38. [TestFixture]
  39. [Category ("odbc")]
  40. public class OdbcDataReaderTest
  41. {
  42. [Test]
  43. public void OutputParametersTest ()
  44. {
  45. IDbConnection conn = ConnectionManager.Singleton.Connection;
  46. try {
  47. ConnectionManager.Singleton.OpenConnection ();
  48. IDbCommand cmd = conn.CreateCommand ();
  49. cmd.CommandText = "call {? = sp_get_age (?,?)}";
  50. OdbcParameter ret = (OdbcParameter) new OdbcParameter ("ret", OdbcType.Int);
  51. cmd.Parameters.Add (ret);
  52. ret.Direction = ParameterDirection.ReturnValue;
  53. OdbcParameter name = (OdbcParameter) new OdbcParameter ("name", OdbcType.VarChar);
  54. cmd.Parameters.Add (name);
  55. name.Direction = ParameterDirection.Input;
  56. name.Value = "suresh";
  57. OdbcParameter age = (OdbcParameter) new OdbcParameter ("age", OdbcType.Int);
  58. cmd.Parameters.Add (age);
  59. name.Direction = ParameterDirection.Output;
  60. IDataReader reader = cmd.ExecuteReader ();
  61. reader.Close ();
  62. Assert.AreEqual (true, ((int) ret.Value) > 0, "#1");
  63. } finally {
  64. ConnectionManager.Singleton.CloseConnection ();
  65. }
  66. }
  67. [Test]
  68. public void LongTextTest ()
  69. {
  70. IDbConnection conn = new OdbcConnection (
  71. ConnectionManager.Singleton.ConnectionString);
  72. IDataReader rdr = null;
  73. try {
  74. conn.Open ();
  75. IDbCommand cmd = conn.CreateCommand ();
  76. cmd.CommandText = "Select type_text";
  77. cmd.CommandText += " from string_family where id=3";
  78. rdr = cmd.ExecuteReader ();
  79. rdr.Read ();
  80. rdr.GetValue (0);
  81. }finally {
  82. if (rdr != null)
  83. rdr.Close ();
  84. conn.Close ();
  85. }
  86. }
  87. }
  88. }