Setup() vs SetupGet()

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


Solution 1:

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

Solution 2:

SetupGet works when you're trying to mock read only property