Setup() vs SetupGet()

moq
Nil Pun picture Nil Pun · Apr 24, 2011 · Viewed 17.7k times · Source

What is the difference between the SetupGet() and Setup() methods for MOQ?

Answer

John Allers picture John Allers · Apr 25, 2011

Setup() can be used for mocking a method or a property.

SetupGet() is specifically for mocking the getter of a property. Took a quick peek at the Moq source code and it looks like if you use Setup() on a property getter, it will call SetupGet(). So in that case, it is probably more personal preference as to whether you want to be more explicit and use SetupGet() instead of Setup().

Of course, my knowledge of Moq is limited, so I don't know if there special cases where you would need to use SetupGet() over Setup().