In my interface
public IMyListInterface : IList<IMyItem>
{
void Foo();
}
how can I easily create an example for testing classes that use IMyListInterface.
Currently I’m using GenerateStub<MyListInterface>() and delegating the needed methods / properties to a List<IMyItem> list but it’s tedious.
Currently to get the following code under test to work
foreach (var match in matchList)
I’m doing the following in my test class
IList<IMyItem> baseList = new List<IMyItem>();
IMyListInterface matchList = MockRepository.GenerateStub<IMyListInterface>();
matchList.Stub(m => m.GetEnumerator()).Return(null).WhenCalled(i => i.ReturnValue = baseList.GetEnumerator());
Is there a better way?
Implement the interface in an abstract base class for testing:
You can then use
MockRepository.GenerateStub<MyMockableList>(), which will function as a normal list (RhinoMocks won’t override the methods inherited fromList<MyItem>) but you can still stub out theFoo()method.