From: <gc...@us...> - 2002-10-07 00:07:47
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Data In directory usw-pr-cvs1:/tmp/cvs-serv28500 Added Files: MockDataParameter.cs Log Message: --- NEW FILE: MockDataParameter.cs --- using System; using System.Data; using DotNetMock; namespace DotNetMock.Data { /// <summary> /// Summary description for MockDataParameter. /// </summary> public class MockDataParameter : MockObject, IDataParameter { private ExpectationBool _nullable = new ExpectationBool("MockDataParameter.IsNullable"); private ExpectationString _parameterName = new ExpectationString("MockDataParameter.Name"); private ExpectationValue _parameterValue = new ExpectationValue("MockDataParameter.Value"); private ExpectationString _parameterSourceColumn = new ExpectationString("MockDataParameter.SourceColumn"); private ExpectationValue _parameterType = new ExpectationValue("MockDataParameter.Type"); public MockDataParameter() {} public MockDataParameter(string name, DbType newType) { _parameterName.Actual = name; _parameterType.Actual = newType; } public MockDataParameter(string name, string value) { _parameterName.Actual = name; _parameterValue.Actual = value; } public MockDataParameter(string name, DbType newType, string sourceColumn) { _parameterName.Actual = name; _parameterType.Actual = newType; _parameterSourceColumn.Actual = sourceColumn; } public void SetExpectedName(string name) { _parameterName.Expected = name; } public void SetExpectedValue(string value) { _parameterValue.Expected = value; } public void SetExpectedNullable(bool nullable) { _nullable.Expected = nullable; } public void SetExpectedType(DbType expectedType) { _parameterType.Expected = expectedType; } public void SetExpectedSourceColumn(string column) { _parameterSourceColumn.Expected = column; } #region Implementation of IDataParameter // TODO: Implement complete directions: Input, Output, InputOutput, and ReturnValue public System.Data.ParameterDirection Direction { get { return new System.Data.ParameterDirection(); } set { } } public System.Data.DbType DbType { get { return (DbType)_parameterType.Actual; } set { } } public object Value { get { return _parameterValue.Actual; } set { _parameterValue.Actual = value; _parameterType.Actual = inferType(value); } } public bool IsNullable { set { _nullable.Actual = value; } get { return _nullable.Actual; } } /// TODO: Implement different DataRowVersion information: Current, Proposed, Default, and Original public System.Data.DataRowVersion SourceVersion { get { return DataRowVersion.Current; } set { } } public string ParameterName { get { return _parameterName.Actual; } set { } } public string SourceColumn { get { return _parameterSourceColumn.Actual; } set { } } #endregion private DbType inferType(Object value) { switch (Type.GetTypeCode(value.GetType())) { case TypeCode.Empty: throw new SystemException("Invalid data type"); case TypeCode.Object: return DbType.Object; case TypeCode.DBNull: case TypeCode.Char: case TypeCode.SByte: case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: // Throw a SystemException for unsupported data types. throw new SystemException("Invalid data type"); case TypeCode.Boolean: return DbType.Boolean; case TypeCode.Byte: return DbType.Byte; case TypeCode.Int16: return DbType.Int16; case TypeCode.Int32: return DbType.Int32; case TypeCode.Int64: return DbType.Int64; case TypeCode.Single: return DbType.Single; case TypeCode.Double: return DbType.Double; case TypeCode.Decimal: return DbType.Decimal; case TypeCode.DateTime: return DbType.DateTime; case TypeCode.String: return DbType.String; default: throw new SystemException("Value is of unknown data type"); } } } } |