OleDbDataReader_Read.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //
  2. // Copyright (c) 2006 Mainsoft Co.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. using System;
  24. using System.Data;
  25. using System.Data.OleDb;
  26. using MonoTests.System.Data.Utils;
  27. using NUnit.Framework;
  28. namespace MonoTests.System.Data.OleDb
  29. {
  30. [TestFixture]
  31. public class OleDbDataReader_Read : ADONetTesterClass
  32. {
  33. OleDbConnection con;
  34. OleDbCommand cmd;
  35. [SetUp]
  36. public void SetUp()
  37. {
  38. Exception exp = null;
  39. BeginCase("Setup");
  40. try
  41. {
  42. con = new OleDbConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
  43. cmd = new OleDbCommand("", con);
  44. con.Open();
  45. //prepare data
  46. base.PrepareDataForTesting(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
  47. }
  48. catch(Exception ex) {exp = ex;}
  49. finally {EndCase(exp); exp = null;}
  50. }
  51. [TearDown]
  52. public void TearDown()
  53. {
  54. if (con != null && con.State != ConnectionState.Closed)
  55. con.Close();
  56. }
  57. public static void Main()
  58. {
  59. OleDbDataReader_Read tc = new OleDbDataReader_Read();
  60. Exception exp = null;
  61. try
  62. {
  63. tc.BeginTest("OleDbDataReader_Read");
  64. tc.SetUp();
  65. tc.run();
  66. tc.TearDown();
  67. }
  68. catch(Exception ex){exp = ex;}
  69. finally {tc.EndTest(exp);}
  70. }
  71. [Test]
  72. public void run()
  73. {
  74. Exception exp = null;
  75. cmd.CommandText = "Select EmployeeID, LastName, FirstName, Title, BirthDate From Employees where EmployeeID in (100,200) order by EmployeeID asc";
  76. OleDbDataReader rdr = cmd.ExecuteReader();
  77. try
  78. {
  79. BeginCase("first row");
  80. bool read = rdr.Read();
  81. Compare(read, true);
  82. }
  83. catch(Exception ex){exp = ex;}
  84. finally{EndCase(exp); exp = null;}
  85. try
  86. {
  87. BeginCase("first row - value");
  88. object obj = rdr.GetValue(0);
  89. Compare(obj.ToString(), "100");
  90. }
  91. catch(Exception ex){exp = ex;}
  92. finally{EndCase(exp); exp = null;}
  93. try
  94. {
  95. BeginCase("Second row");
  96. bool read = rdr.Read();
  97. Compare(read, true);
  98. }
  99. catch(Exception ex){exp = ex;}
  100. finally{EndCase(exp); exp = null;}
  101. try
  102. {
  103. BeginCase("Second row - value");
  104. object obj = rdr.GetValue(0);
  105. Compare(obj.ToString(), "200");
  106. }
  107. catch(Exception ex){exp = ex;}
  108. finally{EndCase(exp); exp = null;}
  109. try
  110. {
  111. BeginCase("End of data");
  112. bool read = rdr.Read();
  113. Compare(read, false);
  114. rdr.Close();
  115. }
  116. catch(Exception ex){exp = ex;}
  117. finally{EndCase(exp); exp = null;}
  118. try
  119. {
  120. BeginCase("Read return false");
  121. cmd.CommandText= "select * from Orders where OrderID=-909";
  122. rdr = cmd.ExecuteReader();
  123. Compare(rdr.Read(),false);
  124. rdr.Close();
  125. }
  126. catch(Exception ex){exp = ex;}
  127. finally{EndCase(exp); exp = null;}
  128. }
  129. }
  130. }