Verification method and property invocations with Moq

Mock behaviors are specified during the setup. This is the expected behavior of an object and the collaborator. While unit testing, mocking is not complete until all the mocked dependencie's invocations have been verified. It can be helpful to be aware of the number of times methods were executed or properties accessed.

The Moq framework has useful verification methods that can be used to verify mocked methods and properties. Also, the Times structure contains useful members showing the number of calls that can be allowed on a method.

The Verify method can be used to verify that a method invocation, together with the supplied parameters performed on a mock, match what was earlier configured ...

Get C# and .NET Core Test Driven Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.