tags:

views:

116

answers:

1

If I have a Rhino Mock object that has already has a Stub call declared on it like this...

mockEmploymentService.Stub(x => x.GetEmployment(999)).Return(employment);

Is there anyway I can remove this call to replace it with something different eg...

mockEmploymentService.Stub(x => x.GetEmployment(999)).Return(null);

The reason I ask is that I want to set up some generic mocks to be used in multiple unit tests and then allow each unit test to tailor the calls where necessary.

+1  A: 

I use this extension method to clear the behavior of stubs (or the behavior+expectations of mocks):

public static class RhinoExtensions
{
    /// <summary>
    /// Clears the behavior already recorded in a Rhino Mocks stub.
    /// </summary>
    public static void ClearBehavior<T>(this T stub)
    {
        stub.BackToRecord(BackToRecordOptions.All);
        stub.Replay();
    }
}

I picked that up from this other stackoverflow answer, or maybe it was this one.

Wim Coenen
Thanks Wim, the only problem is that it would clear all stub calls so I would have to reset them all rather than just override the one I am interested in.
Si Keep