Is it possible to Mock a Linq Expression via Moq using a Generic class such as ~1Repository. ~IRepository being something that is injected via an IoC such as StructureMap or Windsor?
CODE TO TEST:
var person = _repository.Find<Person>()
.Where(p => p.Id == person.Id).SingleOrDefault();
TEST:
var repository = new Mock<IRepository>();
repository.Setup(i => i.Find<Person>()
.Where(p => p.Id == person.Id).SingleOrDefault())
.Returns(person).Verifiable();
EXCEPTION:
System.ArgumentException: Invalid setup on a non-member method:i => i.Find().Where(p => p.Id == "Fred").SingleOrDefault()
SOLUTION
using System.Linq;
...
_container.GetMock<IRepository>.Setup(i => i.Find<Person>())
.Returns(new List{person}.AsQueryable()).Verifiable();
...