OleDbDataReader_GetDouble_I.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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_GetDouble_I : GHTBase
  33. {
  34. private Exception exp = null;
  35. private int testTypesInvocations;
  36. public static void Main()
  37. {
  38. OleDbDataReader_GetDouble_I tc = new OleDbDataReader_GetDouble_I();
  39. Exception exp = null;
  40. try
  41. {
  42. tc.BeginTest("OleDbDataReader_GetDouble_I");
  43. tc.run();
  44. }
  45. catch(Exception ex)
  46. {
  47. tc.exp = ex;
  48. }
  49. finally
  50. {
  51. tc.EndTest(tc.exp);
  52. }
  53. }
  54. [Test]
  55. public void run()
  56. {
  57. DoTestTypes(ConnectedDataProvider.GetSimpleDbTypesParameters());
  58. DoTestTypes(ConnectedDataProvider.GetExtendedDbTypesParameters());
  59. }
  60. public void DoTestTypes(DbTypeParametersCollection row)
  61. {
  62. testTypesInvocations++;
  63. exp = null;
  64. string rowId = "43969_" + this.testTypesInvocations.ToString();
  65. OleDbDataReader rdr = null;
  66. OleDbConnection con = null;
  67. try
  68. {
  69. row.ExecuteInsert(rowId);
  70. row.ExecuteSelectReader(rowId, out rdr, out con);
  71. while (rdr.Read())
  72. {
  73. //Run over all the columns in the result set row.
  74. //For each column, try to read it as a double.
  75. for (int i=0; i<row.Count; i++)
  76. {
  77. if (row[i].Value.GetType() == typeof(double)) //The value in the result set should be a double.
  78. {
  79. try
  80. {
  81. BeginCase(string.Format("Calling GetDouble() on a field of dbtype {0}", row[i].DbTypeName));
  82. double retDouble = rdr.GetDouble(i);
  83. Compare(row[i].Value, retDouble);
  84. }
  85. catch (Exception ex)
  86. {
  87. exp = ex;
  88. }
  89. finally
  90. {
  91. EndCase(exp);
  92. exp = null;
  93. }
  94. }
  95. else //The value in the result set should NOT be double. In this case an Invalid case exception should be thrown.
  96. {
  97. try
  98. {
  99. BeginCase(string.Format("Calling GetDouble() on a field of dbtype {0}", row[i].DbTypeName));
  100. double retDouble = rdr.GetDouble(i);
  101. ExpectedExceptionNotCaught("InvalidCastException");
  102. }
  103. catch (InvalidCastException ex)
  104. {
  105. ExpectedExceptionCaught(ex);
  106. }
  107. catch (Exception ex)
  108. {
  109. exp = ex;
  110. }
  111. finally
  112. {
  113. EndCase(exp);
  114. exp = null;
  115. }
  116. }
  117. }
  118. }
  119. }
  120. finally
  121. {
  122. row.ExecuteDelete(rowId);
  123. if ( (rdr != null) && (!rdr.IsClosed) )
  124. {
  125. rdr.Close();
  126. }
  127. if ( (con != null) && (con.State != ConnectionState.Closed) )
  128. {
  129. con.Close();
  130. }
  131. }
  132. }
  133. }
  134. }