在组装返回值()时访问Expect()的原始参数

问题描述:

组装返回对象时可以访问用于调用模拟期望的参数吗?在组装返回值()时访问Expect()的原始参数

这里是因为涉及到的对象和存根,我试图嘲弄集合:

Class CollectionValue { 
    public Id { get; set; } 
} 
Class Collection { 
    private List<CollectionValue> AllValues { get; set; } 
    public List<CollectionValue> GetById(List<int> ids) { 
     return AllValues.Where(v => ids.Contains(v.Id)); 
    } 
} 

由于将被用于嘲笑的对象CollectionValues的测试列表,如何做一个去设置一个期望来处理CollectionValues列表中的ID的所有可能的排列,包括组合现有ID和不存在ID的调用?我的问题来自于希望在一次通话中设定所有可能的期望;如果无法访问原始参数,那么每次都可以轻松设置我想要在给定调用中测试的确切期望。

这是我希望做的事情,其中​​“???”代表哪里会很方便的访问用来调用GetById(即合格It.IsAny限制的)参数:这表明

// access invocation arguments when returning a value 
mock.Setup(x => x.Execute(It.IsAny<string>())) 
       .Returns((string s) => s.ToLower()); 

CollectionMock.Expect(c => c.GetById(It.IsAny<List<int>>())).Returns(???); 

从MOQ quickstart指南因此,你可以填写你的??? as

CollectionMock.Expect(c => c.GetById(It.IsAny<List<int>>())) 
       .Returns((List<int> l) => //Do some stuff with l 
        );