I have a class which has a internal method and i want to mock the internal method . But i am unable to mock it i.e. it is not calling the mocked function but calling the original function. Is there any way to achieve this ?
Edit:Actually i am a novice to the Moq. I have many classes and methods of the classes to test using the Moq. Many classes are internal , many have internal methods, many have not-virtual methods . And can not change the signature on the methods and classes. Can anyone please let me know how to go about testing this scenario using Moq. Or else please suggest me some other testing framework which is easy to learn and easy to work with .
Why would you want to mock an internal method?
If you find the need to mock an internal method, say to sidestep a dependency or an interaction, you perhaps should consider redesign of the class.
Inversion of Control and Dependency Injection are some possible design strategies that can reduce coupling and increase cohesion of your classes and eliminate the need to mock internal methods.
I don’t believe there is a clear path to non-public mocking with Moq.
But, if you absolutely must, you can use TypeMock Isolator to mock just about anything.
Also, just so it doesn’t get lost in the din: Thomas linked a good article on using the free MS Moles to mock non-public members.
Mocking the Unmockable: Using Microsoft Moles with Gallio