I had a discussion today regarding Moq and how to make a quick stub of a property so that a mock object could be thrown into somewhere and have the properties work as simple properties. The simple answer weas to use an expectation:
But that felt ugly – and not as useful as it could be.
After playing around for a while I found the Moq.Stub namespace. After placing a using to this namespace at the top you can do something along the lines of personMock.Stub( p => p.Name ):
or to mock out all of the properties use personMock.StubAll():
As you can see – if no expectation is needed stubbing properties is quite simple in Moq.