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"));

Silverlight extra day of PDC...

Register now!

 

Learn about the future of Silverlight from Corporate Vice President, Scott Guthrie and other experts, direct from Microsoft’s HQ.

http://www.silverlight.net/news/events/firestarter/

 

If you are a INETA User Group Leader or INETA Country Lead er, please help us to deliver this message and spread it. Thanks!

 

Recent Tweets

Note: For Customization and Configuration, CheckOut Recent Tweets Documentation

Calendar

<<  July 2017  >>
MoTuWeThFrSaSu
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

View posts in large calendar

Month List