# Wednesday, October 27, 2010

We have just published a new game where you have to figure out the secret regular expression. Try it out, you might be surprised what you will find there.


posted on Wednesday, October 27, 2010 11:15:17 PM (Pacific Daylight Time, UTC-07:00)  #    Comments [1]
# Thursday, September 16, 2010

We just released Pex and Moles v0.94 which brings MSBuild support for Moles! 

Moles is now entirely based on MSBuild and does not require to check in any generated files. All the previous headaches related to locked files in TFS are now a history. Moles assemblies will be generated on demand during the build. We strongly recommend you read the upgrade instructions in the release to see how you can smoothly upgrade to v0.94.

And while the installer is running, don’t forget to solve a duel or two at http://www.pexforfun.com

Cheers, the Pex Team.

posted on Thursday, September 16, 2010 9:05:30 PM (Pacific Daylight Time, UTC-07:00)  #    Comments [1]
# Thursday, September 09, 2010

Ever wanted to see the Code Contracts directly in your Intellisense? Well, it is possible now thanks to the Code Contracts Editor Extensions. Get it now on Visual Studio Code Gallery!

Code Contracts Editor Extensions

posted on Thursday, September 09, 2010 4:26:42 AM (Pacific Daylight Time, UTC-07:00)  #    Comments [1]
# Monday, August 23, 2010

We have added a new step-by-step tutorial to help testing Asp.NET applications with Pex and Moles. You will find as part of the installer or simply at


posted on Monday, August 23, 2010 10:15:33 PM (Pacific Daylight Time, UTC-07:00)  #    Comments [1]
# Monday, June 28, 2010

Is there anything else to say than… try it out now at http://www.pexforfun.com !


posted on Monday, June 28, 2010 2:35:18 PM (Pacific Daylight Time, UTC-07:00)  #    Comments [0]
# Monday, June 07, 2010

We’ve just released a new version of Pex and Moles v0.92. This version brings Rex integration (smarter about regular expressions), Silverlight support (Alpha) and a number of bugs/improvements here and there.

Read all about the new stuff on the release notes page. Happy Pexing!

posted on Monday, June 07, 2010 12:13:52 PM (Pacific Daylight Time, UTC-07:00)  #    Comments [2]
# Friday, June 04, 2010

I just uploaded a refresh of the QuickGraph binaries with Code Contracts references and documentation instrumented with the Contracts.


posted on Friday, June 04, 2010 7:34:36 AM (Pacific Daylight Time, UTC-07:00)  #    Comments [0]
# Monday, May 24, 2010

Are you using Code Contracts ? or not? Give us 5 minutes of your time and fill up the survey that the BCL has put up…


posted on Monday, May 24, 2010 8:42:30 PM (Pacific Daylight Time, UTC-07:00)  #    Comments [0]
# Tuesday, May 18, 2010


This post shows how you can leverage the un-typed Detours API to extend any mock framework to support static methods, sealed types, etc…

Moles is an isolation framework for .NET that the Pex team designed to make Pex happy. It relies heavily on delegates and comes with a syntax of its own. Moles is actually a simple strongly typed layer on top of a un-typed general purpose detour API. If you do not like the Moles syntax, you can still leverage the detours API to deal with static methods or sealed types.

Let us see how we can use the detour API to build a micro-mock-framework using expressions trees. Let’s call it Deq.

The Challenge

As usual, we’ll toy with an example where we need a very particular DateTime.Now value. Since DateTime.Now is a struct living in mscorlib.dll, it cannot be mocked using traditional approaches –DateTime.Now can’t be overloaded. The test case looks like this and will most likely fail.

image The Whish

We would like to be able to replace the implementation of DateTime.Now with a method that always returns the year 2000 in the context of the test. If possible, we would like to use a strongly typed, Linq-ish, expression tree based syntax to do this. For example, we could think that a Deq class would define a Replace(Expression<Func<T>> method, Func<T> detour) method that would achieve this detour:


 Implementing Deq on top of MoleRuntime

The implementation of Deq.Replace relies on MoleRuntime.SetMole, an un-typed API to replace methods that Moles builds upon. First, one needs to walk the expression tree to extract the MethodInfo that the user wanted to replace (I’m not showing this code here, it is beyond the point of this blog post). Once you have the method, you can use the Moles API to install the detour. This happens through the MoleRuntime.SetMole method and the rest is taken care of the Moles runtime.

imageThat’s it. You’ve just written a micro-mock framework that can isolate from static methods.

To get this code to compile, you will need a reference to Microsoft.ExtendedReflection.dll and Microsoft.Moles.Framework.dll. Also, since the Replace method only works for the Func<T> method, you’ll probably want to write a T4 template that takes care of all the other delegates (Func<T,T2>, Action<…> etc…).

Deq Sources?

The Deq sources are available in the Samples solution that ships with Pex.

posted on Tuesday, May 18, 2010 9:30:10 AM (Pacific Daylight Time, UTC-07:00)  #    Comments [0]
# Sunday, May 16, 2010

Nikolai Tillmann announced it on our page, he just finished integrating Rex in to Pex….

posted on Sunday, May 16, 2010 9:55:16 PM (Pacific Daylight Time, UTC-07:00)  #    Comments [0]