Pages

Wednesday, September 26, 2012

System.InvalidOperationException in NUnit with RhinoMocks

To solve the above exception while running unit tests, you need to make sure that all the mocked methods are using "virtual" keyword in method signature.
Ex: Public virtual method(int a, int b)

The reason for this issue is, Rhino mocks creates a proxy class when you call StrictMock (or any type) using  MockRepository. Then, it needs to extend your type.

By making the methods as virtual we let RhinoMocks know that they can override and inherit it for their mocking purposes.

No comments:

Post a Comment