Search code examples
interfacerecursionpropertiesrhino-mocks

Recursive mocking with Rhino-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


Solution

  • Thanks for the respons. A colleague of min suggested that I used reflection to assign the PropertyBehavior in the IControl elements. This way I can still mock the view and don't have to write reduntant code for each view i have. Something like this: haacked.com/archive/2007/05/04/… If anyone have any other thoughts, please comment