Moq

How many of you create your own mocks? I've recently been using Mocq and I give it the thumbs up :-)

 Note it's using .net 3.5; time for an upgrade? I can't stress enough how much I love linq, today worked on a problem for a client that were using 3.0; it's a true saying " you never miss the water till the well runs dry" ! 

I wonder however I ever lived without it. 

 Anyway:

Moq (pronounced "Mock-you" or just "Mock") is the only mocking library for .NET developed from scratch to take full advantage of .NET 3.5 (i.e. Linq expression trees) and C# 3.0 features (i.e. lambda expressions) that make it the most productive, type-safe and refactoring-friendly mocking library available. And it supports mocking interfaces as well as classes. Its API is extremely simple and straightforward, and doesn't require any prior knowledge or experience with mocking concepts.

 

var mock = new Mock<ILoveThisFramework>(); 
 
// WOW! No record/replay weirdness?! :) 
mock
.Setup(framework => framework.DownloadExists("2.0.0.0")) 
   
.Returns(true) 
   
.AtMostOnce(); 
 
// Hand mock.Object as a collaborator and exercise it,  
// like calling methods on it... 
ILoveThisFramework lovable = mock.Object; 
bool download = lovable.DownloadExists("2.0.0.0"); 
 
// Verify that the given method was indeed called with the expected value 
mock
.Verify(framework => framework.DownloadExists("2.0.0.0"));