From: <gc...@us...> - 2002-12-28 21:36:36
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Data In directory sc8-pr-cvs1:/tmp/cvs-serv6799/DotNetMock/Data Added Files: MockDataReader.cs Log Message: --- NEW FILE: MockDataReader.cs --- using System; using System.Data; using DotNetMock; namespace DotNetMock.Data { /// <summary> /// Summary description for MockDataReader. /// </summary> public class MockDataReader : MockObject, IDataReader { private int _recordsAffectedCount = -1; private bool _isClosed = false; private ExpectationCounter _closeCalls = new ExpectationCounter("MockDataReader.CloseCalls"); private ExpectationCounter _readCalls = new ExpectationCounter("MockDataReader.ReadCalls"); private DataTable _schemaTable = null; private object[,] _rows = new object[0,0]; private int _currentRow = -1; public MockDataReader() {} #region Mock Methods public void SetRecordsAffectedCount(int count) { _recordsAffectedCount = count; } public void SetExpectedCloseCalls(int calls) { _closeCalls.Expected = calls; } public void SetSchemaTable(DataTable schemaTable) { _schemaTable = schemaTable; } public void SetExpectedReadCalls(int readCalls) { _readCalls.Expected = readCalls; } public void SetIsClosedValue(bool isClosed) { _isClosed = isClosed; } public void SetRows(object[,] rows) { _rows = rows; } #endregion #region Implementation of IDataReader public void Close() { _closeCalls.Inc(); _isClosed = true; } public System.Data.DataTable GetSchemaTable() { return _schemaTable; } public bool NextResult() { this.NotImplemented("MockDataReader.NextResult"); return true; } public bool Read() { _readCalls.Inc(); if (_currentRow + 1 >= _rows.GetLength(0)) { return false; } _currentRow++; return true; } public int Depth { get { this.NotImplemented("MockDataReader.Depth"); return 0; } } public bool IsClosed { get { return _isClosed; } } public int RecordsAffected { get { return _recordsAffectedCount; } } #region Implementation of IDisposable public void Dispose() { } #endregion #region Implementation of IDataRecord public int GetInt32(int i) { return Convert.ToInt32(GetValue(i)); } public object GetValue(int i) { return _rows[_currentRow, i - 1]; } public bool IsDBNull(int i) { bool result = true; if (!GetValue(i).Equals("")) { result = false; } return result; } public long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, int length) { this.NotImplemented("MockDataReader.GetBytes"); return 0; } public byte GetByte(int i) { return Convert.ToByte(GetValue(i)); } public System.Type GetFieldType(int i) { this.NotImplemented("MockDataReader.GetFieldType"); return null; } public decimal GetDecimal(int i) { return Convert.ToDecimal(GetValue(i)); } public int GetValues(object[] values) { this.NotImplemented("MockDataReader.GetValues"); return 0; } public string GetName(int i) { this.NotImplemented("MockDataReader.GetName"); return null; } public long GetInt64(int i) { return Convert.ToInt64(GetValue(i)); } public double GetDouble(int i) { return Convert.ToDouble(GetValue(i)); } public bool GetBoolean(int i) { return Convert.ToBoolean(GetValue(i)); } public System.Guid GetGuid(int i) { this.NotImplemented("MockDataReader.GetGuid"); return new System.Guid(); } public System.DateTime GetDateTime(int i) { return Convert.ToDateTime(GetValue(i)); } public int GetOrdinal(string name) { this.NotImplemented("MockDataReader.GetOrdinal"); return 0; } public string GetDataTypeName(int i) { this.NotImplemented("MockDataReader.GetDataTypeName"); return null; } public float GetFloat(int i) { this.NotImplemented("MockDataReader.GetFloat"); return 0; } public System.Data.IDataReader GetData(int i) { this.NotImplemented("MockDataReader.GetData"); return null; } public long GetChars(int i, long fieldoffset, char[] buffer, int bufferoffset, int length) { this.NotImplemented("MockDataReader.GetChars"); return 0; } public string GetString(int i) { return Convert.ToString(GetValue(i)); } public char GetChar(int i) { return Convert.ToChar(GetValue(i)); } public short GetInt16(int i) { return Convert.ToInt16(GetValue(i)); } public object this[string name] { get { return this[findColumnIndexForName(name)]; } } public object this[int i] { get { return GetValue(i); } } public int FieldCount { get { this.NotImplemented("MockDataReader.FieldCount"); return 0; } } #endregion #endregion private int findColumnIndexForName(string name) { if (_schemaTable != null) { for (int i = 0; i < _schemaTable.Columns.Count; ++i) { if (_schemaTable.Columns[i].ColumnName.Equals(name)) { return i + 1; } } } throw new IndexOutOfRangeException("Column name: " + name + " not found"); } } } |