What is the purpose of VerifyAll() in Moq?

Nam G VU picture Nam G VU · Sep 15, 2010 · Viewed 30.1k times · Source

I read the question at What is the purpose of Verifiable() in Moq? and have this question in my mind. Need your help to explain that.

Answer

ema picture ema · Sep 15, 2010

VerifyAll() is for verifying that all the expectations have been met. Suppose you have:

myMock.Setup(m => m.DoSomething()).Returns(1);
mySut.Do();
myMock.VerifyAll(); // Fail if DoSomething was not called

HTH