views:

166

answers:

1

Hi

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

A: 

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.

martinnjensen
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: http://haacked.com/archive/2007/05/04/setting-propertybehavior-on-all-properties-with-rhino-mocks.aspxIf anyone have any other thoughts, please comment.
jaspernygaard