A Basic Code Example using Moq

Moq is a great framework that allows you to unit test part of your application that wouldn't otherwise be possible.  As we work with Microsoft, you might have code that's reliant on the HttpContext, or an SMTP provider to work.  When you run tests yo[...]

Useful Moq Code Snippets

When you're aiming for high test coverage in your website, you'll inevitably need to test things like service locators, the HTTP context, controllers, base class and a host of other weird and wonderful classes.  In today's tutorial, I'm going to quic[...]

How To Use Moq To Ensure A Method Was Called, or, Not Called!

When we write tests and we're using dependency injection, we sometimes want to test that a certain method was called (or in some instances NOT called).  Moq makes this really easy with its Verify() method.   How To Use Moq To Make Sure A Method Gets[...]

How To Perform Logic In Your Moq Returns

I recently needed to test a method that took in a string and a list of integers, and then return a matching object the input ID matched the ID in the database.  After a quick Google, I couldn't find how to do this easily, so here it's a quick code ex[...]

Moq - How To Deal With Invalid Verify On A Non-Virtual

Often when we want to write unit tests, we need to work with third-party code which we can't change.  Moq is a great free library, but it sadly can't mock non-virtual methods or properties.  This can be a pain but, usefully, it is fixable. I think in[...]

Homepage C Sharp Bootcamp TDD Mocking
Back to top