I am trying to test the following code
public void CleanUp()
{
List<ITask> tasks = _cleanupTaskFactory.GetTasks();
//Make sure each task has the task.Execute() method called on them
}
In my test I create a mocked implementation of _cleanupTaskFactory, and I want to stub the GetTasks() method to return a type:
List<Mock<ITask>>
…but the compiler won’t accept that as a return value.
My goal is to ensure that each task returned has the .Execute() method called on it using the Verify() MoQ method.
How can I assert that each task gets executed?
In your
_cleanUpTaskFactorymock you could simply do something like the following:Now make sure to keep a reference to the
mockslist, and when you done with your testing you iterate over all the mocks and callVerify()like so: