I have the following generic method:
public bool Any<TEntity>(Expression<Func<TEntity, bool>> whereCondition) where TEntity : class
{
bool result = false;
ObjectQuery<TEntity> query = CreateObjectSet<TEntity>();
var queryResult = query.Where(whereCondition);
if(queryResult.Count() > 0)
result = true;
return result;
}
Using Moq, I mocked an instance of the class where this method resides.
Now I’d like to mock the return result of this method:
var mock = new Mock<ITestRepository>();
mock.Setup(foo => foo.Single<MyObject>(It.IsAny<Expression>)).Returns(new MyObject());
What am I missing with this?
I don’t know if you’ve already been able to solve this, but you’re passing the wrong type parameter to
It.IsAny<>.Your call to
Setupshould actually be: