代码之家  ›  专栏  ›  技术社区  ›  tbischel

moq函数,但不能访问参数

  •  1
  • tbischel  · 技术社区  · 14 年前

    我有一个类,它构造一个新的对象来添加到我正在模拟的对象的内部状态…类似的东西

        public class foo
        {
            public bar raz;
    
            public foo(bar raz)
            {
                this.raz = raz;
            }
    
            public void InsertItem()
            {
                raz.Insert(new FooBar());
            }
        }
    

    我想嘲笑raz,但无法找出语法来表示verify raz.insert被调用,但它不需要匹配传递的参数(因为它是在内部创建的)。我能做什么?

    var mock = new Mock<bar>();
    mock.Setup(mock => mock.Insert(?)).Verifiable();  //This is the line I can't figure out
    var test(mock.Object);
    test.InsertItem();
    mock.VerifyAll(); 
    
    1 回复  |  直到 14 年前
        1
  •  1
  •   Aliostad    14 年前

    用途:

    mock.Setup(mock => mock.Insert(It.IsAny<FooBar>()));