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>()));
精彩评论