开发者

Moq a function but don't have access to the arguments

I have a class that constructs a new object to add to the internal state of an object I am mocking... something like

    public clas开发者_开发百科s foo
    {
        public bar raz;

        public foo(bar raz)
        {
            this.raz = raz;
        }

        public void InsertItem()
        {
            raz.Insert(new FooBar());
        }
    }

I want to mock raz, but can't figure out the syntax to say verify raz.Insert was called, but it doesn't need to match the argument passed (since its created internally). What can I do?

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(); 


Use:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜