OleDbDataReader_HasRows.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 MonoTests.System.Data.Utils.Data;
  28. using NUnit.Framework;
  29. namespace MonoTests.System.Data.OleDb
  30. {
  31. [TestFixture]
  32. public class OleDbDataReader_HasRows : GHTBase
  33. {
  34. Exception exp;
  35. public static void Main()
  36. {
  37. OleDbDataReader_HasRows tc = new OleDbDataReader_HasRows();
  38. tc.exp = null;
  39. try
  40. {
  41. tc.BeginTest("OleDbDataReader_HasRows");
  42. tc.run();
  43. }
  44. catch(Exception ex)
  45. {
  46. tc.exp = ex;
  47. }
  48. finally
  49. {
  50. tc.EndTest(tc.exp);
  51. }
  52. }
  53. public void run()
  54. {
  55. TestHasRowsTrue();
  56. TestHasRowsFalse();
  57. }
  58. [Test]
  59. public void TestHasRowsTrue()
  60. {
  61. BeginCase("Test HasRows = True");
  62. exp = null;
  63. string rowId = string.Format("43977_{0}", TestCaseNumber);
  64. OleDbConnection con = null;
  65. OleDbDataReader rdr = null;
  66. try
  67. {
  68. DbTypeParametersCollection row = ConnectedDataProvider.GetSimpleDbTypesParameters();
  69. row.ExecuteInsert(rowId);
  70. row.ExecuteSelectReader(rowId, out rdr, out con);
  71. Compare(rdr.HasRows, true);
  72. }
  73. catch (Exception ex)
  74. {
  75. exp = ex;
  76. }
  77. finally
  78. {
  79. EndCase(exp);
  80. exp = null;
  81. }
  82. }
  83. [Test]
  84. public void TestHasRowsFalse()
  85. {
  86. BeginCase("Test HasRows = False");
  87. exp = null;
  88. string rowId = string.Format("43977_{0}", TestCaseNumber);
  89. OleDbConnection con = null;
  90. OleDbDataReader rdr = null;
  91. try
  92. {
  93. DbTypeParametersCollection row = ConnectedDataProvider.GetSimpleDbTypesParameters();
  94. row.ExecuteDelete(rowId); //Make sure that a row with such ID does not exist.
  95. row.ExecuteSelectReader(rowId, out rdr, out con);
  96. Compare(rdr.HasRows, false);
  97. }
  98. catch (Exception ex)
  99. {
  100. exp = ex;
  101. }
  102. finally
  103. {
  104. EndCase(exp);
  105. exp = null;
  106. }
  107. }
  108. }
  109. }