Mocking a non-settable child property with Rhino Mocks
Posted
by Marcus
on Stack Overflow
See other posts from Stack Overflow
or by Marcus
Published on 2010-04-22T11:52:46Z
Indexed on
2010/04/22
12:43 UTC
Read the original article
Hit count: 317
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...
© Stack Overflow or respective owner