Mocking classes that implement IQueryable with Moq

后端 未结 5 1125
隐瞒了意图╮
隐瞒了意图╮ 2020-12-13 08:41

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

public interface IRepo : IQueryable
{
}

The best

5条回答
  •  别那么骄傲
    2020-12-13 09:43

    I had the same issue. I've fixed it by changing this line

    mock.Setup(r => r.GetEnumerator()).Returns(queryable.GetEnumerator());
    

    to

    mock.Setup(r => r.GetEnumerator()).Returns(queryable.GetEnumerator);
    

    I hope that additional comments are not required here.

提交回复
热议问题