Checking Received Calls

It is often necessary to verify whether some fake-object method or property was called (and how many times it was called). You can check this by using Verify static class. It has the following features:

Verifying that a method or property get accessor was called:

Verify.WasCalled(() => shapeFake.Draw());

Verifying that a method or property get accessor was never called:

Verify.WasCalled(() => shapeFake.Draw(), Times.Never);

Verifying that a method or property get accessor was called by a given number of times:

Verify.WasCalled(() => shapeFake.Draw(), Times.Exactly(3));

Verifying that a method or property get accessor was called at least N times:

Verify.WasCalled(() => shapeFake.Draw(), Times.AtLeast(3));

Verifying that a method or property get accessor was called from 1 to N times:

Verify.WasCalled(() => shapeFake.Draw(), Times.LessThen(3));

Verifying that a method or property get accessor was called from N through M times:

Verify.WasCalled(() => shapeFake.Draw(), Times.Between(2, 4));

Verifying that a property was set:

Verify.PropertyWasSet(() => shapeFake.Name);

Verifying that a property was set a specified value:

Verify.PropertyWasSet(() => shapeFake.Name, "Ellipse");

If the actual behavior is not the same as the expected (for example, if the method was called more times than expected) during assertion, it throws CallCountException.

You can also see how many times the method or property has been called:

var shapeDrawCount = Verify.GetCallsCount(() => shapeFake.Draw());
var nameSetCount = Verify.GetPropertySetCallsCount(() => shapeFake.Name, "Rectangle");