I am using Rhino Mocks 3.6 in C# and i am experiencing problems when mocking objects instead of interfaces. Could somebody please explain why methods are actually called when just defining an expectation?
public class MockingBird
{
public void TestMethod()
{
throw new Exception("Method call!");
}
}
...
[TestMethod]
public void TestMock()
{
var mockedMockingBird = MockRepository.GenerateStrictMock<MockingBird>();
mockedMockingBird.Expect(x => x.TestMethod());
}
You can't mock methods that are not overridable. When creating mock instance Rhino does the following:
In practice, you can only mock virtual
/abstract
methods of classes and any member of interface.
Keep in mind that this limitation is present in all free mocking frameworks.