I'm writing a unit test with a mock and I'm having trouble writing it successfully. One of the properties is a collection and I need to reference it when setting an expectation for the mock. Right now the expectation statement throws a null. Here's what it roughly looks like.
IFoo myMock = MockRepository.GenerateMock<IFoo>();
List<Entity> col = new List<Entity>();
Entity entity = new Entity();
myMock.Expect(p => p.FooCollection).Return(col);
myMock.Expect(p => p.FooCollection.Add(entity)); // throws null exception here
I'm new to rhino mocks and have a feeling I'm not doing this correctly. Is there anyway else to properly instantiate the collection? Possibly without an expectation like I have above?
Update
I think I'm having the problem because the interface I defined specifies the collection as readonly.
interface IFoo
{
List<Entity> FooCollection { get; }
}