How do I set a value for a Rhino Mocked object?
I have a scenario like this:
form = MockRepository.GenerateMock<IAddAddressForm>();
mediator = new AddAddressMediator(form);
A mediator is a real object that should test and should be able to set values for a form object.
But the only way to see the values for the form object is as follows:
form.Stub(x=>x.FirstName).Return(item.FirstName)
I don't want to do this in my real code.
Am I missing the point of bullying?
source to share
Stubs are built in to support property behavior. In cases where you are not using stubs, you can use the PropertyBehaviour () method for a similar effect.
Within a pick, you should normally use an object form
- it shouldn't know that a fake object was passed to it.
This code:
form.Stub(x=>x.FirstName).Return(item.FirstName)
does not have to be in your real object, but can be part of your test to set expectations for how you will use your layout.
Edit:
From what you have provided, I cannot tell if you are missing a scam. The main goal is to provide a way to test code that has dependencies in isolation from those dependencies. Take a look at Martin Fowler's essay "Mocks Are not Stubs " and the Usage Guide section of the Rhino Mocks Documentation .
source to share