Tuesday 13 May 2008

Rhino Mocks - Partial mock not calling base method

Had a problem where I was creating a partial mock then calling a method of the partial mock which was returning 0 (zero).

The base method was not being called even though no expectations had been setup.

The reason for this was that the ReplayAll (and VerifyAll) methods of Rhino Mocks was not being called.

Original code:

            _interestBiz = _mocks.PartialMock<InterestBiz>();
int baseDay = _interestBiz.GetBaseDaysFromAccount(account);
Assert.AreEqual(365, baseDay, "Incorrect base days");


Fixed code:



            _interestBiz = _mocks.PartialMock<InterestBiz>();
using (_mocks.Record())
{

}

using (_mocks.Playback())
{
int baseDay = _interestBiz.GetBaseDaysFromAccount(account);
Assert.AreEqual(365, baseDay, "Incorrect base days");



 



So even though no expectations were set Rhino Mocks needs to no this.