Is there a way to use Rhino Mocks to create a Stub for IObjectSet<T>
?
What is am after, is something like the following code:
var context = MockRepository.GenerateMock <IContext>();
var mockProjectObjectSet = MockRepository.GenerateStub<IObjectSet<Project>>();
TestObjectSets.GenerateFakeProjectList(mockProjectObjectSet);
context.Expect(p => p.Projects).Return(mockProjectObjectSet);
var projectRepository = new ProjectRepository(context);
In the static helper method, GenerateFakeProjectList
I simply create objects of the specified type and add them to the stub using the method AddObject
on IObjectSet
:
public static IObjectSet<Project> GenerateFakeProjectList(IObjectSet<Project> projectsObjectSet)
{
projectsObjectSet.AddObject(new Project()
{
Categories = null,
DateCreated = DateTime.Now.AddDays(-10),
.......
source
share