No Dogma Blog (Bryan Hogan)
Read post

Two Ways to Count the Number of Times a Mocked Method is Called With Moq

Two approaches for counting how many times a mocked method is called using the Moq library in C#. The first uses Moq's built-in `Verify` method with `Times.Exactly()`, which is purpose-built for this scenario. The second uses the `Callback` method to manually increment a counter and then assert its value. Both approaches support `It.IsAny<>` for flexible parameter matching.

    #testing#c#
May 31•3m read time•From nodogmablog.bryanhogan.net
Post cover image
2 Impressions
No Dogma Blog (Bryan Hogan)'s image
No Dogma Blog (Bryan Hogan)

1 Followers

•

7 Upvotes

Would you recommend this post?

Copy link
WhatsApp
Facebook
X
New Squad
  • © 2026 Daily Dev Ltd.
  • Guidelines
  • Explore
  • Tags
  • Sources
  • Squads
  • Leaderboard