DbDataReaderMock.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. // DbDataReaderMock.cs - Helper class for DbDataReader tests
  2. //
  3. // Author:
  4. // Mika Aalto ([email protected])
  5. //
  6. // Copyright (C) 2014 Mika Aalto
  7. //
  8. // Permission is hereby granted, free of charge, to any person obtaining
  9. // a copy of this software and associated documentation files (the
  10. // "Software"), to deal in the Software without restriction, including
  11. // without limitation the rights to use, copy, modify, merge, publish,
  12. // distribute, sublicense, and/or sell copies of the Software, and to
  13. // permit persons to whom the Software is furnished to do so, subject to
  14. // the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be
  17. // included in all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  22. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  23. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  24. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  25. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. //
  27. #if NET_2_0
  28. using System;
  29. using System.Data;
  30. using System.Data.Common;
  31. using System.IO;
  32. namespace Test.System.Data.Common
  33. {
  34. internal class DbDataReaderMock : DbDataReader
  35. {
  36. int currentRowIndex = -1;
  37. DataTable testDataTable;
  38. public DbDataReaderMock ()
  39. {
  40. testDataTable = new DataTable ();
  41. }
  42. public DbDataReaderMock (DataTable testData)
  43. {
  44. if (testData == null) {
  45. throw new ArgumentNullException ("testData");
  46. }
  47. testDataTable = testData;
  48. }
  49. public override void Close ()
  50. {
  51. testDataTable.Clear ();
  52. }
  53. public override int Depth {
  54. get { throw new NotImplementedException (); }
  55. }
  56. public override int FieldCount {
  57. get { throw new NotImplementedException (); }
  58. }
  59. public override bool GetBoolean (int ordinal)
  60. {
  61. throw new NotImplementedException ();
  62. }
  63. public override byte GetByte (int ordinal)
  64. {
  65. throw new NotImplementedException ();
  66. }
  67. public override long GetBytes (int ordinal, long dataOffset, byte[] buffer, int bufferOffset, int length)
  68. {
  69. object value = GetValue (ordinal);
  70. if (value == DBNull.Value) {
  71. return 0;
  72. }
  73. byte[] data = (byte[])value;
  74. long bytesToRead = Math.Min (data.Length - dataOffset, length);
  75. Buffer.BlockCopy (data, (int)dataOffset, buffer, bufferOffset, (int)bytesToRead);
  76. return bytesToRead;
  77. }
  78. public override char GetChar (int ordinal)
  79. {
  80. throw new NotImplementedException ();
  81. }
  82. public override long GetChars (int ordinal, long dataOffset, char[] buffer, int bufferOffset, int length)
  83. {
  84. throw new NotImplementedException ();
  85. }
  86. public override string GetDataTypeName (int ordinal)
  87. {
  88. throw new NotImplementedException ();
  89. }
  90. public override DateTime GetDateTime (int ordinal)
  91. {
  92. throw new NotImplementedException ();
  93. }
  94. public override decimal GetDecimal (int ordinal)
  95. {
  96. throw new NotImplementedException ();
  97. }
  98. public override double GetDouble (int ordinal)
  99. {
  100. throw new NotImplementedException ();
  101. }
  102. public override global::System.Collections.IEnumerator GetEnumerator ()
  103. {
  104. throw new NotImplementedException ();
  105. }
  106. public override Type GetFieldType (int ordinal)
  107. {
  108. throw new NotImplementedException ();
  109. }
  110. public override float GetFloat (int ordinal)
  111. {
  112. throw new NotImplementedException ();
  113. }
  114. public override Guid GetGuid (int ordinal)
  115. {
  116. throw new NotImplementedException ();
  117. }
  118. public override short GetInt16 (int ordinal)
  119. {
  120. throw new NotImplementedException ();
  121. }
  122. public override int GetInt32 (int ordinal)
  123. {
  124. throw new NotImplementedException ();
  125. }
  126. public override long GetInt64 (int ordinal)
  127. {
  128. throw new NotImplementedException ();
  129. }
  130. public override string GetName (int ordinal)
  131. {
  132. throw new NotImplementedException ();
  133. }
  134. public override int GetOrdinal (string name)
  135. {
  136. throw new NotImplementedException ();
  137. }
  138. public override DataTable GetSchemaTable ()
  139. {
  140. throw new NotImplementedException ();
  141. }
  142. public override string GetString (int ordinal)
  143. {
  144. return (string)testDataTable.Rows [currentRowIndex] [ordinal];
  145. }
  146. public override object GetValue (int ordinal)
  147. {
  148. return testDataTable.Rows [currentRowIndex] [ordinal];
  149. }
  150. public override int GetValues (object[] values)
  151. {
  152. throw new NotImplementedException ();
  153. }
  154. public override bool HasRows {
  155. get { throw new NotImplementedException (); }
  156. }
  157. public override bool IsClosed {
  158. get { throw new NotImplementedException (); }
  159. }
  160. public override bool IsDBNull (int ordinal)
  161. {
  162. return testDataTable.Rows [currentRowIndex] [ordinal] == DBNull.Value;
  163. }
  164. public override bool NextResult ()
  165. {
  166. throw new NotImplementedException ();
  167. }
  168. public override bool Read ()
  169. {
  170. currentRowIndex++;
  171. return currentRowIndex < testDataTable.Rows.Count;
  172. }
  173. public override int RecordsAffected {
  174. get { throw new NotImplementedException (); }
  175. }
  176. public override object this [string name] {
  177. get { throw new NotImplementedException (); }
  178. }
  179. public override object this [int ordinal] {
  180. get { throw new NotImplementedException (); }
  181. }
  182. }
  183. }
  184. #endif // NET_2_0