I want to create an IList of objects that are all different concrete types, so:
var tasks = new List<ITask>();
foreach (string taskName in taskNames)
{
var task = MockRepository.GenerateStub<ITask>();
task.Stub(t => t.Name).Return(taskName);
tasks.Add(task);
}
return tasks;
The problem is that each stub object is all the same concrete type. Normally this is fine, but I have a case where I want to test each one being a different type. Can I somehow configure Rhino Mocks to do this, in this case?
EDIT:
The "you-must-be-doing-it-wrong-crew" are out in force today. Since you all seem to think I need to justify my use-case before you can take a stab at answering my question, here's what I'm doing:
So, I hope you can see why I need the test logic. So far I've had to write my own Stub factory that generates from a limited pool of concrete ITask types. It works, but I'd rather let Rhino Mocks do it for me.
You could add a ITask.Type
property.
The code which is interested in the type behind the interface should then use this property instead of calling GetType()
. In your tests, it then becomes trivial to take control of what the Type
property returns for any given ITask
stub.