Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rhino Mocks calls real method in Arrange

Tags:

c#

rhino-mocks

I am trying to stub a method call of a class like this:

Manager managerStub = MockRepository.GenerateStub(constructordata);
managerStub.Stub(x => x.GetData(Arg.Is.Anything)).Return(10)

But when I try to run this unit test, Rhino mocks calls the "GetData" method, with parameter "0" on the "manager.Stub..." line.

Why does Rhino Mocks call the real method?

like image 833
Kornél Regius Avatar asked Jul 03 '13 10:07

Kornél Regius


1 Answers

If you request a stub of a class RhinoMocks creates a derived class on the fly and overrides the methods you want to stub.
However, if the method you want to stub is not virtual RhinoMocks can't override it and thus it can't stub it.

like image 52
Daniel Hilgarth Avatar answered Oct 21 '22 03:10

Daniel Hilgarth