-1

如何将 OfType 起订量返回

class A
{ 
  public void iterate()
  {
    foreach (var aTool in Handler.Tools.OfType<IDrawTool>())
    {
      //some code
    }
  }
}

//tools implementes both interface ITool and IDrawTool
//wanted to get the tool which implements the IDrawTool from the 
//Handler.Tools<ITool> list

Mock<List<ITool>> aToolMockList = new Mock<ITool>();
Mock<IDrawTool> adrawToolMock = new Mock<IDrawTool>();
aToolMockList.Setup(list => list.OfType<IDrawTool>()).Returns((IEnumerable<IDrawTool>)  adrawToolMock .Object);

但是OfType抛出异常setup on a non-member method

我应该覆盖这个吗?我应该怎么办?

4

1 回答 1

0
List<ITool> aToolMockList = new List<ITool>();
Mock<IDrawTool> adrawToolMock = new Mock<IDrawTool>();
Mock<ITool> aToolMock = new Mock<ITool>;
//additional setups
aToolMockList.Add(adrawToolMock.object);
aToolMockList.Add(aToolMock.object);
//
A a = new A(aToolMockList);
A.iterate();
//
adrawToolMock.Toolwork.Verify(Times.Once);
aToolMock.Toolwork.Verify(Times.Never);

类似的东西:)

于 2012-05-10T08:38:27.177 回答