Mocking classes that implement IQueryable with Moq
I spent an evening trying to mock an object that implements IQueryable:

    public interface IRepo<T> : IQueryable<T>
    {
    }

The best I could come up with is something like this:

    var items = new Item[] {}.AsQueryable();

    var repo = new Mock<IRepo>();
    repo.Setup(r => r.GetEnumerator()).Returns(items.GetEnumerator());
    repo.Setup(r => r.Provider).Returns(items.Provider);
    repo.Setup(r => r.ElementType).Returns(items.ElementType);
    repo.Setup(r => r.Expression).Returns(items.Expression);
    
Is there a more concise way to do the same? It would be easier to expose a property/method in IRepo that returns IQueryable<T> and the simply mock like this:

    repo.Setup(r => r.GetItems()).Returns(new Items[]{ }.AsQueryable());

But this is not what I want to do =)
Mocking classes that implement IQueryable with Moq
===

I spent an evening trying to mock an object that implements IQueryable:

    public interface IRepo<T> : IQueryable<T>
    {
    }

The best I could come up with is something like this:

    var items = new Item[] {}.AsQueryable();

    var repo = new Mock<IRepo>();
    repo.Setup(r => r.GetEnumerator()).Returns(items.GetEnumerator());
    repo.Setup(r => r.Provider).Returns(items.Provider);
    repo.Setup(r => r.ElementType).Returns(items.ElementType);
    repo.Setup(r => r.Expression).Returns(items.Expression);
    
Is there a more concise way to do the same? It would be easier to expose a property/method in IRepo that returns IQueryable<T> and the simply mock like this:

    repo.Setup(r => r.GetItems()).Returns(new Items[]{ }.AsQueryable());

But this is not what I want to do =)