OleDbDataReader_GetChars.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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_GetChars : ADONetTesterClass
  32. {
  33. OleDbConnection con;
  34. char [] Result;
  35. [SetUp]
  36. public void SetUp()
  37. {
  38. Exception exp = null;
  39. BeginCase("Setup");
  40. try
  41. {
  42. //prepare data
  43. base.PrepareDataForTesting(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
  44. con = new OleDbConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
  45. Result = new char[100];
  46. con.Open();
  47. }
  48. catch(Exception ex) {exp = ex;}
  49. finally {EndCase(exp); exp = null;}
  50. }
  51. [TearDown]
  52. public void TearDown()
  53. {
  54. if (con.State == ConnectionState.Open) con.Close();
  55. }
  56. public static void Main()
  57. {
  58. OleDbDataReader_GetChars tc = new OleDbDataReader_GetChars();
  59. Exception exp = null;
  60. try
  61. {
  62. tc.BeginTest("OleDbDataReader_GetChars");
  63. tc.SetUp();
  64. tc.run();
  65. tc.TearDown();
  66. }
  67. catch(Exception ex){exp = ex;}
  68. finally {tc.EndTest(exp);}
  69. }
  70. [Test]
  71. public void run()
  72. {
  73. Exception exp = null;
  74. long rdrResults = 0;
  75. OleDbCommand cmd = new OleDbCommand("Select LastName From Employees Where EmployeeID = 100", con);
  76. OleDbDataReader rdr = cmd.ExecuteReader();
  77. rdr.Read();
  78. //LastName should be "Last100"
  79. try
  80. {
  81. BeginCase("check result length");
  82. rdrResults = rdr.GetChars(0, 0, Result, 0, Result.Length);
  83. Compare(rdrResults,(long)"Last100".Length );
  84. }
  85. catch(Exception ex){exp = ex;}
  86. finally{EndCase(exp); exp = null;}
  87. try
  88. {
  89. BeginCase("check result - char[0]");
  90. Compare(Result[0] ,'L');
  91. }
  92. catch(Exception ex){exp = ex;}
  93. finally{EndCase(exp); exp = null;}
  94. try
  95. {
  96. BeginCase("check result - char[last char index]");
  97. Compare(Result["Last100".Length-1] ,'0');
  98. }
  99. catch(Exception ex){exp = ex;}
  100. finally{EndCase(exp); exp = null;}
  101. }
  102. }
  103. }