I need to mock any DbCommand calls to the specific sproc. I tried mocking
for the code below but I doesn't work. How can I achieve it?
var cmd = Mock.CreateLike<System.Data.IDbCommand>(c => c.CommandText ==
"dbo.GetStartTime"
);
Mock.Arrange(() => cmd.ExecuteScalar())
.Returns(
"10:00"
);
for the code below but I doesn't work. How can I achieve it?
private
static
string
LoadFromDatabase(DateTime date)
{
// create EntLib database object
using
(DbCommand cmd = db.GetStoredProcCommand(
"dbo.GetStartTime"
))
{
db.AddInParameter(cmd,
"DateToCheck"
, DbType.Date, date.Date);
var startTime = db.ExecuteScalar(cmd);
if
(startTime ==
null
|| startTime == DBNull.Value)
return
null
;
else
return
startTime;
}
}