// DbDataReaderMock.cs - Helper class for DbDataReader tests // // Author: // Mika Aalto (mika@aalto.pro) // // Copyright (C) 2014 Mika Aalto // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; using System.Data; using System.Data.Common; using System.IO; namespace MonoTests.System.Data.Common { internal class DbDataReaderMock : DbDataReader { int currentRowIndex = -1; DataTable testDataTable; public DbDataReaderMock () { testDataTable = new DataTable (); } public DbDataReaderMock (DataTable testData) { if (testData == null) { throw new ArgumentNullException ("testData"); } testDataTable = testData; } public override void Close () { testDataTable.Clear (); } public override int Depth { get { throw new NotImplementedException (); } } public override int FieldCount { get { throw new NotImplementedException (); } } public override bool GetBoolean (int ordinal) { throw new NotImplementedException (); } public override byte GetByte (int ordinal) { throw new NotImplementedException (); } public override long GetBytes (int ordinal, long dataOffset, byte[] buffer, int bufferOffset, int length) { object value = GetValue (ordinal); if (value == DBNull.Value) { return 0; } byte[] data = (byte[])value; long bytesToRead = Math.Min (data.Length - dataOffset, length); Buffer.BlockCopy (data, (int)dataOffset, buffer, bufferOffset, (int)bytesToRead); return bytesToRead; } public override char GetChar (int ordinal) { throw new NotImplementedException (); } public override long GetChars (int ordinal, long dataOffset, char[] buffer, int bufferOffset, int length) { throw new NotImplementedException (); } public override string GetDataTypeName (int ordinal) { throw new NotImplementedException (); } public override DateTime GetDateTime (int ordinal) { throw new NotImplementedException (); } public override decimal GetDecimal (int ordinal) { throw new NotImplementedException (); } public override double GetDouble (int ordinal) { throw new NotImplementedException (); } public override global::System.Collections.IEnumerator GetEnumerator () { throw new NotImplementedException (); } public override Type GetFieldType (int ordinal) { throw new NotImplementedException (); } public override float GetFloat (int ordinal) { throw new NotImplementedException (); } public override Guid GetGuid (int ordinal) { throw new NotImplementedException (); } public override short GetInt16 (int ordinal) { throw new NotImplementedException (); } public override int GetInt32 (int ordinal) { throw new NotImplementedException (); } public override long GetInt64 (int ordinal) { throw new NotImplementedException (); } public override string GetName (int ordinal) { throw new NotImplementedException (); } public override int GetOrdinal (string name) { throw new NotImplementedException (); } public override DataTable GetSchemaTable () { throw new NotImplementedException (); } public override string GetString (int ordinal) { return (string)testDataTable.Rows [currentRowIndex] [ordinal]; } public override object GetValue (int ordinal) { return testDataTable.Rows [currentRowIndex] [ordinal]; } public override int GetValues (object[] values) { throw new NotImplementedException (); } public override bool HasRows { get { throw new NotImplementedException (); } } public override bool IsClosed { get { throw new NotImplementedException (); } } public override bool IsDBNull (int ordinal) { return testDataTable.Rows [currentRowIndex] [ordinal] == DBNull.Value; } public override bool NextResult () { throw new NotImplementedException (); } public override bool Read () { currentRowIndex++; return currentRowIndex < testDataTable.Rows.Count; } public override int RecordsAffected { get { throw new NotImplementedException (); } } public override object this [string name] { get { throw new NotImplementedException (); } } public override object this [int ordinal] { get { throw new NotImplementedException (); } } } }