How to Change Default Return Values in MOQ
In Moq, any mocked method or property without defined behavior will return the default value of its return type. This means that for all reference types a null value is returned. It turns out that this behavior is easily configurable by calling the SetReturnsDefault() of T method, and passing in a default value of your choosing.
In the example bellow I've specified that I want all methods or properties that return objects of type string to return the fixed string “John Smith” instead of the default null value.
SetReturnsDefault() can be used as an alternative to Setups, but one obvious limitation is that all strings, throughout the entire mock, will now be returned as “John Smith”. If you need more granular control at the method or property level I recommend using Setups instead.