Recursive mocking with Rhino-Mocks

interfacepropertiesrecursionrhino-mocks

I'm trying to unittest several MVP implementations and can't quite figure out the best way to mock the view. I'll try to boil it down. The view IView consists e.g. of a property of type IControl.

 interface IView
{
    IControl Control1 { get; }
    IControl Control2 { get; }
}

interface IControl
{

    bool Enabled { get; set; }

    object Value { get; set; }

}

My question is whether there's a simple way to setup the property behavior for Enabled and Value on the IControl interface members on the IView interface – like recursive mocking a guess. I would rather not setup expectations for all my properties on the view (quite a few on each view).

Thanks in advance

Best Answer

You will have to set the behavior of each IControl instance separately. You cannot define the behavior on the type level.

If your scenario really is this simple, I would consider making a ValidControl and an InvalidControl that both implement IControl, and just use instances of those instead of mocking IControl with Rhino Mocks. You should probably still mock IView because you don't seem to have a way of setting the controls on the view.