DbDataReaderMock.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. using System;
  28. using System.Data;
  29. using System.Data.Common;
  30. using System.IO;
  31. namespace MonoTests.System.Data.Common
  32. {
  33. internal class DbDataReaderMock : DbDataReader
  34. {
  35. int currentRowIndex = -1;
  36. DataTable testDataTable;
  37. public DbDataReaderMock ()
  38. {
  39. testDataTable = new DataTable ();
  40. }
  41. public DbDataReaderMock (DataTable testData)
  42. {
  43. if (testData == null) {
  44. throw new ArgumentNullException ("testData");
  45. }
  46. testDataTable = testData;
  47. }
  48. public override void Close ()
  49. {
  50. testDataTable.Clear ();
  51. }
  52. public override int Depth {
  53. get { throw new NotImplementedException (); }
  54. }
  55. public override int FieldCount {
  56. get { throw new NotImplementedException (); }
  57. }
  58. public override bool GetBoolean (int ordinal)
  59. {
  60. throw new NotImplementedException ();
  61. }
  62. public override byte GetByte (int ordinal)
  63. {
  64. throw new NotImplementedException ();
  65. }
  66. public override long GetBytes (int ordinal, long dataOffset, byte[] buffer, int bufferOffset, int length)
  67. {
  68. object value = GetValue (ordinal);
  69. if (value == DBNull.Value) {
  70. return 0;
  71. }
  72. byte[] data = (byte[])value;
  73. long bytesToRead = Math.Min (data.Length - dataOffset, length);
  74. Buffer.BlockCopy (data, (int)dataOffset, buffer, bufferOffset, (int)bytesToRead);
  75. return bytesToRead;
  76. }
  77. public override char GetChar (int ordinal)
  78. {
  79. throw new NotImplementedException ();
  80. }
  81. public override long GetChars (int ordinal, long dataOffset, char[] buffer, int bufferOffset, int length)
  82. {
  83. throw new NotImplementedException ();
  84. }
  85. public override string GetDataTypeName (int ordinal)
  86. {
  87. throw new NotImplementedException ();
  88. }
  89. public override DateTime GetDateTime (int ordinal)
  90. {
  91. throw new NotImplementedException ();
  92. }
  93. public override decimal GetDecimal (int ordinal)
  94. {
  95. throw new NotImplementedException ();
  96. }
  97. public override double GetDouble (int ordinal)
  98. {
  99. throw new NotImplementedException ();
  100. }
  101. public override global::System.Collections.IEnumerator GetEnumerator ()
  102. {
  103. throw new NotImplementedException ();
  104. }
  105. public override Type GetFieldType (int ordinal)
  106. {
  107. throw new NotImplementedException ();
  108. }
  109. public override float GetFloat (int ordinal)
  110. {
  111. throw new NotImplementedException ();
  112. }
  113. public override Guid GetGuid (int ordinal)
  114. {
  115. throw new NotImplementedException ();
  116. }
  117. public override short GetInt16 (int ordinal)
  118. {
  119. throw new NotImplementedException ();
  120. }
  121. public override int GetInt32 (int ordinal)
  122. {
  123. throw new NotImplementedException ();
  124. }
  125. public override long GetInt64 (int ordinal)
  126. {
  127. throw new NotImplementedException ();
  128. }
  129. public override string GetName (int ordinal)
  130. {
  131. throw new NotImplementedException ();
  132. }
  133. public override int GetOrdinal (string name)
  134. {
  135. throw new NotImplementedException ();
  136. }
  137. public override DataTable GetSchemaTable ()
  138. {
  139. throw new NotImplementedException ();
  140. }
  141. public override string GetString (int ordinal)
  142. {
  143. return (string)testDataTable.Rows [currentRowIndex] [ordinal];
  144. }
  145. public override object GetValue (int ordinal)
  146. {
  147. return testDataTable.Rows [currentRowIndex] [ordinal];
  148. }
  149. public override int GetValues (object[] values)
  150. {
  151. throw new NotImplementedException ();
  152. }
  153. public override bool HasRows {
  154. get { throw new NotImplementedException (); }
  155. }
  156. public override bool IsClosed {
  157. get { throw new NotImplementedException (); }
  158. }
  159. public override bool IsDBNull (int ordinal)
  160. {
  161. return testDataTable.Rows [currentRowIndex] [ordinal] == DBNull.Value;
  162. }
  163. public override bool NextResult ()
  164. {
  165. throw new NotImplementedException ();
  166. }
  167. public override bool Read ()
  168. {
  169. currentRowIndex++;
  170. return currentRowIndex < testDataTable.Rows.Count;
  171. }
  172. public override int RecordsAffected {
  173. get { throw new NotImplementedException (); }
  174. }
  175. public override object this [string name] {
  176. get { throw new NotImplementedException (); }
  177. }
  178. public override object this [int ordinal] {
  179. get { throw new NotImplementedException (); }
  180. }
  181. }
  182. }