Mocking a non-settable child property with Rhino Mocks
- by Marcus
I currently have interfaces much like the following:
interface IService
{
void Start();
IHandler ServiceHandler { get; }
}
interface IHandler
{
event EventHandler OnMessageReceived;
}
Using Rhino Mocks, it's easy enough to mock IService, but it doesn't assign any IHandler instance to the ServiceHandler property. Therefore when my method under test adds an event handler to _mockedService.ServiceHandler.OnMessageReceived, I get an 'Object reference not set' error.
How can I ensure that ServiceHandler is assigned a value in the mocked IService instance?
This is likely Rhino Mocks 101, but I'm just getting up to speed on it...