2
0

SqlDataReaderTest.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // SqlDataReaderTest.cs - NUnit Test Cases for testing the
  3. // SqlDataReader class
  4. // Author:
  5. // Umadevi S ([email protected])
  6. // Kornél Pál <http://www.kornelpal.hu/>
  7. // Sureshkumar T ([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.Common;
  34. using System.Data.SqlClient;
  35. using NUnit.Framework;
  36. namespace MonoTests.System.Data.SqlClient
  37. {
  38. [TestFixture]
  39. [Category ("sqlserver")]
  40. public class SqlDataReaderTest
  41. {
  42. SqlConnection conn;
  43. [Test]
  44. public void ReadEmptyNTextFieldTest () {
  45. conn = (SqlConnection) ConnectionManager.Singleton.Connection;
  46. try {
  47. ConnectionManager.Singleton.OpenConnection ();
  48. DBHelper.ExecuteNonQuery (conn, "create table #tmp_monotest (name ntext)");
  49. DBHelper.ExecuteNonQuery (conn, "insert into #tmp_monotest values ('')");
  50. SqlCommand cmd = (SqlCommand) conn.CreateCommand ();
  51. cmd.CommandText = "select * from #tmp_monotest";
  52. SqlDataReader dr = cmd.ExecuteReader ();
  53. if (dr.Read()) {
  54. Assert.AreEqual("System.String",dr["NAME"].GetType().FullName);
  55. }
  56. Assert.AreEqual (false, dr.Read (), "#2");
  57. } finally {
  58. ConnectionManager.Singleton.CloseConnection ();
  59. }
  60. }
  61. [Test]
  62. public void ReadBingIntTest()
  63. {
  64. conn = (SqlConnection) ConnectionManager.Singleton.Connection;
  65. try {
  66. ConnectionManager.Singleton.OpenConnection ();
  67. string query = "SELECT CAST(548967465189498 AS bigint) AS Value";
  68. SqlCommand cmd = new SqlCommand();
  69. cmd.Connection = conn;
  70. cmd.CommandText = query;
  71. SqlDataReader r = cmd.ExecuteReader();
  72. using (r) {
  73. Assert.AreEqual (true, r.Read(), "#1");
  74. long id = r.GetInt64(0);
  75. Assert.AreEqual(548967465189498, id, "#2");
  76. id = r.GetSqlInt64(0).Value;
  77. Assert.AreEqual(548967465189498, id, "#3");
  78. }
  79. } finally {
  80. ConnectionManager.Singleton.CloseConnection ();
  81. }
  82. }
  83. }
  84. }