方法设置上的模拟参数数组不绑定

时间:2018-01-04 17:30:15

标签: moq

我正在尝试设置以下方法调用:

public Entity GetById(int id, params Expression<Func<Entity, object>>[] includes)
{
}

这是我的设置:

var mock = new Mock<Caller>();
mock.Setup(caller => caller.GetById(It.Is<int>(id => id == request.Id),
    It.IsAny<Expression<Func<Entity, object>>[]>()))
.Returns(fakeEntity);

这个编译得很好。但是,在运行时,我收到以下错误:

Moq.MockException: Caller.GetById(1, ex1 => ex1, ex2 => ex2, ex3 => ex3) invocation failed with mock behavior Strict. All invocations on the mock must have a corresponding setup.

所以我尝试改用松散的行为,但正如预期的那样,它返回了Mock<Entity>而不是fakeEntity。为什么模拟签名没有正确绑定到方法签名?

0 个答案:

没有答案