How to run a function when return value is void upon setup in Moq

Viewed 682

So when there is a return value, I can do this in Moq

mockStudentRepository.Setup(m => m.Create(It.IsAny<IStudent>())).Returns<IStudent>(s =>
{
    students.Add(s);
    return 1;
});

so this lambda gets ran as the mock implementation of the repository.

How do I do this when a method returns void? When I try the same code, Returns is not available. I have something like this right now:

mockStudentRepository.Setup(m => m.Update(It.IsAny<IStudent>()));

I want to put a lambda that will run when Update is called much like the first code above. How can I do this?

1 Answers
Related