Question

I am trying to set an expectation on a Mocked object to find out if the method was called as expected.

I use the following code to achieve it.

//// Create a mocked object(arrange)
A controller = MockRepository.GenerateMock<A>();
someObject.Stub(x => x.Resolve(typeof(A))).Return(controller);

//// Act i.e. call the target function where the controller is created
this._target.InvokePrivateMethod("OnTargetUpdated", false, this, eventArgs);

//// Assert
controller.AssertWasCalled(x => x.UpdateTarget(targetInfo2), o => o.Repeat.Once());

However, when i try to assert if the "UpdateTarget()" was called the flow goes into the code of the method. I simply want to check "If the method was called" and not "call the method".

Was it helpful?

Solution

As method UpdateTarget() is non-virtual then Rhino Mock can't intercept call to it.

That's why the real method is executed instead.
See details e.g. in this question.

To get your test working you need to make mocked method virtual. Or even better if you use interface here instead of class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top