Moq: Mocking Method by using Moq Mocking Framework
This's about how to mock method using Moq Mocking Framework. So, basically, Interface is good way to go, eventhough your method is get only, it's able to mock your method to result different data. There's one thing you need to remembers, Mocking can only mock Interface, abstarct, virtal, but sealed class. for example if you have following kind of class and interface.
So, First Total() will run thouht, but you'll get run-time error when you mock GetOnlyMethod(), like following image.
You can't mock class not Get only property on your class
However, if you mock the Interface like following it's gonna work.
Also, if you class is Public, and Method is Virtual works fine too.
In addition, your class, method is abstarct, you could mock you method's value too.
You could also write like following depend on what's you set, return different result.
Or, like following user can put any string, and return specific result
Basically, best practice is mock your interface class.