views:

42

answers:

1

I have a scenario like this:

 form = MockRepository.GenerateMock<IAddAddressForm>();
 mediator = new AddAddressMediator(form);

The mediator is the real object under test and needs to be able to set values for the "form" object.

But the only way I can see to set values for the form object is like this:

  form.Stub(x=>x.FirstName).Return(item.FirstName)

I don't want to be doing that in my real code.

Am I missing the point of mocks?

+1  A: 

Stubs have built in support for property behaviour. In cases where you aren't using stubs, you can use the PropertyBehaviour() method for a similar effect.

Within the mediator, you should be using the form object normally -- it should not know that it has been handed a fake object.

This code:

form.Stub(x=>x.FirstName).Return(item.FirstName)

should not be in your real object, but may be part of your test to set up the expectations for how you will use your mock object.

Edit:

From what you've provided, I can't judge whether you're "missing the point of mocks". The essential purpose is to provide a way to test code that has dependencies in isolation from those dependencies. Have a look at Martin Fowler's essay "Mocks Aren't Stubs", and the Usage Guidance section of the Rhino Mocks documentation.

Nader Shirazie
Sweet Answer! Thank you so much (I wish I could vote you up twice!)
Vaccano
haha cheers :) happy to be of service...
Nader Shirazie