Category: Moq

The Right Way to Do Automocking with Ninject

While StructureMap is definitely my IoC container of choice, it’s not the only game in town.  At my new job, our existing project uses Ninject.   One of my first tasks at this new job was integrating my SpecsFor “framework” into the existing projects.  The original version of SpecsFor worked with StructureMap and leveraged its auto-mocking…

Read More

Easily override ToString using Moq

I recently discovered a rather annoying limitation in Moq: you cannot setup expectations on the ToString method.  For a good discussion of the issue, check out Sean’s post.  His solution was to add ToString explicitly to the interface you are mocking, but I don’t want to dirty up my interfaces unnecessarily.  Fortunately, Moq does allow…

Read MoreView 3 Comments

Extending Moq: returning multiple results via lambdas

I have on several occasions wished that I could setup expectations in Moq for subsequent calls to a method.  For example, I might want Moq to return one value the first time a method is called, but a different value the second and third times.  Phil Haack has a nice way to achieve this, but…

Read MoreView 11 Comments