OleDbDataReader_Item.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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_Item : ADONetTesterClass
  32. {
  33. public static void Main()
  34. {
  35. OleDbDataReader_Item tc = new OleDbDataReader_Item();
  36. Exception exp = null;
  37. try
  38. {
  39. tc.BeginTest("OleDbDataReader_Item");
  40. tc.run();
  41. }
  42. catch(Exception ex){exp = ex;}
  43. finally {tc.EndTest(exp);}
  44. }
  45. [Test]
  46. public void run()
  47. {
  48. Exception exp = null;
  49. //prepare data
  50. OleDbConnection con = new OleDbConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
  51. OleDbCommand cmd = new OleDbCommand("select ProductID,ProductName,Discontinued from Products where ProductID=1", con);
  52. con.Open();
  53. OleDbDataReader rdr = cmd.ExecuteReader();
  54. rdr.Read();
  55. object obj = null;
  56. switch (ConnectedDataProvider.GetDbType(con))
  57. {
  58. case DataBaseServer.DB2:
  59. case DataBaseServer.SQLServer:
  60. case DataBaseServer.PostgreSQL:
  61. try
  62. {
  63. BeginCase("Column int - type");
  64. obj = rdr["ProductID"];
  65. Compare(obj.GetType().FullName , typeof(int).FullName);
  66. }
  67. catch(Exception ex){exp = ex;}
  68. finally{EndCase(exp); exp = null;}
  69. break;
  70. case DataBaseServer.Oracle:
  71. case DataBaseServer.Sybase:
  72. try
  73. {
  74. BeginCase("Column Decimal - type");
  75. obj = rdr["ProductID"];
  76. Compare(obj.GetType().FullName , typeof(decimal).FullName);
  77. }
  78. catch(Exception ex){exp = ex;}
  79. finally{EndCase(exp); exp = null;}
  80. break;
  81. }
  82. try
  83. {
  84. BeginCase("Column int - value");
  85. Compare(obj.ToString(),"1");
  86. }
  87. catch(Exception ex){exp = ex;}
  88. finally{EndCase(exp); exp = null;}
  89. try
  90. {
  91. BeginCase("Column string - type");
  92. obj = rdr["ProductName"];
  93. Compare(obj.GetType().FullName , typeof(string).FullName);
  94. }
  95. catch(Exception ex){exp = ex;}
  96. finally{EndCase(exp); exp = null;}
  97. try
  98. {
  99. BeginCase("Column string - value");
  100. Compare(obj.ToString(),"Chai");
  101. }
  102. catch(Exception ex){exp = ex;}
  103. finally{EndCase(exp); exp = null;}
  104. switch (ConnectedDataProvider.GetDbType(con))
  105. {
  106. case DataBaseServer.DB2 :
  107. try
  108. {
  109. BeginCase("Column Int16 - type");
  110. obj = rdr["Discontinued"];
  111. Compare(obj.GetType().FullName , typeof(Int16).FullName);
  112. }
  113. catch(Exception ex){exp = ex;}
  114. finally{EndCase(exp); exp = null;}
  115. try
  116. {
  117. BeginCase("Column Int16 - value");
  118. Compare(obj.ToString(),"0");
  119. }
  120. catch(Exception ex){exp = ex;}
  121. finally{EndCase(exp); exp = null;}
  122. break;
  123. case DataBaseServer.SQLServer :
  124. try
  125. {
  126. BeginCase("Column bool - type");
  127. obj = rdr["Discontinued"];
  128. Compare(obj.GetType().FullName , typeof(bool).FullName);
  129. }
  130. catch(Exception ex){exp = ex;}
  131. finally{EndCase(exp); exp = null;}
  132. try
  133. {
  134. BeginCase("Column bool - value");
  135. Compare(obj.ToString().ToUpper(),"FALSE");
  136. }
  137. catch(Exception ex){exp = ex;}
  138. finally{EndCase(exp); exp = null;}
  139. break;
  140. case DataBaseServer.Oracle :
  141. //Column type is Decimal - already tested
  142. break;
  143. }
  144. if (con.State == ConnectionState.Open) con.Close();
  145. }
  146. //public TestClass():base(true){}
  147. //Activate this constructor to log Failures to a log file
  148. //public TestClass(System.IO.TextWriter tw):base(tw, false){}
  149. //Activate this constructor to log All to a log file
  150. //public TestClass(System.IO.TextWriter tw):base(tw, true){}
  151. //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
  152. }
  153. }