As I understand it, you want to execute some mock logic predicated on the properties of the instance on which a method was called. You also want that mock logic to execute on every instance of a given type.
In the next JustMock internal build, there will be a new feature that allows you to write Returns() clauses that can operate on the instance itself, rather than just the arguments.
Your arrange would then look like this:
var mock = Mock.Create<SqlDbCommand>();
Mock.Arrange(() => mock.ExecuteScalar())
.Returns((IDbCommand @this) =>
if (@this.CommandText == "dbo.GetStartTime")
By making an arrange with the IgnoreInstance() clause, you'll then be able to access the concrete instance in the delegate passed to returns. Inside the delegate you'll be able to implement the custom logic that relates the CommandText to the return value. What you won't be able to do is call the original implementation of ExecuteScalar - JustMock still doesn't support this.
Also, note that you must call Mock.Create<T>() for the concrete type of ADO.NET provider you use, e.g. SqlDbCommand. If you don't then interception for this type will not be enabled and you'll miss calls to methods declared on that type. It is not enough to call just Mock.Create<IDbCommand>().
I hope the above solution will prove useful and sufficient. If it doesn't fulfill all your testing needs, or have additional comments, then please write us back.
Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
Thanks for detailed reply. I'm looking forward for the exciting features in the new release. Meanwhile, i'll try to reconsider my approach and mock the my class private method which calls db - hope it would be easier.