How to mock non virtual methods?

Moq cannot mock non virtual methods on classes. Either use other mocking frameworks such as Type mock Isolator which actually weaves IL into your assembly or place an interface on EmailService and mock that.


Mocking non virtual methods involves the use of low level profiler API. At the moment I think the only options available are :

  • TypeMock
  • JustMock

both are commercial, even if JustMock have a lite edition, mocking non virtual methods are available just with the commercial version. As pointed in the comments there is something from Microsoft research, in the project Pex and Moles

Tags:

C#

.Net

Moq