Learning Moq with The Moq Koans

Inspired by a local “Software Craftsmanship” group, and the “Coding Dojo” at CodeMash 2011, I decided to set up a weekly coding dojo at work. Every Friday, two developers spend an hour during lunch doing katas or learning something new.

One of the tools we use a lot for mocking in unit tests is Moq. I wanted to put together an exercise that would help the other developers get more familiar with Moq, and be simple enough for someone with no Moq experience at all to learn how to use it.

Drawing inspiration from the RubyKoans, I decided to put together a set of Koans for learning Moq.

My peers at work have so far found it very helpful for an easy and hands-on introduction to mocking with Moq.

Please have a took at it over on my GitHub account:
The MoqKoans on GitHub
If you do not want to checkout the project using Git, you can also:
Download the MoqKoans as a .zip file.

Tagged with: , , ,
Posted in Programming
2 comments on “Learning Moq with The Moq Koans
  1. madhead_uk says:

    does this have an update specifically for Mute_CallsQuieterRepeatedly_UntilCurrentVolumeReturnsZero how do you get the current volume with the existing quieter and louder methods? do you need to implement them so that they set the current volume ?

    • rally25rs says:

      The idea behind those was that you would implement your mock to either keep track of the current volume, or just have it return a volume of 0 after it had been called a set number of times. Then you could use mock.Verify(x => x.Quieter(), Times.Exactly(5)); to ensure that it was called the expected number of times. Sorry if it came across as a little weird. Making examples that aren’t too simple, aren’t too hard, and have some element of realism is tough 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

CodingWithSpike is Jeff Valore. A professional software engineer, focused on JavaScript, Web Development, C# and the Microsoft stack. Jeff is currently a Software Engineer at Virtual Hold Technologies.

I am also a Pluralsight author. Check out my courses!

%d bloggers like this: