Setup on a void method

207 views
Skip to first unread message

Brian

unread,
Jul 21, 2010, 4:31:27 PM7/21/10
to Moq Discussions
I have a method with no return type that I want to mock. I don't want
the methods implementation to be executed. Is it bad practice to do
this? Or should setup only be called on methods which return values?

AutoMock<IMyInterface>().Setup(m => m.MyVoidMethod)

Daniel Cazzulino

unread,
Jul 21, 2010, 5:53:12 PM7/21/10
to moq...@googlegroups.com
it's supported and fine.

btw, if you don't set the mock CallBase property to true, we don't call it by default, IIRC, so you don't need to make a setup just to avoid the call to the base class (as long as the method is virtual)

/kzu

--
Daniel Cazzulino | Developer Lead | XML MVP | Clarius Consulting | +1 425.329.3471


Brian

unread,
Jul 21, 2010, 6:09:30 PM7/21/10
to Moq Discussions
Thanks Daniel. I've removed my redundant Setup calls. Your are also
correct about the CallBase property.
Reply all
Reply to author
Forward
0 new messages