<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>Peli's Farm - Pex, Stubs, QuickGraph, MbUnit, Reflector Addins</title>
    <link>http://blog.dotnetwiki.org/</link>
    <description>Pex, Stubs, QuickGraph, MbUnit, Reflector Addins</description>
    <language>en-us</language>
    <copyright>Jonathan 'Peli' de Halleux</copyright>
    <lastBuildDate>Fri, 12 Jun 2009 02:14:58 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.2.8279.16125</generator>
    <managingEditor>jonathan.dehalleux@gmail.com</managingEditor>
    <webMaster>jonathan.dehalleux@gmail.com</webMaster>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/PelisFarm" type="application/rss+xml" /><item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=8128b319-4e2b-4a36-98b7-7b123a4d1bf5</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,8128b319-4e2b-4a36-98b7-7b123a4d1bf5.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,8128b319-4e2b-4a36-98b7-7b123a4d1bf5.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=8128b319-4e2b-4a36-98b7-7b123a4d1bf5</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We have just released a new version of <a href="http://research.microsoft.com/pex" target="_blank">Pex</a>,
v0.14.040610.2. This version brings a range of <strong>Bug Fixes</strong> that were
reported on the <a href="http://social.msdn.microsoft.com/Forums/en-US/pex/threads" target="_blank">MSDN
forums</a> and a couple new features: <strong>Fix Suggestions for Invariant Methods
and Natural properties  for </strong><a href="http://research.microsoft.com/stubs" target="_blank"><strong>Stubs</strong></a><strong>.</strong></p>
        <p>
          <b>Fix Suggestions for Invariant Methods</b>
        </p>
        <p>
When you use <a href="http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx">Code
Contracts</a>, then Pex can now help you to add missing invariants, just as Pex already
inferred missing preconditions in the past. Take for example the ArrayList class that
comes with the <a href="http://research.microsoft.com/en-us/projects/pex/pexpublictutorialsamples.zip">samples</a> of
our recently updated <a href="http://research.microsoft.com/en-us/projects/pex/pexpublictutorialslides.pptx/">tutorial
slide deck</a>. This class has the following fields:
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/clip_image002_2.jpg">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/clip_image002_thumb.jpg" width="244" height="60" />
          </a>
        </p>
        <p>
When you add an empty invariant method,
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/clip_image004_2.jpg">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/clip_image004_thumb.jpg" width="240" height="58" />
          </a>
        </p>
        <p>
and enable Runtime Checking of contracts, then Pex will create instances of this class
using reflection while making sure that the invariants holds (we announced this feature
in the <a href="http://blogs.msdn.com/nikolait/archive/2009/05/28/pex-0-13-released-unit-tests-as-inputs-fuzzing-and-visual-studio-2010-beta-1-f-beta-1-support.aspx">last
release</a>). However, with an empty invariant method, Pex will be able to create
illegal states, e.g. where the _items array is null, which may cause a NullReferenceException,
and other issues. To get the following test cases, we let Pex explore the Add method
of our ArrayList class:
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/clip_image006_2.jpg">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/clip_image006_thumb.jpg" width="627" height="149" />
          </a>
        </p>
        <p>
When you look at the details of the failing test cases, then you will see that Pex
now offers the option to add invariants directly into your [ContractInvariantMethod]:
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/image_8.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/image_thumb_3.png" width="581" height="204" />
          </a>
        </p>
        <p>
          <strong>Natural Properties for Stubs</strong>
        </p>
        <p>
The logic to handle properties with setters and getters generated by Stubs has been
slightly improved so that it is possible to force properties to have as if they had
a backing field.
</p>
        <p>
When a getter or a setter of a property is invoked, Stubs checks whether the getter
delegate or the setter delegates have been set. If not, i.e. no custom user behavior,
it queries the fallback behavior for an initial value of the property. If the fallback
behavior successfully returns a value, Stubs generates a closure and binds the getter
and setter.
</p>
        <p>
For example, here’s a simple IFoo interface with a Bar property:
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/image_2.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/image_thumb.png" width="242" height="81" />
          </a>
        </p>
        <p>
One could write the following parameterized unit test:
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/image_4.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/image_thumb_1.png" width="364" height="113" />
          </a>
        </p>
        <p>
Since we expect the Bar property to behave as it was wrapping a field, we don’t expect
the assertion to be raised. When we execute this test with Pex, and the Pex fallback
behavior, Pex will choose a value for ‘Bar’, and this value will be ‘stored’ the property.
Therefore, we get as expected 2 test cases:
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/image_6.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/image_thumb_2.png" width="210" height="78" />
          </a>
        </p>
        <p>
        </p>
        <p>
          <strong>Non default constructor support for Stubs</strong>
        </p>
        <p>
In previous versions, Stubs could not generate stubs for classes with no default constructor.
This is no longer the case, Stubs will generate one public constructor for each public
or protected base constructor.
</p>
        <p>
          <strong>Bug Fixes</strong>
        </p>
        <ul>
          <li>
Various code generation tweaks to make <a href="http://code.msdn.microsoft.com/sourceanalysis" target="_blank">StyleCop</a> happier 
</li>
          <li>
Visual Studio addin crashes when loading in VS2010 
</li>
          <li>
Visual Studio addin does not find attributes when they are globally qualified 
</li>
          <li>
Added missing substitutions for System.Threading.Interlocked members 
</li>
          <li>
Stubs automatically imports missing references 
</li>
          <li>
When an object has an invariant method (from Code <a href="http://research.microsoft.com/contracts" target="_blank">Contracts</a>),
Pex would emit assertions using the private fields 
</li>
          <li>
Editorial issues to patterns paper 
</li>
          <li>
Contracts no longer kill the process when the runtime rewriter was not executed (.net
4.0) 
</li>
          <li>
Fixed bug in generic type guesser 
</li>
          <li>
Fixed samples for the latest version of Stubs 
</li>
        </ul>
        <p>
          <strong>As always, don’t hesitate to send us your feedback, good or bad, through our <a href="http://social.msdn.microsoft.com/Forums/en-US/pex/threads/" target="_blank">MSDN
forums</a>.</strong>
        </p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=8128b319-4e2b-4a36-98b7-7b123a4d1bf5" />
      </body>
      <title>Pex 0.14.040610.2: Fix Suggestions for Invariant Methods and Natural properties for Stubs.</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,8128b319-4e2b-4a36-98b7-7b123a4d1bf5.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/BLazwoMuZJI/Pex0140406102FixSuggestionsForInvariantMethodsAndNaturalPropertiesForStubs.aspx</link>
      <pubDate>Fri, 12 Jun 2009 02:14:58 GMT</pubDate>
      <description>&lt;p&gt;
We have just released a new version of &lt;a href="http://research.microsoft.com/pex" target="_blank"&gt;Pex&lt;/a&gt;,
v0.14.040610.2. This version brings a range of &lt;strong&gt;Bug Fixes&lt;/strong&gt; that were
reported on the &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/pex/threads" target="_blank"&gt;MSDN
forums&lt;/a&gt; and a couple new features: &lt;strong&gt;Fix Suggestions for Invariant Methods
and Natural properties&amp;#160; for &lt;/strong&gt;&lt;a href="http://research.microsoft.com/stubs" target="_blank"&gt;&lt;strong&gt;Stubs&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;.&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;b&gt;Fix Suggestions for Invariant Methods&lt;/b&gt;
&lt;/p&gt;
&lt;p&gt;
When you use &lt;a href="http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx"&gt;Code
Contracts&lt;/a&gt;, then Pex can now help you to add missing invariants, just as Pex already
inferred missing preconditions in the past. Take for example the ArrayList class that
comes with the &lt;a href="http://research.microsoft.com/en-us/projects/pex/pexpublictutorialsamples.zip"&gt;samples&lt;/a&gt; of
our recently updated &lt;a href="http://research.microsoft.com/en-us/projects/pex/pexpublictutorialslides.pptx/"&gt;tutorial
slide deck&lt;/a&gt;. This class has the following fields:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/clip_image002_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/clip_image002_thumb.jpg" width="244" height="60" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
When you add an empty invariant method,
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/clip_image004_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/clip_image004_thumb.jpg" width="240" height="58" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
and enable Runtime Checking of contracts, then Pex will create instances of this class
using reflection while making sure that the invariants holds (we announced this feature
in the &lt;a href="http://blogs.msdn.com/nikolait/archive/2009/05/28/pex-0-13-released-unit-tests-as-inputs-fuzzing-and-visual-studio-2010-beta-1-f-beta-1-support.aspx"&gt;last
release&lt;/a&gt;). However, with an empty invariant method, Pex will be able to create
illegal states, e.g. where the _items array is null, which may cause a NullReferenceException,
and other issues. To get the following test cases, we let Pex explore the Add method
of our ArrayList class:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/clip_image006_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/clip_image006_thumb.jpg" width="627" height="149" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
When you look at the details of the failing test cases, then you will see that Pex
now offers the option to add invariants directly into your [ContractInvariantMethod]:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/image_8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/image_thumb_3.png" width="581" height="204" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Natural Properties for Stubs&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
The logic to handle properties with setters and getters generated by Stubs has been
slightly improved so that it is possible to force properties to have as if they had
a backing field.
&lt;/p&gt;
&lt;p&gt;
When a getter or a setter of a property is invoked, Stubs checks whether the getter
delegate or the setter delegates have been set. If not, i.e. no custom user behavior,
it queries the fallback behavior for an initial value of the property. If the fallback
behavior successfully returns a value, Stubs generates a closure and binds the getter
and setter.
&lt;/p&gt;
&lt;p&gt;
For example, here’s a simple IFoo interface with a Bar property:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/image_thumb.png" width="242" height="81" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
One could write the following parameterized unit test:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/image_thumb_1.png" width="364" height="113" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Since we expect the Bar property to behave as it was wrapping a field, we don’t expect
the assertion to be raised. When we execute this test with Pex, and the Pex fallback
behavior, Pex will choose a value for ‘Bar’, and this value will be ‘stored’ the property.
Therefore, we get as expected 2 test cases:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.xxBugfixesNaturalPropertiesandnondef_7CD8/image_thumb_2.png" width="210" height="78" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Non default constructor support for Stubs&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
In previous versions, Stubs could not generate stubs for classes with no default constructor.
This is no longer the case, Stubs will generate one public constructor for each public
or protected base constructor.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Bug Fixes&lt;/strong&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Various code generation tweaks to make &lt;a href="http://code.msdn.microsoft.com/sourceanalysis" target="_blank"&gt;StyleCop&lt;/a&gt; happier 
&lt;/li&gt;
&lt;li&gt;
Visual Studio addin crashes when loading in VS2010 
&lt;/li&gt;
&lt;li&gt;
Visual Studio addin does not find attributes when they are globally qualified 
&lt;/li&gt;
&lt;li&gt;
Added missing substitutions for System.Threading.Interlocked members 
&lt;/li&gt;
&lt;li&gt;
Stubs automatically imports missing references 
&lt;/li&gt;
&lt;li&gt;
When an object has an invariant method (from Code &lt;a href="http://research.microsoft.com/contracts" target="_blank"&gt;Contracts&lt;/a&gt;),
Pex would emit assertions using the private fields 
&lt;/li&gt;
&lt;li&gt;
Editorial issues to patterns paper 
&lt;/li&gt;
&lt;li&gt;
Contracts no longer kill the process when the runtime rewriter was not executed (.net
4.0) 
&lt;/li&gt;
&lt;li&gt;
Fixed bug in generic type guesser 
&lt;/li&gt;
&lt;li&gt;
Fixed samples for the latest version of Stubs 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;strong&gt;As always, don’t hesitate to send us your feedback, good or bad, through our &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/pex/threads/" target="_blank"&gt;MSDN
forums&lt;/a&gt;.&lt;/strong&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=8128b319-4e2b-4a36-98b7-7b123a4d1bf5" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,8128b319-4e2b-4a36-98b7-7b123a4d1bf5.aspx</comments>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/06/12/Pex0140406102FixSuggestionsForInvariantMethodsAndNaturalPropertiesForStubs.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=04c198f2-ca64-4e84-8fd5-e11fd04c4ad1</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,04c198f2-ca64-4e84-8fd5-e11fd04c4ad1.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,04c198f2-ca64-4e84-8fd5-e11fd04c4ad1.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=04c198f2-ca64-4e84-8fd5-e11fd04c4ad1</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://en.wikipedia.org/wiki/Inversion_of_control" target="_blank">Inversion
of Control</a> (IoC) is a very important practice to make code testable. It usually
relies on defining interfaces for each external dependency. Various frameworks and
techniques, i.e. <a href="http://en.wikipedia.org/wiki/Dependency_injection" target="_blank">Dependency
Injection</a> (DI), <a href="http://en.wikipedia.org/wiki/Service_locator_pattern" target="_blank">Service
Locator</a>, exist to bind the interface implementations to the components. In this
blog post, we will *not* focus on this aspects of IoC but rather on it’s main building
block: <em>interfaces</em>. This article describes how <strong>Contracts for interfaces
improves IoC… <em>regardless of which DI framework/technique you are using.</em></strong>The
Contracts for interfaces are a feature of the <a href="http://research.microsoft.com/contracts" target="_blank">Code
Contracts for .Net</a> tool.
</p>
        <h3>Interfaces are not Contracts
</h3>
        <p>
Interfaces are often referred to as <em>Contracts</em> in the context of IoC: they
define the methods and properties that a service should implement and are a key factor
in achieving the loose coupling: one can build the code against the interface and
can plug in various implementation with no risks.
</p>
        <p>
Unfortunately, <a href="http://blogs.msdn.com/kcwalina/archive/2004/10/24/246947.aspx" target="_blank">interfaces
are not contracts</a>: while they specify how the methods signatures should be, <strong>interfaces
do not specify the functional behavior</strong>. To illustrate this, let’s take a
look at a well-known simple interface of the BCL:
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/DependencyInjectionContractsforInterface_5E38/image_4.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/DependencyInjectionContractsforInterface_5E38/image_thumb_1.png" width="398" height="64" />
          </a>
        </p>
        <p>
For this interface, I could naively implement as follows:
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/DependencyInjectionContractsforInterface_5E38/image_6.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/DependencyInjectionContractsforInterface_5E38/image_thumb_2.png" width="406" height="93" />
          </a>
        </p>
        <p>
While my implementation is really really wrong, it fulfills all requirements of the
IServiceProvider interface: a method GetService that returns object. Of course, if
I would have read the MSDN documentation of GetService, I would have known that object
should implement serviceType. Unfortunately, the interface did not tell me anything
about that and compilers don’t understand MSDN documentation either. 
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/DependencyInjectionContractsforInterface_5E38/image_2.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/DependencyInjectionContractsforInterface_5E38/image_thumb.png" width="386" height="267" />
          </a> 
</p>
        <h3>Contracts for interfaces
</h3>
        <p>
Code Contracts provides <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.contracts(VS.100).aspx" target="_blank">an
API for design-by-contracts</a> (pre-condition, post-condition, etc…). It also supports
defining contracts for interface or abstract classes. <strong>Contracts for interfaces
can be used to specify the functional behavior of interface members.</strong> While
they also serve as documentation, those contracts can also be turned into runtime
checks or leveraged by static checkers. 
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/DependencyInjectionContractsforInterface_5E38/image_8.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/DependencyInjectionContractsforInterface_5E38/image_thumb_3.png" width="627" height="318" />
          </a>
        </p>
        <p>
        </p>
        <p>
        </p>
        <ul>
          <li>
since interface members cannot have method bodies, the contracts are stored in a ‘buddy’
type. 
</li>
          <li>
The [<a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.contracts.contractclassattribute(VS.100).aspx" target="_blank">ContractClass</a>]/[<a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.contracts.contractclassforattribute(VS.100).aspx" target="_blank">ContractClassFor</a>]
attributes bind the interface type and the contract type together. 
</li>
          <li>
            <a href="http://msdn.microsoft.com/en-us/library/dd412873(VS.100).aspx" target="_blank">Contract.Result&lt;object&gt;()</a> is
a helper method to refer to the result value, since this is not supported in C#. 
</li>
        </ul>
        <p>
Let’s take a closer look at the body of IServiceProviderContract.GetService. It contains
a pre-condition (Requires) that the serviceType should not be null and a post-condition
(Ensures) that the return value should be null or should be assignable to the serviceType:
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/DependencyInjectionContractsforInterface_5E38/image_10.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/DependencyInjectionContractsforInterface_5E38/image_thumb_4.png" width="561" height="96" />
          </a>
        </p>
        <p>
In this simple case, the contracts captured precisely the specification that we found
in MSDN. The critical difference is that they are stored in a format that compilers
and runtimes know pretty well: MSIL byte code. The benefits are huge:
</p>
        <ul>
          <li>
documentation: the contracts are stored in a programming-language agnostic format
that mined and rendered for your favorite programming language, 
</li>
          <li>
static checking: static analysis tools can (and will) use contract to try to find
bugs before you execute the code, or prove that it is correct with respect to the
contracts, 
</li>
          <li>
            <strong>runtime checking: the runtime checker will instrument all implementations
of the interface with the interface contracts <em>automatically</em>. </strong>Once
you’ve specified how an interface should behave, you do not have to repeat yourself
when re-implementing it, the re-writer takes care of that. 
</li>
          <li>
automated white box testing:<strong />tools like <a href="http://research.microsoft.com/pex" target="_blank">Pex</a> can
leverage the runtime contract checks to try to find inputs that violate the contracts. 
</li>
          <li>
            <strong>IoC/DI framework agnostic: </strong>It does not matter which DI framework
you use, as soon as you use interface, you could also provide contracts for it. 
</li>
        </ul>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=04c198f2-ca64-4e84-8fd5-e11fd04c4ad1" />
      </body>
      <title>Specifying Inversion of Control through Contracts for Interfaces</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,04c198f2-ca64-4e84-8fd5-e11fd04c4ad1.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/oG0124nXCiM/SpecifyingInversionOfControlThroughContractsForInterfaces.aspx</link>
      <pubDate>Wed, 03 Jun 2009 00:14:03 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://en.wikipedia.org/wiki/Inversion_of_control" target="_blank"&gt;Inversion
of Control&lt;/a&gt; (IoC) is a very important practice to make code testable. It usually
relies on defining interfaces for each external dependency. Various frameworks and
techniques, i.e. &lt;a href="http://en.wikipedia.org/wiki/Dependency_injection" target="_blank"&gt;Dependency
Injection&lt;/a&gt; (DI), &lt;a href="http://en.wikipedia.org/wiki/Service_locator_pattern" target="_blank"&gt;Service
Locator&lt;/a&gt;, exist to bind the interface implementations to the components. In this
blog post, we will *not* focus on this aspects of IoC but rather on it’s main building
block: &lt;em&gt;interfaces&lt;/em&gt;. This article describes how &lt;strong&gt;Contracts for interfaces
improves IoC… &lt;em&gt;regardless of which DI framework/technique you are using.&lt;/em&gt; &lt;/strong&gt;The
Contracts for interfaces are a feature of the &lt;a href="http://research.microsoft.com/contracts" target="_blank"&gt;Code
Contracts for .Net&lt;/a&gt; tool.
&lt;/p&gt;
&lt;h3&gt;Interfaces are not Contracts
&lt;/h3&gt;
&lt;p&gt;
Interfaces are often referred to as &lt;em&gt;Contracts&lt;/em&gt; in the context of IoC: they
define the methods and properties that a service should implement and are a key factor
in achieving the loose coupling: one can build the code against the interface and
can plug in various implementation with no risks.
&lt;/p&gt;
&lt;p&gt;
Unfortunately, &lt;a href="http://blogs.msdn.com/kcwalina/archive/2004/10/24/246947.aspx" target="_blank"&gt;interfaces
are not contracts&lt;/a&gt;: while they specify how the methods signatures should be, &lt;strong&gt;interfaces
do not specify the functional behavior&lt;/strong&gt;. To illustrate this, let’s take a
look at a well-known simple interface of the BCL:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/DependencyInjectionContractsforInterface_5E38/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/DependencyInjectionContractsforInterface_5E38/image_thumb_1.png" width="398" height="64" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
For this interface, I could naively implement as follows:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/DependencyInjectionContractsforInterface_5E38/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/DependencyInjectionContractsforInterface_5E38/image_thumb_2.png" width="406" height="93" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
While my implementation is really really wrong, it fulfills all requirements of the
IServiceProvider interface: a method GetService that returns object. Of course, if
I would have read the MSDN documentation of GetService, I would have known that object
should implement serviceType. Unfortunately, the interface did not tell me anything
about that and compilers don’t understand MSDN documentation either. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/DependencyInjectionContractsforInterface_5E38/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/DependencyInjectionContractsforInterface_5E38/image_thumb.png" width="386" height="267" /&gt;&lt;/a&gt;&amp;#160;
&lt;/p&gt;
&lt;h3&gt;Contracts for interfaces
&lt;/h3&gt;
&lt;p&gt;
Code Contracts provides &lt;a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.contracts(VS.100).aspx" target="_blank"&gt;an
API for design-by-contracts&lt;/a&gt; (pre-condition, post-condition, etc…). It also supports
defining contracts for interface or abstract classes. &lt;strong&gt;Contracts for interfaces
can be used to specify the functional behavior of interface members.&lt;/strong&gt; While
they also serve as documentation, those contracts can also be turned into runtime
checks or leveraged by static checkers. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/DependencyInjectionContractsforInterface_5E38/image_8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/DependencyInjectionContractsforInterface_5E38/image_thumb_3.png" width="627" height="318" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
since interface members cannot have method bodies, the contracts are stored in a ‘buddy’
type. 
&lt;/li&gt;
&lt;li&gt;
The [&lt;a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.contracts.contractclassattribute(VS.100).aspx" target="_blank"&gt;ContractClass&lt;/a&gt;]/[&lt;a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.contracts.contractclassforattribute(VS.100).aspx" target="_blank"&gt;ContractClassFor&lt;/a&gt;]
attributes bind the interface type and the contract type together. 
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/dd412873(VS.100).aspx" target="_blank"&gt;Contract.Result&amp;lt;object&amp;gt;()&lt;/a&gt; is
a helper method to refer to the result value, since this is not supported in C#. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Let’s take a closer look at the body of IServiceProviderContract.GetService. It contains
a pre-condition (Requires) that the serviceType should not be null and a post-condition
(Ensures) that the return value should be null or should be assignable to the serviceType:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/DependencyInjectionContractsforInterface_5E38/image_10.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/DependencyInjectionContractsforInterface_5E38/image_thumb_4.png" width="561" height="96" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
In this simple case, the contracts captured precisely the specification that we found
in MSDN. The critical difference is that they are stored in a format that compilers
and runtimes know pretty well: MSIL byte code. The benefits are huge:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
documentation: the contracts are stored in a programming-language agnostic format
that mined and rendered for your favorite programming language, 
&lt;/li&gt;
&lt;li&gt;
static checking: static analysis tools can (and will) use contract to try to find
bugs before you execute the code, or prove that it is correct with respect to the
contracts, 
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;runtime checking: the runtime checker will instrument all implementations
of the interface with the interface contracts &lt;em&gt;automatically&lt;/em&gt;. &lt;/strong&gt;Once
you’ve specified how an interface should behave, you do not have to repeat yourself
when re-implementing it, the re-writer takes care of that. 
&lt;/li&gt;
&lt;li&gt;
automated white box testing:&lt;strong&gt; &lt;/strong&gt;tools like &lt;a href="http://research.microsoft.com/pex" target="_blank"&gt;Pex&lt;/a&gt; can
leverage the runtime contract checks to try to find inputs that violate the contracts. 
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IoC/DI framework agnostic: &lt;/strong&gt;It does not matter which DI framework
you use, as soon as you use interface, you could also provide contracts for it. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=04c198f2-ca64-4e84-8fd5-e11fd04c4ad1" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,04c198f2-ca64-4e84-8fd5-e11fd04c4ad1.aspx</comments>
      <category>Code Contracts</category>
      <category>Testing</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/06/03/SpecifyingInversionOfControlThroughContractsForInterfaces.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=c08175a6-efc8-4452-b7dc-92346a3033de</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,c08175a6-efc8-4452-b7dc-92346a3033de.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,c08175a6-efc8-4452-b7dc-92346a3033de.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=c08175a6-efc8-4452-b7dc-92346a3033de</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We’ve just released the <a href="http://research.microsoft.com/en-us/projects/pex/downloads.aspx" target="_blank">Pex
0.13.40528.2</a> (Nikolai <a href="http://blogs.msdn.com/nikolait/archive/2009/05/28/pex-0-13-released-unit-tests-as-inputs-fuzzing-and-visual-studio-2010-beta-1-f-beta-1-support.aspx" target="_blank">has
all the details about the new features</a>). In this release, a number of attributes
were added to force Pex produce more friendly inputs.
</p>
        <p>
          <strong>The problem with Enums</strong>
        </p>
        <p>
When you apply <a href="http://research.microsoft.com/pex" target="_blank">Pex</a> to
code that uses Enumerations, you quickly learn something: the CLR does not constraints
the enumeration values to be defined. This means than whenever you take an Enum as
a parameter, you should validate it is properly defined: 
</p>
        <blockquote>
          <p>
void Test(SomeEnum e) { 
<br />
    if (!Enum.IsDefined(typeof(SomeEnum), e)) throw new ArgumentException(“…”); 
<br />
}
</p>
        </blockquote>
        <p>
Look at the BCL code, they actually do this kind of validation. For good or bad, some
of our users have been complaining that Pex should restrict the enumeration to defined
values, in fact considering the generated failing test case as <em>noise</em>. To
restrict generated enumartion values to be defined, you can add the <strong>[PexEnumValuesDefined(typeof(SomeEnum))]</strong> attribute
on your test/fixture/assembly. Internally, this attribute attaches an invariant to
the given enumeration type that tells <a href="http://research.microsoft.com/en-us/um/redmond/projects/z3/" target="_blank">Z3</a> the
allowed values for that type.
</p>
        <p>
          <strong>What about multi-dimensional arrays</strong>?
</p>
        <p>
Ever wakened a day wanting to iterate arrays starting from –12345? Well you can with
multidimensional arrays… The Array.CreateInstance method has an overload that takes
length and <em>lower bounds</em> to instantiate multidimensional arrays:
</p>
        <blockquote>
          <p>
int[,] array = (int[,])Array.CreateInstance(typeof(int), 
<br />
    new int[] {10, 10}, // lengths 
<br /><strong>    new int[] {–12345, – 789} // lower bounds 
<br />
    </strong>); 
<br />
a[<strong>-12345, –789</strong>] = –1;
</p>
        </blockquote>
        <p>
Of course, this feels a bit weird because most languages won’t allow to create such
arrays, but the Array.CreateInstance method is still available nonetheless. It feels
a bit weird but this behavior is perfectly valid from the runtime point of view. To
restrict Pex from generating such bounds, you can add the <strong>[PexZeroMdArrayLowerBounds(0)]</strong> attribute
(one attribute per dimension).
</p>
        <p>
          <strong>What about Booleans?</strong>
        </p>
        <p>
Booleans is another interesting citizen of the CLR. At the MSIL level, the Boolean
type is really a byte, widened as an integer when on the stack. Compilers try really
hard to keep Booleans as 0 or 1 but… it is possible to craft Boolean values anywhere
the byte range <em>using safe MSIL code </em>(not from C# though or any BCL method
I know of). The implication of this are quite disturbing, for example, consider the
following parameterized test:
</p>
        <blockquote>
          <p>
[PexMethod] { 
<br />
void BooleanMadness(bool a, bool b) { 
<br /><strong>     if (a &amp;&amp; b &amp;&amp; a != b) 
<br /></strong>         throw new Exception(“this
is madness!”); 
<br />
}
</p>
        </blockquote>
        <p>
Clearly, in a word of Booleans constrained to 0 or 1, the branch that throws the exception
should be unreachable. If you execute Pex on this test, it will generate 4 test<strong> one
of which raises the exception:</strong></p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/TamingthePexWellbehavedenumsandbooleans_E75/image_2.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/TamingthePexWellbehavedenumsandbooleans_E75/image_thumb.png" width="399" height="115" />
          </a>  
</p>
        <p>
Notice the actual values (0x02, 0x03) of the Booleans in the pretty printing. If you
want Pex to generate Boolean that are restricted to 0 or 1, use the <strong>[PexBooleanAsZeroOrOne]</strong> attribute.
This attribute forces Z3 to pick boolean values as 0 or 1. Btw, there’s already a <a href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=455553" target="_blank">connect
bug</a> for this behavior.
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=c08175a6-efc8-4452-b7dc-92346a3033de" />
      </body>
      <title>Taming the Pex beast: Well-behaved enums, multi-dimensional arrays and booleans</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,c08175a6-efc8-4452-b7dc-92346a3033de.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/0p6V3DgowB8/TamingThePexBeastWellbehavedEnumsMultidimensionalArraysAndBooleans.aspx</link>
      <pubDate>Fri, 29 May 2009 00:06:06 GMT</pubDate>
      <description>&lt;p&gt;
We’ve just released the &lt;a href="http://research.microsoft.com/en-us/projects/pex/downloads.aspx" target="_blank"&gt;Pex
0.13.40528.2&lt;/a&gt; (Nikolai &lt;a href="http://blogs.msdn.com/nikolait/archive/2009/05/28/pex-0-13-released-unit-tests-as-inputs-fuzzing-and-visual-studio-2010-beta-1-f-beta-1-support.aspx" target="_blank"&gt;has
all the details about the new features&lt;/a&gt;). In this release, a number of attributes
were added to force Pex produce more friendly inputs.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;The problem with Enums&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
When you apply &lt;a href="http://research.microsoft.com/pex" target="_blank"&gt;Pex&lt;/a&gt; to
code that uses Enumerations, you quickly learn something: the CLR does not constraints
the enumeration values to be defined. This means than whenever you take an Enum as
a parameter, you should validate it is properly defined: 
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
void Test(SomeEnum e) { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; if (!Enum.IsDefined(typeof(SomeEnum), e)) throw new ArgumentException(“…”); 
&lt;br /&gt;
}
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Look at the BCL code, they actually do this kind of validation. For good or bad, some
of our users have been complaining that Pex should restrict the enumeration to defined
values, in fact considering the generated failing test case as &lt;em&gt;noise&lt;/em&gt;. To
restrict generated enumartion values to be defined, you can add the &lt;strong&gt;[PexEnumValuesDefined(typeof(SomeEnum))]&lt;/strong&gt; attribute
on your test/fixture/assembly. Internally, this attribute attaches an invariant to
the given enumeration type that tells &lt;a href="http://research.microsoft.com/en-us/um/redmond/projects/z3/" target="_blank"&gt;Z3&lt;/a&gt; the
allowed values for that type.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;What about multi-dimensional arrays&lt;/strong&gt;?
&lt;/p&gt;
&lt;p&gt;
Ever wakened a day wanting to iterate arrays starting from –12345? Well you can with
multidimensional arrays… The Array.CreateInstance method has an overload that takes
length and &lt;em&gt;lower bounds&lt;/em&gt; to instantiate multidimensional arrays:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
int[,] array = (int[,])Array.CreateInstance(typeof(int), 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; new int[] {10, 10}, // lengths 
&lt;br /&gt;
&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160; new int[] {–12345, – 789} // lower bounds 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; &lt;/strong&gt;); 
&lt;br /&gt;
a[&lt;strong&gt;-12345, –789&lt;/strong&gt;] = –1;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Of course, this feels a bit weird because most languages won’t allow to create such
arrays, but the Array.CreateInstance method is still available nonetheless. It feels
a bit weird but this behavior is perfectly valid from the runtime point of view. To
restrict Pex from generating such bounds, you can add the &lt;strong&gt;[PexZeroMdArrayLowerBounds(0)]&lt;/strong&gt; attribute
(one attribute per dimension).
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;What about Booleans?&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Booleans is another interesting citizen of the CLR. At the MSIL level, the Boolean
type is really a byte, widened as an integer when on the stack. Compilers try really
hard to keep Booleans as 0 or 1 but… it is possible to craft Boolean values anywhere
the byte range &lt;em&gt;using safe MSIL code &lt;/em&gt;(not from C# though or any BCL method
I know of). The implication of this are quite disturbing, for example, consider the
following parameterized test:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
[PexMethod] { 
&lt;br /&gt;
void BooleanMadness(bool a, bool b) { 
&lt;br /&gt;
&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (a &amp;amp;&amp;amp; b &amp;amp;&amp;amp; a != b) 
&lt;br /&gt;
&lt;/strong&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new Exception(“this
is madness!”); 
&lt;br /&gt;
}
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Clearly, in a word of Booleans constrained to 0 or 1, the branch that throws the exception
should be unreachable. If you execute Pex on this test, it will generate 4 test&lt;strong&gt; one
of which raises the exception:&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/TamingthePexWellbehavedenumsandbooleans_E75/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/TamingthePexWellbehavedenumsandbooleans_E75/image_thumb.png" width="399" height="115" /&gt;&lt;/a&gt;&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
Notice the actual values (0x02, 0x03) of the Booleans in the pretty printing. If you
want Pex to generate Boolean that are restricted to 0 or 1, use the &lt;strong&gt;[PexBooleanAsZeroOrOne]&lt;/strong&gt; attribute.
This attribute forces Z3 to pick boolean values as 0 or 1. Btw, there’s already a &lt;a href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=455553" target="_blank"&gt;connect
bug&lt;/a&gt; for this behavior.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=c08175a6-efc8-4452-b7dc-92346a3033de" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,c08175a6-efc8-4452-b7dc-92346a3033de.aspx</comments>
      <category>Pex</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/05/29/TamingThePexBeastWellbehavedEnumsMultidimensionalArraysAndBooleans.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=7c424777-4325-431a-9173-f306c3e29abd</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,7c424777-4325-431a-9173-f306c3e29abd.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,7c424777-4325-431a-9173-f306c3e29abd.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=7c424777-4325-431a-9173-f306c3e29abd</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
If you’ve been thinking about presenting <a href="http://research.microsoft.com/pex" target="_blank">Pex</a> to
your co-workers or your local .NET community, you can use our slide decks at <a title="http://research.microsoft.com/en-us/projects/pex/documentation.aspx" href="http://research.microsoft.com/en-us/projects/pex/documentation.aspx">http://research.microsoft.com/en-us/projects/pex/documentation.aspx</a> .
The slide decks are there to help you, don’t hesitate to shuffle them, cut them or
pick whatever you need in them (and of course, tell us about it).
</p>
        <p>
Cheers, Peli.
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=7c424777-4325-431a-9173-f306c3e29abd" />
      </body>
      <title>Presenting Pex to your co-workers? Use our slide decks…</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,7c424777-4325-431a-9173-f306c3e29abd.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/0aqSZP7FNbg/PresentingPexToYourCoworkersUseOurSlideDecks.aspx</link>
      <pubDate>Tue, 26 May 2009 05:54:47 GMT</pubDate>
      <description>&lt;p&gt;
If you’ve been thinking about presenting &lt;a href="http://research.microsoft.com/pex" target="_blank"&gt;Pex&lt;/a&gt; to
your co-workers or your local .NET community, you can use our slide decks at &lt;a title="http://research.microsoft.com/en-us/projects/pex/documentation.aspx" href="http://research.microsoft.com/en-us/projects/pex/documentation.aspx"&gt;http://research.microsoft.com/en-us/projects/pex/documentation.aspx&lt;/a&gt; .
The slide decks are there to help you, don’t hesitate to shuffle them, cut them or
pick whatever you need in them (and of course, tell us about it).
&lt;/p&gt;
&lt;p&gt;
Cheers, Peli.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=7c424777-4325-431a-9173-f306c3e29abd" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,7c424777-4325-431a-9173-f306c3e29abd.aspx</comments>
      <category>Pex</category>
      <category>Testing</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/05/26/PresentingPexToYourCoworkersUseOurSlideDecks.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=04862018-38f9-4562-8b68-7b2a067ea3a1</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,04862018-38f9-4562-8b68-7b2a067ea3a1.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,04862018-38f9-4562-8b68-7b2a067ea3a1.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=04862018-38f9-4562-8b68-7b2a067ea3a1</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
If you are (or you've been) blogging about Pex, let us know and drop the link in this
following forum thread: 
</p>
        <blockquote>
          <p>
            <a title="http://social.msdn.microsoft.com/Forums/en-US/pex/thread/7e6c26df-ccfb-48a4-878d-b3b01f5ba8d5" href="http://social.msdn.microsoft.com/Forums/en-US/pex/thread/7e6c26df-ccfb-48a4-878d-b3b01f5ba8d5">http://social.msdn.microsoft.com/Forums/en-US/pex/thread/7e6c26df-ccfb-48a4-878d-b3b01f5ba8d5</a>
          </p>
        </blockquote>
        <p>
We are building a list of links that will be hosted our project web site.
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=04862018-38f9-4562-8b68-7b2a067ea3a1" />
      </body>
      <title>Blogging about Pex, let us know!</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,04862018-38f9-4562-8b68-7b2a067ea3a1.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/dqCL0FJUXOE/BloggingAboutPexLetUsKnow.aspx</link>
      <pubDate>Wed, 20 May 2009 14:26:22 GMT</pubDate>
      <description>&lt;p&gt;
If you are (or you've been) blogging about Pex, let us know and drop the link in this
following forum thread: 
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;a title="http://social.msdn.microsoft.com/Forums/en-US/pex/thread/7e6c26df-ccfb-48a4-878d-b3b01f5ba8d5" href="http://social.msdn.microsoft.com/Forums/en-US/pex/thread/7e6c26df-ccfb-48a4-878d-b3b01f5ba8d5"&gt;http://social.msdn.microsoft.com/Forums/en-US/pex/thread/7e6c26df-ccfb-48a4-878d-b3b01f5ba8d5&lt;/a&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
We are building a list of links that will be hosted our project web site.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=04862018-38f9-4562-8b68-7b2a067ea3a1" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,04862018-38f9-4562-8b68-7b2a067ea3a1.aspx</comments>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/05/20/BloggingAboutPexLetUsKnow.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=f00fef7c-c211-4541-836c-dbe0b60ec719</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,f00fef7c-c211-4541-836c-dbe0b60ec719.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,f00fef7c-c211-4541-836c-dbe0b60ec719.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=f00fef7c-c211-4541-836c-dbe0b60ec719</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Not sure what’s going to come up at of this but you can find me on twitter at <a title="http://twitter.com/pelikhan" href="http://twitter.com/pelikhan">http://twitter.com/pelikhan</a>.
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=f00fef7c-c211-4541-836c-dbe0b60ec719" />
      </body>
      <title>find me at http://twitter.com/pelikhan</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,f00fef7c-c211-4541-836c-dbe0b60ec719.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/t3d3esxTQeo/findMeAtHttptwittercompelikhan.aspx</link>
      <pubDate>Sat, 16 May 2009 13:06:55 GMT</pubDate>
      <description>&lt;p&gt;
Not sure what’s going to come up at of this but you can find me on twitter at &lt;a title="http://twitter.com/pelikhan" href="http://twitter.com/pelikhan"&gt;http://twitter.com/pelikhan&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=f00fef7c-c211-4541-836c-dbe0b60ec719" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,f00fef7c-c211-4541-836c-dbe0b60ec719.aspx</comments>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/05/16/findMeAtHttptwittercompelikhan.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=bbda23d8-9f56-4ce8-96b1-b222841d2093</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,bbda23d8-9f56-4ce8-96b1-b222841d2093.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,bbda23d8-9f56-4ce8-96b1-b222841d2093.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=bbda23d8-9f56-4ce8-96b1-b222841d2093</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This is a cool new feature that builds on <a href="http://research.microsoft.com/stubs" target="_blank">Stubs</a>, <a href="http://research.microsoft.com/pex" target="_blank">Pex</a> 
and Code <a href="http://research.microsoft.com/contracts" target="_blank">Contracts</a> 
(in fact, it is really just a consequence of the interaction of the 3 technologies):
stubs that act as parameterized models while complying to the interface contracts.
</p>
        <ul>
          <li>
Code Contracts provide contracts for interfaces. All implementations of that particular
interface will be instrumented with the runtime checks by the rewriter <b>at compile
time</b>. 
</li>
          <li>
Stubs is really just a code generator that provides a minimal implementation of interfaces
and relies on the C# compiler to build the code. Therefore, if a stub implements an
interface with contracts, it will automatically be instrumented by the runtime rewriter
as well. 
</li>
          <li>
Pex choices (i.e. dynamic parameter generation) may be used as the fallback behavior
of stubs. In other words, whenever a stubbed method without user-defined behavior
is called, Pex gets to pick the return value. Since the stub implementation itself
may have been instrumented with contracts, we’ve added special handling code so that <b>post-condition
violation coming from a stub are considered as an assumption</b>. This effectively
forces Pex to generate values that comply with the interface contracts. 
</li>
        </ul>
        <p>
Let’s see how this works with an example. The IFoo interface contains a single ‘GetName’
method. This method has one precondition, i should be positive and one postcondition,
the result is non null. Since interfaces cannot have a method body, we use a ‘buddy’
class to express those contracts and bind both classes using the [ContractClass] and
[ContractClassFor] attributes:
</p>
        <p>
          <a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles4A3CCC8\image%5b15%5d.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsasParameterizedModeldwithCodeContra_D4E6/clip_image002_92a5f4fd-8fb6-46ca-9bc9-1f3638fa9af8.gif" width="557" height="291" />
          </a>
        </p>
        <p>
We then turn on runtime rewriting for both the project under test and the test project
(Project properties –&gt; Code Contracts –&gt; Runtime checks). As a result, the stub
of IFoo automatically gets instrumented with the contracts. We can clearly see that
from the generated code of GetName in Reflector below:
</p>
        <p>
          <a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles4A3CCC8\image%5b19%5d.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsasParameterizedModeldwithCodeContra_D4E6/clip_image004_e18deaf5-0c62-467a-9d37-14ad9817b8b6.gif" width="572" height="278" />
          </a>
        </p>
        <p>
The last step is to write a test for IFoo. In this case, we write a parameterized
unit test that takes an IFoo instance and an integer, then simply call GetName.
</p>
        <p>
          <a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles4A3CCC8\image%5b30%5d.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsasParameterizedModeldwithCodeContra_D4E6/clip_image006_2e49dd05-8b33-49fa-a84d-e1c2e2a1af1a.gif" width="337" height="150" />
          </a>
        </p>
        <p>
Since the contracts of IFoo.GetName specifies that the result should not be null,
we should not see any assertion violation in this test. Moreover, we should see a
test for the precondition considered as an expected exception:
</p>
        <p>
          <a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles4A3CCC8\image%5b29%5d.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image008" border="0" alt="clip_image008" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsasParameterizedModeldwithCodeContra_D4E6/clip_image008_5f0984a3-2fca-4b3f-a226-3e724802109d.gif" width="622" height="82" />
          </a>
        </p>
        <p>
Note that all those behaviors rely on extensions to Pex that the wizard automatically
inserted in the PexAssemblyInfo.cs file:
</p>
        <p>
          <a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles4A3CCC8\image%5b34%5d.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image010" border="0" alt="clip_image010" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsasParameterizedModeldwithCodeContra_D4E6/clip_image010_4b1ce042-a76c-490a-a4a3-90613d0f528d.gif" width="518" height="115" />
          </a>
        </p>
        <p>
where
</p>
        <ul>
          <li>
[PexAssumeContractEnsuresFailureAtStubSurface] filters post-condition violations in
stubs as assumptions, 
</li>
          <li>
[PexChooseAsStubFallbackBehavior] installs Pex choices as the fallback behavior of
stubs, 
</li>
          <li>
[PexStubsPackage] load the stubs package (this is a standard procedure for Pex packages), 
</li>
          <li>
[PexUseStubsFromTestAssembly] specifies to Pex that it should considers stub types
when trying to test interfaces or abstract classes. 
</li>
        </ul>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=bbda23d8-9f56-4ce8-96b1-b222841d2093" />
      </body>
      <title>Stubs as Parameterized Models with Contracts</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,bbda23d8-9f56-4ce8-96b1-b222841d2093.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/JfBYaGYJhlQ/StubsAsParameterizedModelsWithContracts.aspx</link>
      <pubDate>Sat, 02 May 2009 17:19:16 GMT</pubDate>
      <description>&lt;p&gt;
This is a cool new feature that builds on &lt;a href="http://research.microsoft.com/stubs" target="_blank"&gt;Stubs&lt;/a&gt;, &lt;a href="http://research.microsoft.com/pex" target="_blank"&gt;Pex&lt;/a&gt;&amp;#160;
and Code &lt;a href="http://research.microsoft.com/contracts" target="_blank"&gt;Contracts&lt;/a&gt;&amp;#160;
(in fact, it is really just a consequence of the interaction of the 3 technologies):
stubs that act as parameterized models while complying to the interface contracts.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Code Contracts provide contracts for interfaces. All implementations of that particular
interface will be instrumented with the runtime checks by the rewriter &lt;b&gt;at compile
time&lt;/b&gt;. 
&lt;/li&gt;
&lt;li&gt;
Stubs is really just a code generator that provides a minimal implementation of interfaces
and relies on the C# compiler to build the code. Therefore, if a stub implements an
interface with contracts, it will automatically be instrumented by the runtime rewriter
as well. 
&lt;/li&gt;
&lt;li&gt;
Pex choices (i.e. dynamic parameter generation) may be used as the fallback behavior
of stubs. In other words, whenever a stubbed method without user-defined behavior
is called, Pex gets to pick the return value. Since the stub implementation itself
may have been instrumented with contracts, we’ve added special handling code so that &lt;b&gt;post-condition
violation coming from a stub are considered as an assumption&lt;/b&gt;. This effectively
forces Pex to generate values that comply with the interface contracts. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Let’s see how this works with an example. The IFoo interface contains a single ‘GetName’
method. This method has one precondition, i should be positive and one postcondition,
the result is non null. Since interfaces cannot have a method body, we use a ‘buddy’
class to express those contracts and bind both classes using the [ContractClass] and
[ContractClassFor] attributes:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles4A3CCC8\image%5b15%5d.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsasParameterizedModeldwithCodeContra_D4E6/clip_image002_92a5f4fd-8fb6-46ca-9bc9-1f3638fa9af8.gif" width="557" height="291" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
We then turn on runtime rewriting for both the project under test and the test project
(Project properties –&amp;gt; Code Contracts –&amp;gt; Runtime checks). As a result, the stub
of IFoo automatically gets instrumented with the contracts. We can clearly see that
from the generated code of GetName in Reflector below:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles4A3CCC8\image%5b19%5d.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsasParameterizedModeldwithCodeContra_D4E6/clip_image004_e18deaf5-0c62-467a-9d37-14ad9817b8b6.gif" width="572" height="278" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
The last step is to write a test for IFoo. In this case, we write a parameterized
unit test that takes an IFoo instance and an integer, then simply call GetName.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles4A3CCC8\image%5b30%5d.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsasParameterizedModeldwithCodeContra_D4E6/clip_image006_2e49dd05-8b33-49fa-a84d-e1c2e2a1af1a.gif" width="337" height="150" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Since the contracts of IFoo.GetName specifies that the result should not be null,
we should not see any assertion violation in this test. Moreover, we should see a
test for the precondition considered as an expected exception:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles4A3CCC8\image%5b29%5d.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image008" border="0" alt="clip_image008" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsasParameterizedModeldwithCodeContra_D4E6/clip_image008_5f0984a3-2fca-4b3f-a226-3e724802109d.gif" width="622" height="82" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Note that all those behaviors rely on extensions to Pex that the wizard automatically
inserted in the PexAssemblyInfo.cs file:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles4A3CCC8\image%5b34%5d.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image010" border="0" alt="clip_image010" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsasParameterizedModeldwithCodeContra_D4E6/clip_image010_4b1ce042-a76c-490a-a4a3-90613d0f528d.gif" width="518" height="115" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
where
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
[PexAssumeContractEnsuresFailureAtStubSurface] filters post-condition violations in
stubs as assumptions, 
&lt;/li&gt;
&lt;li&gt;
[PexChooseAsStubFallbackBehavior] installs Pex choices as the fallback behavior of
stubs, 
&lt;/li&gt;
&lt;li&gt;
[PexStubsPackage] load the stubs package (this is a standard procedure for Pex packages), 
&lt;/li&gt;
&lt;li&gt;
[PexUseStubsFromTestAssembly] specifies to Pex that it should considers stub types
when trying to test interfaces or abstract classes. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=bbda23d8-9f56-4ce8-96b1-b222841d2093" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,bbda23d8-9f56-4ce8-96b1-b222841d2093.aspx</comments>
      <category>Code Contracts</category>
      <category>Pex</category>
      <category>Stubs</category>
      <category>Testing</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/05/02/StubsAsParameterizedModelsWithContracts.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=18226b58-0d8f-484e-a07d-12f3ebae8c1e</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,18226b58-0d8f-484e-a07d-12f3ebae8c1e.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,18226b58-0d8f-484e-a07d-12f3ebae8c1e.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=18226b58-0d8f-484e-a07d-12f3ebae8c1e</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We just made a <a href="http://research.microsoft.com/pex/downloads.aspx">quick release</a> to
fix another installer issue related to missing packages. Along the way, we’ve added
an <strong>Exploration Tree View</strong> and <strong>Partial Stubs</strong> support.
</p>
        <p>
          <strong>Exploration Tree View</strong>
        </p>
        <p>
The exploration tree view displays the list of explorations to be executed, running
and finished. It serves as a progress indicator but also as a smooth result explorer.
When browsing through the tree, <a href="http://research.microsoft.com/pex" target="_blank">Pex</a> will
synchronize the exploration result view and the tree view.
</p>
        <p>
The tree view populates each namespace with the fixture types and exploration methods,
and provide a visual feedback on the progress of Pex.
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_4.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_thumb_1.png" width="390" height="363" />
          </a>
        </p>
        <p>
When you browse through the exploration and generated test nodes, Pex automatically
synchronizes the exploration result display. This makes it really easy to start from
an high-level view of the failures and drill into a particular generated test, with
stack trace and parameter table.
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_2.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_thumb.png" width="604" height="212" />
          </a>
        </p>
        <p>
          <strong>
          </strong>
        </p>
        <p>
          <strong>Partial Stubs</strong>
        </p>
        <p>
Stubs lets you call the base class implementation of methods as a fallback behavior.
This functionality is commonly referred as <a href="http://ayende.com/Wiki/Default.aspx?Page=Rhino+Mocks+Partial+Mocks">Partial
Mocks</a> or Partial Stubs and is useful to test abstract classes in isolation. Stubs
inheriting from classes have a “CallBase” property that can turn this mode on and
off.
</p>
        <p>
Let see this with the <a href="http://ayende.com/Wiki/Default.aspx?Page=Rhino+Mocks+Partial+Mocks">RhinoMocks
example on partial mocks</a>. Given an abstract ProcessorBase class,
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_10.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_thumb_4.png" width="337" height="207" />
          </a>
        </p>
        <p>
we write a test for the Inc method. To do so, we provide a stub implementation of
Add that simply increment a counter.
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_8.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_thumb_3.png" width="558" height="210" />
          </a>
        </p>
        <p>
          <strong>Miscellaneous</strong>
        </p>
        <ul>
          <li>
PexAssume/PexAssert.EnumIsDefine checks that a particular value is defined in an enum. 
</li>
          <li>
Missing OpenMP files in the installer break Pex.</li>
        </ul>
        <p>
          <strong>
          </strong>
        </p>
        <p>
          <strong>Poll:</strong> should we skip 0.13 and go straight for 0.14? :)
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=18226b58-0d8f-484e-a07d-12f3ebae8c1e" />
      </body>
      <title>Pex 0.12.40430.3 : Exploration Tree View, Partial Stubs…</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,18226b58-0d8f-484e-a07d-12f3ebae8c1e.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/GA6q4V-3cCE/Pex012404303ExplorationTreeViewPartialStubs.aspx</link>
      <pubDate>Fri, 01 May 2009 20:28:25 GMT</pubDate>
      <description>&lt;p&gt;
We just made a &lt;a href="http://research.microsoft.com/pex/downloads.aspx"&gt;quick release&lt;/a&gt; to
fix another installer issue related to missing packages. Along the way, we’ve added
an &lt;strong&gt;Exploration Tree View&lt;/strong&gt; and &lt;strong&gt;Partial Stubs&lt;/strong&gt; support.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Exploration Tree View&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
The exploration tree view displays the list of explorations to be executed, running
and finished. It serves as a progress indicator but also as a smooth result explorer.
When browsing through the tree, &lt;a href="http://research.microsoft.com/pex" target="_blank"&gt;Pex&lt;/a&gt; will
synchronize the exploration result view and the tree view.
&lt;/p&gt;
&lt;p&gt;
The tree view populates each namespace with the fixture types and exploration methods,
and provide a visual feedback on the progress of Pex.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_thumb_1.png" width="390" height="363" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
When you browse through the exploration and generated test nodes, Pex automatically
synchronizes the exploration result display. This makes it really easy to start from
an high-level view of the failures and drill into a particular generated test, with
stack trace and parameter table.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_thumb.png" width="604" height="212" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Partial Stubs&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Stubs lets you call the base class implementation of methods as a fallback behavior.
This functionality is commonly referred as &lt;a href="http://ayende.com/Wiki/Default.aspx?Page=Rhino+Mocks+Partial+Mocks"&gt;Partial
Mocks&lt;/a&gt; or Partial Stubs and is useful to test abstract classes in isolation. Stubs
inheriting from classes have a “CallBase” property that can turn this mode on and
off.
&lt;/p&gt;
&lt;p&gt;
Let see this with the &lt;a href="http://ayende.com/Wiki/Default.aspx?Page=Rhino+Mocks+Partial+Mocks"&gt;RhinoMocks
example on partial mocks&lt;/a&gt;. Given an abstract ProcessorBase class,
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_10.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_thumb_4.png" width="337" height="207" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
we write a test for the Inc method. To do so, we provide a stub implementation of
Add that simply increment a counter.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_thumb_3.png" width="558" height="210" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Miscellaneous&lt;/strong&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
PexAssume/PexAssert.EnumIsDefine checks that a particular value is defined in an enum. 
&lt;/li&gt;
&lt;li&gt;
Missing OpenMP files in the installer break Pex.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;strong&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Poll:&lt;/strong&gt; should we skip 0.13 and go straight for 0.14? :)
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=18226b58-0d8f-484e-a07d-12f3ebae8c1e" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,18226b58-0d8f-484e-a07d-12f3ebae8c1e.aspx</comments>
      <category>Pex</category>
      <category>RiSE</category>
      <category>Stubs</category>
      <category>Testing</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/05/01/Pex012404303ExplorationTreeViewPartialStubs.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=9997ca8f-c91a-4581-839f-459e8dc06dc0</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,9997ca8f-c91a-4581-839f-459e8dc06dc0.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,9997ca8f-c91a-4581-839f-459e8dc06dc0.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=9997ca8f-c91a-4581-839f-459e8dc06dc0</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I recorded a <a href="http://channel9.msdn.com/posts/Peli/The-Synergy-of-Code-Contracts-and-Pex/" target="_blank">Channel9
video</a> last week with <a href="http://research.microsoft.com/~maf" target="_blank">Manuel
Fahndrich</a> on the interaction of Code <a href="http://research.microsoft.com/contracts" target="_blank">Contracts</a> and <a href="http://research.microsoft.com/pex" target="_blank">Pex</a>.
The demo gives a glimpse at the nice interaction between Contracts (design by contracts)
and Pex (automated white box).
</p>
        <p>
Code Contracts gives you a great way to specify what your code is supposed to do.
These contracts can be leverage for documentation, static checkers but also – tada
– by Pex! Contracts can also be turned into runtime checks which Pex will try to explore.
Pex will try to cover the post conditions, assertions or in other words, find inputs
that violates of your contracts etc… By adding contracts to your code, you give Pex
a ‘direction’ to search for (and a test oracle).
</p>
        <p>
          <a href="http://channel9.msdn.com/posts/Peli/The-Synergy-of-Code-Contracts-and-Pex/">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/DesignByContractsmeetsAutomatedWhiteboxT_1261F/image_3.png" width="328" height="247" />
          </a> 
</p>
        <p>
Drop me a note if you want more of those movies.
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=9997ca8f-c91a-4581-839f-459e8dc06dc0" />
      </body>
      <title>Design By Contracts meets Automated White box Testing</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,9997ca8f-c91a-4581-839f-459e8dc06dc0.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/aclBLBqfxKg/DesignByContractsMeetsAutomatedWhiteBoxTesting.aspx</link>
      <pubDate>Sun, 26 Apr 2009 04:09:57 GMT</pubDate>
      <description>&lt;p&gt;
I recorded a &lt;a href="http://channel9.msdn.com/posts/Peli/The-Synergy-of-Code-Contracts-and-Pex/" target="_blank"&gt;Channel9
video&lt;/a&gt; last week with &lt;a href="http://research.microsoft.com/~maf" target="_blank"&gt;Manuel
Fahndrich&lt;/a&gt; on the interaction of Code &lt;a href="http://research.microsoft.com/contracts" target="_blank"&gt;Contracts&lt;/a&gt; and &lt;a href="http://research.microsoft.com/pex" target="_blank"&gt;Pex&lt;/a&gt;.
The demo gives a glimpse at the nice interaction between Contracts (design by contracts)
and Pex (automated white box).
&lt;/p&gt;
&lt;p&gt;
Code Contracts gives you a great way to specify what your code is supposed to do.
These contracts can be leverage for documentation, static checkers but also – tada
– by Pex! Contracts can also be turned into runtime checks which Pex will try to explore.
Pex will try to cover the post conditions, assertions or in other words, find inputs
that violates of your contracts etc… By adding contracts to your code, you give Pex
a ‘direction’ to search for (and a test oracle).
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://channel9.msdn.com/posts/Peli/The-Synergy-of-Code-Contracts-and-Pex/"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/DesignByContractsmeetsAutomatedWhiteboxT_1261F/image_3.png" width="328" height="247" /&gt;&lt;/a&gt;&amp;#160;
&lt;/p&gt;
&lt;p&gt;
Drop me a note if you want more of those movies.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=9997ca8f-c91a-4581-839f-459e8dc06dc0" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,9997ca8f-c91a-4581-839f-459e8dc06dc0.aspx</comments>
      <category>Code Contracts</category>
      <category>Pex</category>
      <category>Testing</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/04/26/DesignByContractsMeetsAutomatedWhiteBoxTesting.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=7c5d5cdd-7ebc-4a3d-8fb1-e84b187343b2</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,7c5d5cdd-7ebc-4a3d-8fb1-e84b187343b2.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,7c5d5cdd-7ebc-4a3d-8fb1-e84b187343b2.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=7c5d5cdd-7ebc-4a3d-8fb1-e84b187343b2</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <em>Update: Andrew Kazyrevich does the final performance analysis <a href="http://codevanced.net/post/The-Shark-Fin-Pex.aspx">on
his blog</a>. 
<br />
Update II: Stubs v0.12.40430.3 has Partial Stubs support. </em>
        </p>
        <p>
          <a href="http://research.microsoft.com/stubs" target="_blank">Stubs</a> is a lightweight
stub framework that is entirely based on delegates. We designed it so that it brings
as little overhead as possible, and as a side effect, is very effective with <a href="http://research.microsoft.com/pex" target="_blank">Pex</a>.
In this post, we’ll see how Stubs ‘look’ with respect to other frameworks.
</p>
        <p>
          <strong>Mocking-framework-compare</strong>
        </p>
        <p>
          <a href="http://codevanced.net/" target="_blank">Andrew Kazyrevich</a> started a project, <a href="http://code.google.com/p/mocking-frameworks-compare/" target="_blank">mocking-framework-compare</a>,
back in February that compared Moq, Rhino, NMock2 and Isolator. This is project compares
various ‘mocking scenarios’ across all those frameworks. I added Stubs to the mix
today (go <a href="http://code.google.com/p/mocking-frameworks-compare/source/detail?r=56" target="_blank">check
it out</a>).
</p>
        <p>
          <strong>What’s a stub in Stubs anyway?</strong>
        </p>
        <p>
Before we dig in, let’s recap how stubs look like when you use Stubs. Stubs uses delegate
to ‘hook’ behavior to interface members.<strong />For every stubbed interface
and class, code is generated at a compile time: One stub class per interface and class.
For each stubbed method, the stub class contains a field. The field has a delegate
type matching the stubbed method. As a user, you can simply attach delegates (or lambdas)
to the delegate fields to assign<strong>*any*</strong> behavior to each member. If
no user delegate is set, Stubs calls into a fallback behavior, i.e. throw or return
the default value. 
</p>
        <p>
Let’s take one of the examples of mocking-framework-compare. The little snippet below
‘stubs’ the TouchIron() method (which is implemented explicitly) by attaching a lambda
to the TouchIron field.
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_2.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_thumb.png" width="324" height="133" />
          </a>
        </p>
        <p>
SIHand is the stub type of the IHand interface, it was generated at compile time by
the Stubs framework. Its implementation looks more or less like this:
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_4.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_thumb_1.png" width="504" height="289" />
          </a>
        </p>
        <p>
The TouchIron methods really shows the main idea behind stubs: delegates are all we
need to move behavior around.
</p>
        <p>
          <strong>Stubs: relying on the language rather than an API</strong>
        </p>
        <p>
One of the differences of Stubs with other mock frameworks is that Stubs does not
have any API: delegates, lambdas, closures are all features of the programming language,
while assertions are part of the test framework. This is quite obvious when we compare
the BrainTest <a href="http://code.google.com/p/mocking-frameworks-compare/source/browse/trunk/Tests/CS/MoqTests/BrainTests.cs" target="_blank">using
Moq</a> and <a href="http://code.google.com/p/mocking-frameworks-compare/source/browse/trunk/Tests/CS/StubsTests/BrainTests.cs" target="_blank">using
Stubs</a>. In this test, we need to ensure that the brain coordinates the hand and
the mouth so that when a hot iron is touched by the hand, the mouth yells.
</p>
        <ul>
          <li>
Moq: we set up the hand to throw a burn exception when touched with a hot iron and
verify that the mouth yelled. 
</li>
        </ul>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_6.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_thumb_2.png" width="612" height="172" />
          </a>
        </p>
        <p>
Moq, as Rhino or Isolate, make smart use of expression trees and/or Reflection.Emit
to define the mock behavior. The expectation and behavior are set through nice and
fluent APIs which really make the developer’s life’s easier.
</p>
        <ul>
          <li>
Stubs: same scenario, we attach a lambda that throws if iron is hot and use a local
to verify that Yell is called (this local is pushed to the heap by the compiler). 
</li>
        </ul>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_8.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_thumb_3.png" width="402" height="316" />
          </a> 
</p>
        <p>
Stubs does not have any API. It relies on lambdas (to define new behaviors), closures
(to track side effects) which are given for free by the C# 3.0 language.
</p>
        <p>
          <strong>Performance numbers</strong>
        </p>
        <p>
Does performance matter when it comes to mocking? It’s not really the question we
are trying to answer here. We’re just looking at the benchmark results from the mocking-framework-compare
project. When looking at the results, you’ll notice that Stubs may be 100x to 1000x
faster than other frameworks. This is no surprise since stubs boil down to a virtual
method call, while other frameworks do much more work (in fact we expected worse numbers).
</p>
        <blockquote>
          <p>
Data units of msec resolution = 0.394937 usec 
</p>
          <p>
Mocking methods. 
<br />
Moq      : 100 repeats:  37.471 +- 12%   msec 
<br />
Rhino    : 100 repeats:  38.030 +- 7%    msec 
<br />
NMock2   : 100 repeats:  24.035 +- 4%    msec 
<br /><strong>Stubs    : 100 repeats:   0.115 +- 8%   
msec </strong></p>
          <p>
Mocking events. 
<br />
Moq      : 100 repeats:  86.913 +- 7%   
msec 
<br />
Rhino    : 100 repeats:  61.142 +- 6%    msec 
<br />
NMock2   : 100 repeats:  27.378 +- 6%    msec 
<br /><strong>Stubs    : 100 repeats:   0.071 +- 6%   
msec </strong></p>
          <p>
Mocking properties. 
<br />
Moq      : 100 repeats:  82.434 +- 6%   
msec 
<br />
Rhino    : 100 repeats:  47.471 +- 5%    msec 
<br />
NMock2   : 100 repeats:  11.334 +- 10%   msec 
<br /><strong>Stubs    : 100 repeats:   0.042 +- 15%  
msec </strong></p>
          <p>
Mocking method arguments. 
<br />
Moq      : 100 repeats: 142.668 +- 4%    msec 
<br />
Rhino    : 100 repeats:  45.118 +- 5%    msec 
<br />
NMock2   : 100 repeats:  22.344 +- 7%    msec 
<br /><strong>Stubs    : 100 repeats:   0.078 +- 4%   
msec </strong></p>
          <p>
Partial mocks. 
<br />
Moq      : 100 repeats: 117.581 +- 5%    msec 
<br />
Rhino    : 100 repeats:  58.827 +- 6%    msec 
<br /><strong>Stubs : 100 repeats:   0.054 +- 6%    msec </strong></p>
          <p>
Recursive mocks. 
<br />
Moq      : 100 repeats:  92.482 +- 4%   
msec 
<br />
Rhino    : 100 repeats:  40.921 +- 3%    msec 
<br /><strong>Stubs    : 100 repeats:   0.493 +- 18%  
msec 
<br /></strong>Press any key to continue . . .
</p>
          <p>
          </p>
          <p>
          </p>
        </blockquote>
        <strong>
        </strong>
        <p>
          <strong>Stubs limitations</strong>
        </p>
        <p>
There are many areas where the Stubs fall short or simply don’t support it. Currently,
Stubs are only emitted for C# and <a href="http://ayende.com/Wiki/Default.aspx?Page=Rhino+Mocks+Partial+Mocks" target="_blank">partial
mocks</a> will be supported in the next version.
</p>
        <p>
          <strong>Getting started with Stubs</strong>
        </p>
        <p>
Stubs comes with the <a href="http://research.microsoft.com/pex/downloads.aspx" target="_blank">Pex
installer</a>. If you’re interested on using it, check out the <a href="http://research.microsoft.com/en-us/projects/stubs/gettingstarted.aspx" target="_blank">getting
started page</a> on the Stubs project page where you can also download the full Stubs
primer.
</p>
        <p>
Cheers, Peli
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=7c5d5cdd-7ebc-4a3d-8fb1-e84b187343b2" />
      </body>
      <title>Stubs: Comparison with other mocking frameworks</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,7c5d5cdd-7ebc-4a3d-8fb1-e84b187343b2.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/d_bI1dic4_o/StubsComparisonWithOtherMockingFrameworks.aspx</link>
      <pubDate>Thu, 23 Apr 2009 04:58:03 GMT</pubDate>
      <description>&lt;p&gt;
&lt;em&gt;Update: Andrew Kazyrevich does the final performance analysis &lt;a href="http://codevanced.net/post/The-Shark-Fin-Pex.aspx"&gt;on
his blog&lt;/a&gt;. 
&lt;br /&gt;
Update II: Stubs v0.12.40430.3 has Partial Stubs support. &lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://research.microsoft.com/stubs" target="_blank"&gt;Stubs&lt;/a&gt; is a lightweight
stub framework that is entirely based on delegates. We designed it so that it brings
as little overhead as possible, and as a side effect, is very effective with &lt;a href="http://research.microsoft.com/pex" target="_blank"&gt;Pex&lt;/a&gt;.
In this post, we’ll see how Stubs ‘look’ with respect to other frameworks.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Mocking-framework-compare&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://codevanced.net/" target="_blank"&gt;Andrew Kazyrevich&lt;/a&gt; started a project, &lt;a href="http://code.google.com/p/mocking-frameworks-compare/" target="_blank"&gt;mocking-framework-compare&lt;/a&gt;,
back in February that compared Moq, Rhino, NMock2 and Isolator. This is project compares
various ‘mocking scenarios’ across all those frameworks. I added Stubs to the mix
today (go &lt;a href="http://code.google.com/p/mocking-frameworks-compare/source/detail?r=56" target="_blank"&gt;check
it out&lt;/a&gt;).
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;What’s a stub in Stubs anyway?&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Before we dig in, let’s recap how stubs look like when you use Stubs. Stubs uses delegate
to ‘hook’ behavior to interface members.&lt;strong&gt; &lt;/strong&gt;For every stubbed interface
and class, code is generated at a compile time: One stub class per interface and class.
For each stubbed method, the stub class contains a field. The field has a delegate
type matching the stubbed method. As a user, you can simply attach delegates (or lambdas)
to the delegate fields to assign&lt;strong&gt;*any*&lt;/strong&gt; behavior to each member. If
no user delegate is set, Stubs calls into a fallback behavior, i.e. throw or return
the default value. 
&lt;/p&gt;
&lt;p&gt;
Let’s take one of the examples of mocking-framework-compare. The little snippet below
‘stubs’ the TouchIron() method (which is implemented explicitly) by attaching a lambda
to the TouchIron field.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_thumb.png" width="324" height="133" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
SIHand is the stub type of the IHand interface, it was generated at compile time by
the Stubs framework. Its implementation looks more or less like this:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_thumb_1.png" width="504" height="289" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
The TouchIron methods really shows the main idea behind stubs: delegates are all we
need to move behavior around.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Stubs: relying on the language rather than an API&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
One of the differences of Stubs with other mock frameworks is that Stubs does not
have any API: delegates, lambdas, closures are all features of the programming language,
while assertions are part of the test framework. This is quite obvious when we compare
the BrainTest &lt;a href="http://code.google.com/p/mocking-frameworks-compare/source/browse/trunk/Tests/CS/MoqTests/BrainTests.cs" target="_blank"&gt;using
Moq&lt;/a&gt; and &lt;a href="http://code.google.com/p/mocking-frameworks-compare/source/browse/trunk/Tests/CS/StubsTests/BrainTests.cs" target="_blank"&gt;using
Stubs&lt;/a&gt;. In this test, we need to ensure that the brain coordinates the hand and
the mouth so that when a hot iron is touched by the hand, the mouth yells.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Moq: we set up the hand to throw a burn exception when touched with a hot iron and
verify that the mouth yelled. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_thumb_2.png" width="612" height="172" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Moq, as Rhino or Isolate, make smart use of expression trees and/or Reflection.Emit
to define the mock behavior. The expectation and behavior are set through nice and
fluent APIs which really make the developer’s life’s easier.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Stubs: same scenario, we attach a lambda that throws if iron is hot and use a local
to verify that Yell is called (this local is pushed to the heap by the compiler). 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_thumb_3.png" width="402" height="316" /&gt;&lt;/a&gt;&amp;#160;
&lt;/p&gt;
&lt;p&gt;
Stubs does not have any API. It relies on lambdas (to define new behaviors), closures
(to track side effects) which are given for free by the C# 3.0 language.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Performance numbers&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Does performance matter when it comes to mocking? It’s not really the question we
are trying to answer here. We’re just looking at the benchmark results from the mocking-framework-compare
project. When looking at the results, you’ll notice that Stubs may be 100x to 1000x
faster than other frameworks. This is no surprise since stubs boil down to a virtual
method call, while other frameworks do much more work (in fact we expected worse numbers).
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
Data units of msec resolution = 0.394937 usec 
&lt;/p&gt;
&lt;p&gt;
Mocking methods. 
&lt;br /&gt;
Moq&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 37.471 +- 12%&amp;#160;&amp;#160; msec 
&lt;br /&gt;
Rhino&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 38.030 +- 7%&amp;#160;&amp;#160;&amp;#160; msec 
&lt;br /&gt;
NMock2&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 24.035 +- 4%&amp;#160;&amp;#160;&amp;#160; msec 
&lt;br /&gt;
&lt;strong&gt;Stubs&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160;&amp;#160; 0.115 +- 8%&amp;#160;&amp;#160;&amp;#160;
msec &lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Mocking events. 
&lt;br /&gt;
Moq&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 86.913 +- 7%&amp;#160;&amp;#160;&amp;#160;
msec 
&lt;br /&gt;
Rhino&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 61.142 +- 6%&amp;#160;&amp;#160;&amp;#160; msec 
&lt;br /&gt;
NMock2&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 27.378 +- 6%&amp;#160;&amp;#160;&amp;#160; msec 
&lt;br /&gt;
&lt;strong&gt;Stubs&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160;&amp;#160; 0.071 +- 6%&amp;#160;&amp;#160;&amp;#160;
msec &lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Mocking properties. 
&lt;br /&gt;
Moq&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 82.434 +- 6%&amp;#160;&amp;#160;&amp;#160;
msec 
&lt;br /&gt;
Rhino&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 47.471 +- 5%&amp;#160;&amp;#160;&amp;#160; msec 
&lt;br /&gt;
NMock2&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 11.334 +- 10%&amp;#160;&amp;#160; msec 
&lt;br /&gt;
&lt;strong&gt;Stubs&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160;&amp;#160; 0.042 +- 15%&amp;#160;&amp;#160;
msec &lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Mocking method arguments. 
&lt;br /&gt;
Moq&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : 100 repeats: 142.668 +- 4%&amp;#160;&amp;#160;&amp;#160; msec 
&lt;br /&gt;
Rhino&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 45.118 +- 5%&amp;#160;&amp;#160;&amp;#160; msec 
&lt;br /&gt;
NMock2&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 22.344 +- 7%&amp;#160;&amp;#160;&amp;#160; msec 
&lt;br /&gt;
&lt;strong&gt;Stubs&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160;&amp;#160; 0.078 +- 4%&amp;#160;&amp;#160;&amp;#160;
msec &lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Partial mocks. 
&lt;br /&gt;
Moq&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : 100 repeats: 117.581 +- 5%&amp;#160;&amp;#160;&amp;#160; msec 
&lt;br /&gt;
Rhino&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 58.827 +- 6%&amp;#160;&amp;#160;&amp;#160; msec 
&lt;br /&gt;
&lt;strong&gt;Stubs : 100 repeats:&amp;#160;&amp;#160; 0.054 +- 6%&amp;#160;&amp;#160;&amp;#160; msec &lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Recursive mocks. 
&lt;br /&gt;
Moq&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 92.482 +- 4%&amp;#160;&amp;#160;&amp;#160;
msec 
&lt;br /&gt;
Rhino&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 40.921 +- 3%&amp;#160;&amp;#160;&amp;#160; msec 
&lt;br /&gt;
&lt;strong&gt;Stubs&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160;&amp;#160; 0.493 +- 18%&amp;#160;&amp;#160;
msec 
&lt;br /&gt;
&lt;/strong&gt;Press any key to continue . . .
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;/blockquote&gt; &lt;strong&gt;&lt;/strong&gt; 
&lt;p&gt;
&lt;strong&gt;Stubs limitations&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
There are many areas where the Stubs fall short or simply don’t support it. Currently,
Stubs are only emitted for C# and &lt;a href="http://ayende.com/Wiki/Default.aspx?Page=Rhino+Mocks+Partial+Mocks" target="_blank"&gt;partial
mocks&lt;/a&gt; will be supported in the next version.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Getting started with Stubs&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Stubs comes with the &lt;a href="http://research.microsoft.com/pex/downloads.aspx" target="_blank"&gt;Pex
installer&lt;/a&gt;. If you’re interested on using it, check out the &lt;a href="http://research.microsoft.com/en-us/projects/stubs/gettingstarted.aspx" target="_blank"&gt;getting
started page&lt;/a&gt; on the Stubs project page where you can also download the full Stubs
primer.
&lt;/p&gt;
&lt;p&gt;
Cheers, Peli
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=7c5d5cdd-7ebc-4a3d-8fb1-e84b187343b2" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,7c5d5cdd-7ebc-4a3d-8fb1-e84b187343b2.aspx</comments>
      <category>Pex</category>
      <category>Stubs</category>
      <category>Testing</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/04/23/StubsComparisonWithOtherMockingFrameworks.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=3f0e2745-a604-4772-a81d-bf7d75faa21a</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,3f0e2745-a604-4772-a81d-bf7d75faa21a.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,3f0e2745-a604-4772-a81d-bf7d75faa21a.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=3f0e2745-a604-4772-a81d-bf7d75faa21a</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">Nikolai just announced the latest drop
of <a href="http://research.microsoft.com/pex" target="_blank">Pex</a>, 0.11.40421.0.
Get <a href="http://blogs.msdn.com/nikolait/archive/2009/04/21/pex-0-11-released-delegates-exception-trees-and-stubs.aspx" target="_blank">all
the details</a> on his blog.<img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=3f0e2745-a604-4772-a81d-bf7d75faa21a" /></body>
      <title>Pex v0.11.40421.0 : Delegates As Parameters, Exception Tree View, Better Stubs.</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,3f0e2745-a604-4772-a81d-bf7d75faa21a.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/tP9BghEJe_4/PexV011404210DelegatesAsParametersExceptionTreeViewBetterStubs.aspx</link>
      <pubDate>Wed, 22 Apr 2009 00:10:17 GMT</pubDate>
      <description>Nikolai just announced the latest drop of &lt;a href="http://research.microsoft.com/pex" target="_blank"&gt;Pex&lt;/a&gt;,
0.11.40421.0. Get &lt;a href="http://blogs.msdn.com/nikolait/archive/2009/04/21/pex-0-11-released-delegates-exception-trees-and-stubs.aspx" target="_blank"&gt;all
the details&lt;/a&gt; on his blog.&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=3f0e2745-a604-4772-a81d-bf7d75faa21a" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,3f0e2745-a604-4772-a81d-bf7d75faa21a.aspx</comments>
      <category>Pex</category>
      <category>RiSE</category>
      <category>Stubs</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/04/22/PexV011404210DelegatesAsParametersExceptionTreeViewBetterStubs.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=613f853f-19ed-4482-af6f-685ed1876096</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,613f853f-19ed-4482-af6f-685ed1876096.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,613f853f-19ed-4482-af6f-685ed1876096.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=613f853f-19ed-4482-af6f-685ed1876096</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
For the last couple of weeks, I given on helping hand to Herman Venter to set up the
open-source-MS-PL-super-cool-Common Compiler Infrastructure (<a href="http://ccimetadata.codeplex.com/" target="_blank">CCI</a>)
project. 
</p>
        <p>
You’ve may have heard and probably used different incarnations of the CCI in the past:
the FxCop introspection engine, <a href="http://research.microsoft.com/en-us/people/mbarnett/ilmerge.aspx" target="_blank">ILMerge</a>, <a href="http://research.microsoft.com/en-us/projects/specsharp/" target="_blank">Spec#</a> or
Code <a href="http://research.microsoft.com/contracts" target="_blank">Contracts</a> use
CCI in same ways. CCI is a set of tools and components that are useful to build compilers:
readers and writers for MSIL and symbol files, and more. With CCI, you can now <em>easily</em> write
your own crazy aspect oriented programming framework, inspect assemblies without reflection
etc…  Just sync the sources, build it, tweak it, etc… It’s all there on <a href="http://ccimetadata.codeplex.com/" target="_blank">codeplex</a> at <a href="http://ccimetadata.codeplex.com">http://ccimetadata.codeplex.com</a>.
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=613f853f-19ed-4482-af6f-685ed1876096" />
      </body>
      <title>Read, morph, tweak, write MSIL with CCI (open source)</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,613f853f-19ed-4482-af6f-685ed1876096.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/rajOheTwCIY/ReadMorphTweakWriteMSILWithCCIOpenSource.aspx</link>
      <pubDate>Thu, 16 Apr 2009 03:51:23 GMT</pubDate>
      <description>&lt;p&gt;
For the last couple of weeks, I given on helping hand to Herman Venter to set up the
open-source-MS-PL-super-cool-Common Compiler Infrastructure (&lt;a href="http://ccimetadata.codeplex.com/" target="_blank"&gt;CCI&lt;/a&gt;)
project. 
&lt;/p&gt;
&lt;p&gt;
You’ve may have heard and probably used different incarnations of the CCI in the past:
the FxCop introspection engine, &lt;a href="http://research.microsoft.com/en-us/people/mbarnett/ilmerge.aspx" target="_blank"&gt;ILMerge&lt;/a&gt;, &lt;a href="http://research.microsoft.com/en-us/projects/specsharp/" target="_blank"&gt;Spec#&lt;/a&gt; or
Code &lt;a href="http://research.microsoft.com/contracts" target="_blank"&gt;Contracts&lt;/a&gt; use
CCI in same ways. CCI is a set of tools and components that are useful to build compilers:
readers and writers for MSIL and symbol files, and more. With CCI, you can now &lt;em&gt;easily&lt;/em&gt; write
your own crazy aspect oriented programming framework, inspect assemblies without reflection
etc…&amp;#160; Just sync the sources, build it, tweak it, etc… It’s all there on &lt;a href="http://ccimetadata.codeplex.com/" target="_blank"&gt;codeplex&lt;/a&gt; at &lt;a href="http://ccimetadata.codeplex.com"&gt;http://ccimetadata.codeplex.com&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=613f853f-19ed-4482-af6f-685ed1876096" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,613f853f-19ed-4482-af6f-685ed1876096.aspx</comments>
      <category>CCI</category>
      <category>Code Contracts</category>
      <category>RiSE</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/04/16/ReadMorphTweakWriteMSILWithCCIOpenSource.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=83fde01f-786e-456d-b1c4-c8dd52448e69</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,83fde01f-786e-456d-b1c4-c8dd52448e69.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,83fde01f-786e-456d-b1c4-c8dd52448e69.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=83fde01f-786e-456d-b1c4-c8dd52448e69</wfw:commentRss>
      <slash:comments>12</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <blockquote>
          <p>
            <a href="http://research.microsoft.com/en-us/projects/pex/downloads.aspx" target="_blank">
              <strong>Download
the new version!</strong>
            </a>
          </p>
        </blockquote>
        <p>
Today we’ve released a new release of <a href="http://research.microsoft.com/pex">Pex</a> on
DevLabs and on our academic downloads. This highlights of this release are: <a href="http://www.nunit.org" target="_blank">NUnit</a>, <a href="http://www.mbunit.com/" target="_blank">MbUnit</a> and <a href="http://xunit.codeplex.com/" target="_blank">xUnit.net</a> support
out of the box, <strong>writing <a href="http://research.microsoft.com/pex">parameterized
unit tests</a> in VisualBasic.NET and F#, better <a href="http://research.microsoft.com/contracts">Code
Contracts</a> support</strong>. As always, if we encourage you to send us feedback,
bugs, stories on our forums at <a href="http://social.msdn.microsoft.com/Forums/en-US/pex/threads/">http://social.msdn.microsoft.com/Forums/en-US/pex/threads/</a> .
</p>
        <p>
          <strong>
            <a href="http://www.nunit.org" target="_blank">NUnit</a>, <a href="http://www.mbunit.com" target="_blank">MbUnit</a> and <a href="http://www.codeplex.com/xunit">xUnit.net</a> supported
out of the box</strong>
        </p>
        <p>
Pex now supports MSTest, NUnit, MbUnit and xUnit.net out of the box. Pex will automatically
detect which framework you are using by inspecting the assembly reference list, and
automatically save the generated tests decorated with the correct attributes for that
framework. 
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_22.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_10.png" width="604" height="351" />
          </a>
        </p>
        <p>
The default test framework can also be specified through the global options (Tools
–&gt; Options –&gt; Pex –&gt; enter the test framework name in TestFramework).
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_16.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_7.png" width="604" height="257" />
          </a>
        </p>
        <p>
 
</p>
        <p>
          <strong>Writing Parameterized Unit Tests in VisualBasic.NET</strong>
        </p>
        <p>
While the Pex white box analysis engine works at the MSIL level, Pex only emits C#
code for now. In previous releases, this limitation made it impossible to use Pex
parameterized unit tests from non-C# code. In this release, we have worked around
this problem by automatically saving the generated tests in a ‘satellite’ C# project.
</p>
        <p>
Let’s see this with an example. The screenshot below shows a single VisualBasic.NET
test project with a Pex parameterized unit test:
</p>
        <p>
          <a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image3.png">
            <b>
              <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image002_0dd1c4a7-6732-42b8-b6fe-76f7499e6a66.gif" width="604" height="237" />
            </b>
          </a>
        </p>
        <p>
We can right-click in the HelloTest.Hello method and select “Run Pex Explorations”:
</p>
        <p>
          <a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image7.png">
            <b>
              <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image004_31e0ecca-a518-4ec3-9ad4-3fef0bb58593.gif" width="305" height="91" />
            </b>
          </a>
        </p>
        <p>
At this point, Pex will start exploring the test in the background as usual. This
is where the new support comes in: When a generated test comes back to Visual Studio,
Pex will save it in a separate C# project automatically (after asking you where to
drop the new project):
</p>
        <p>
          <a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image19.png">
            <b>
              <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image006_324456a0-a756-4cfe-b9cb-e7eb8a9db8a0.gif" width="604" height="391" />
            </b>
          </a>
        </p>
        <p>
The generated tests are now ready to be run just as any other unit tests!
</p>
        <p>
          <strong>Writing Parameterized Unit Tests from F#</strong>
        </p>
        <p>
Similarly to VisualBasic.NET, we’ve made improvements in our infrastructure to enable
writing parameterized unit tests in <strong>F#</strong>. Let’s see this with a familiar
example. We have a single F# library that has xUnit.net unit tests and reference Microsoft.Pex.Framework
(project Library2 below). In that project, we add a parameterized unit test (hello_test):
</p>
        <p>
          <a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image32%5b1%5d.png">
            <b>
              <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image008" border="0" alt="clip_image008" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image008_709d95c3-12c4-4805-b549-2982d5341032.gif" width="604" height="235" />
            </b>
          </a>
        </p>
        <p>
We can right-click on the <strong>test method name</strong> and Pex will start the
exploration of that test in the background. Because of the limitations of the F# project
system, you <strong>absolutely</strong> need to right-click on the<strong> method
name</strong> in F# if you want contextual test selection to work. Because the project
is already referencing xunit.dll, Pex will also automatically detect that you are
using xUnit.net and use that framework. When the first test case comes back to VisualStudio,
Pex saves it in a separate C# project:
</p>
        <p>
          <a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image39.png">
            <b>
              <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image010" border="0" alt="clip_image010" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image010_69f5c0e9-4c03-4251-a79a-38c7ffbb3a19.gif" width="604" height="341" />
            </b>
          </a>
        </p>
        <p>
The tests are saved in the generated test project and ready to be run by your favorite
test runner!
</p>
        <p>
          <strong>PexObserve: Observing values, Asserting values</strong>
        </p>
        <p>
We’ve completely re-factored the way values can be logged on the table or saved as
assertions in the generated tests. The following example shows various ways to log
and assert values:
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_8.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_3.png" width="451" height="228" />
          </a>
        </p>
        <p>
In the Observe method, we use the return value and out parameter output to automatically
log and assert those values. Additionally, we add “view input” on the fly to the parameter
table through the ValueForViewing method, and we add “check input” to be asserted
through the ValueAtEndOfTest method. After running Pex, we get the following results:
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_10.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_4.png" width="373" height="63" />
          </a>
        </p>
        <p>
As expected, input, ‘view input’, output and result show up in the parameter table.
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_12.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_5.png" width="599" height="266" />
          </a>
        </p>
        <p>
In the generated test, we see assertions for the return value, out parameters and
other values passed through the ValueAtEndOfTest method.
</p>
        <p>
          <strong>
            <a href="http://research.microsoft.com/contracts">Code Contracts</a> : Reproducible
generated tests</strong>
        </p>
        <p>
When Pex generates a unit test that relied on a runtime contract, Pex also adds a
check to the unit test which validates that the contracts have been injected into
the code by the contracts rewriter. If the code is not rewritten when re-executing
the unit test, it is marked as inconclusive. You will appreciate this behavior when
you run your unit tests both in Release and in Debug builds, which usually differ
in how contracts get injected.
</p>
        <p>
          <a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image43.png">
            <b>
              <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image012" border="0" alt="clip_image012" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image012_32c70deb-1184-48c7-a1cd-16e1c19559d3.gif" width="604" height="177" />
            </b>
          </a>
        </p>
        <p>
          <strong>Code Contracts:  Automatic filtering of the contract violations</strong>
        </p>
        <p>
When Pex generates a test that violates a Code Contract pre-condition (i.e. Contract.Requires),
there are basically two scenarios: the precondition was on top of the stack and should
be considered as an expected exception; or it is a nested exception and should be
considered as a bug. Pex provides a default exception filtering that implements this
behavior.
</p>
        <p>
          <strong>
            <a href="http://research.microsoft.com/stubs" target="_blank">Stubs</a>: simplified
syntax</strong>
        </p>
        <p>
We’ve considerably simplified the syntax of stubs by removing the ‘this’ parameter
from the stub delegate definition. Let’s illustrate this with a test that stubs the
‘ReadAllText’ method of a fictitious ‘IFileSystem’ interface.  
</p>
        <p>
          <img src="http://research.microsoft.com/en-us/projects/stubs/stubexample.png" />
        </p>
        <p>
          <strong>
            <a href="http://research.microsoft.com/stubs" target="_blank">Stubs</a>: generic
methods</strong>
        </p>
        <p>
The <a href="http://research.microsoft.com/stubs" target="_blank">Stubs</a> framework
now supports stubbing generic methods by providing particular instantiations of that
method. In the following example, the generic Bar&lt;T&gt; method is stubbed for the
particular Bar&lt;int&gt; instantiation:
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_2.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb.png" width="435" height="119" />
          </a>
        </p>
        <p>
          <strong>Stubs and Pex: Pex will choose the stubs behavior by default</strong>
        </p>
        <p>
We provide a new custom attribute, PexChooseAsStubFallbackBehaviorAttribute, that
hooks Pex choices to the Stub fallback behavior. To illustrate what this means, let’s
modify slightly the example above by removing the stub of ReadAllText:
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_4.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_1.png" width="455" height="216" />
          </a>
        </p>
        <p>
If this test was to be run without the PexChooseAsStubFallbackBehavior attribute,
it would throw a StubNotImplementedException. However, with the PexChooseAsStubFallbackBehavior
attribute, the fallback behavior calls into PexChoose to ask Pex for a new string.
In this example in particular, on each call to ReadAllText, Pex will generate a new
string for the result. You can see this string as a new parameter to the parameterized
unit test. Therefore, when we run this test under Pex, we see different behavior happening,
including the “hello world” file:
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_6.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_2.png" width="584" height="90" />
          </a>
        </p>
        <p>
Note that all the necessary attributes are added at the assembly level by the Pex
Wizard.
</p>
        <p>
          <strong>Miscellanous bug fixes and improvements</strong>
        </p>
        <ul>
          <li>
[fixed] Dialogs do not render correctly under high DPI 
</li>
          <li>
When a generic parameterized unit tests does not have any generic argument instantiations,
Pex makes a guess for you. 
</li>
          <li>
When a test parameter is an interface or an abstract class, Pex now searches the known
assemblies for implementations and concrete classes. In particular, that means that
Pex will often automatically use the automatically generated Stubs implementations
for interfaces or abstract classes. 
</li>
          <li>
Static parameterized unit tests are supported (if static tests are supported by your
test framework) 
</li>
          <li>
Better solving of decimal and floating point constraints. We will report on the details
later. 
</li>
        </ul>
        <p>
          <strong>Breaking Changes</strong>
        </p>
        <ul>
          <li>
The PexFactoryClassAttribute is no longer needed and has been removed. Now, Pex will
pick up object factory methods marked with the PexFactoryMethodAttribute from any <i>static
class</i> in the test project containing the parameterized unit tests. If the generated
tests are stored in a separate project, that project is not searched. 
</li>
          <li>
The PexStore API has been renamed to PexObserve. 
</li>
          <li>
Pex is compatible with Code Contracts versions strictly newer than v1.1.20309.13.
Unfortunately, v1.1.20309.13 is the currently available version of Code <a href="http://research.microsoft.com/contracts" target="_blank">Contracts</a>.
The Code Contracts team is planning on a release soon. 
</li>
        </ul>
        <p>
 
</p>
        <p>
Happy Pexing!
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=83fde01f-786e-456d-b1c4-c8dd52448e69" />
      </body>
      <title>Pex v0.10.40408.0: NUnit, MbUnit, xUnit.Net, Visual Basic.NET, F# and more…</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,83fde01f-786e-456d-b1c4-c8dd52448e69.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/Hf0E2nXCC8c/PexV010404080NUnitMbUnitXUnitNetVisualBasicNETFAndMore.aspx</link>
      <pubDate>Fri, 10 Apr 2009 19:06:31 GMT</pubDate>
      <description>&lt;blockquote&gt; 
&lt;p&gt;
&lt;a href="http://research.microsoft.com/en-us/projects/pex/downloads.aspx" target="_blank"&gt;&lt;strong&gt;Download
the new version!&lt;/strong&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Today we’ve released a new release of &lt;a href="http://research.microsoft.com/pex"&gt;Pex&lt;/a&gt; on
DevLabs and on our academic downloads. This highlights of this release are: &lt;a href="http://www.nunit.org" target="_blank"&gt;NUnit&lt;/a&gt;, &lt;a href="http://www.mbunit.com/" target="_blank"&gt;MbUnit&lt;/a&gt; and &lt;a href="http://xunit.codeplex.com/" target="_blank"&gt;xUnit.net&lt;/a&gt; support
out of the box, &lt;strong&gt;writing &lt;a href="http://research.microsoft.com/pex"&gt;parameterized
unit tests&lt;/a&gt; in VisualBasic.NET and F#, better &lt;a href="http://research.microsoft.com/contracts"&gt;Code
Contracts&lt;/a&gt; support&lt;/strong&gt;. As always, if we encourage you to send us feedback,
bugs, stories on our forums at &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/pex/threads/"&gt;http://social.msdn.microsoft.com/Forums/en-US/pex/threads/&lt;/a&gt; .
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;a href="http://www.nunit.org" target="_blank"&gt;NUnit&lt;/a&gt;, &lt;a href="http://www.mbunit.com" target="_blank"&gt;MbUnit&lt;/a&gt; and &lt;a href="http://www.codeplex.com/xunit"&gt;xUnit.net&lt;/a&gt; supported
out of the box&lt;/strong&gt; 
&lt;/p&gt;
&lt;p&gt;
Pex now supports MSTest, NUnit, MbUnit and xUnit.net out of the box. Pex will automatically
detect which framework you are using by inspecting the assembly reference list, and
automatically save the generated tests decorated with the correct attributes for that
framework. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_22.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_10.png" width="604" height="351" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
The default test framework can also be specified through the global options (Tools
–&amp;gt; Options –&amp;gt; Pex –&amp;gt; enter the test framework name in TestFramework).
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_16.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_7.png" width="604" height="257" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Writing Parameterized Unit Tests in VisualBasic.NET&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
While the Pex white box analysis engine works at the MSIL level, Pex only emits C#
code for now. In previous releases, this limitation made it impossible to use Pex
parameterized unit tests from non-C# code. In this release, we have worked around
this problem by automatically saving the generated tests in a ‘satellite’ C# project.
&lt;/p&gt;
&lt;p&gt;
Let’s see this with an example. The screenshot below shows a single VisualBasic.NET
test project with a Pex parameterized unit test:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image3.png"&gt;&lt;b&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image002_0dd1c4a7-6732-42b8-b6fe-76f7499e6a66.gif" width="604" height="237" /&gt;&lt;/b&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
We can right-click in the HelloTest.Hello method and select “Run Pex Explorations”:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image7.png"&gt;&lt;b&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image004_31e0ecca-a518-4ec3-9ad4-3fef0bb58593.gif" width="305" height="91" /&gt;&lt;/b&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
At this point, Pex will start exploring the test in the background as usual. This
is where the new support comes in: When a generated test comes back to Visual Studio,
Pex will save it in a separate C# project automatically (after asking you where to
drop the new project):
&lt;/p&gt;
&lt;p&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image19.png"&gt;&lt;b&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image006_324456a0-a756-4cfe-b9cb-e7eb8a9db8a0.gif" width="604" height="391" /&gt;&lt;/b&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
The generated tests are now ready to be run just as any other unit tests!
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Writing Parameterized Unit Tests from F#&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Similarly to VisualBasic.NET, we’ve made improvements in our infrastructure to enable
writing parameterized unit tests in &lt;strong&gt;F#&lt;/strong&gt;. Let’s see this with a familiar
example. We have a single F# library that has xUnit.net unit tests and reference Microsoft.Pex.Framework
(project Library2 below). In that project, we add a parameterized unit test (hello_test):
&lt;/p&gt;
&lt;p&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image32%5b1%5d.png"&gt;&lt;b&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image008" border="0" alt="clip_image008" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image008_709d95c3-12c4-4805-b549-2982d5341032.gif" width="604" height="235" /&gt;&lt;/b&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
We can right-click on the &lt;strong&gt;test method name&lt;/strong&gt; and Pex will start the
exploration of that test in the background. Because of the limitations of the F# project
system, you &lt;strong&gt;absolutely&lt;/strong&gt; need to right-click on the&lt;strong&gt; method
name&lt;/strong&gt; in F# if you want contextual test selection to work. Because the project
is already referencing xunit.dll, Pex will also automatically detect that you are
using xUnit.net and use that framework. When the first test case comes back to VisualStudio,
Pex saves it in a separate C# project:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image39.png"&gt;&lt;b&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image010" border="0" alt="clip_image010" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image010_69f5c0e9-4c03-4251-a79a-38c7ffbb3a19.gif" width="604" height="341" /&gt;&lt;/b&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
The tests are saved in the generated test project and ready to be run by your favorite
test runner!
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;PexObserve: Observing values, Asserting values&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
We’ve completely re-factored the way values can be logged on the table or saved as
assertions in the generated tests. The following example shows various ways to log
and assert values:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_3.png" width="451" height="228" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
In the Observe method, we use the return value and out parameter output to automatically
log and assert those values. Additionally, we add “view input” on the fly to the parameter
table through the ValueForViewing method, and we add “check input” to be asserted
through the ValueAtEndOfTest method. After running Pex, we get the following results:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_10.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_4.png" width="373" height="63" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
As expected, input, ‘view input’, output and result show up in the parameter table.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_12.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_5.png" width="599" height="266" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
In the generated test, we see assertions for the return value, out parameters and
other values passed through the ValueAtEndOfTest method.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;a href="http://research.microsoft.com/contracts"&gt;Code Contracts&lt;/a&gt; : Reproducible
generated tests&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
When Pex generates a unit test that relied on a runtime contract, Pex also adds a
check to the unit test which validates that the contracts have been injected into
the code by the contracts rewriter. If the code is not rewritten when re-executing
the unit test, it is marked as inconclusive. You will appreciate this behavior when
you run your unit tests both in Release and in Debug builds, which usually differ
in how contracts get injected.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image43.png"&gt;&lt;b&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image012" border="0" alt="clip_image012" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image012_32c70deb-1184-48c7-a1cd-16e1c19559d3.gif" width="604" height="177" /&gt;&lt;/b&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Code Contracts:&amp;#160; Automatic filtering of the contract violations&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
When Pex generates a test that violates a Code Contract pre-condition (i.e. Contract.Requires),
there are basically two scenarios: the precondition was on top of the stack and should
be considered as an expected exception; or it is a nested exception and should be
considered as a bug. Pex provides a default exception filtering that implements this
behavior.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;a href="http://research.microsoft.com/stubs" target="_blank"&gt;Stubs&lt;/a&gt;: simplified
syntax&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
We’ve considerably simplified the syntax of stubs by removing the ‘this’ parameter
from the stub delegate definition. Let’s illustrate this with a test that stubs the
‘ReadAllText’ method of a fictitious ‘IFileSystem’ interface.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://research.microsoft.com/en-us/projects/stubs/stubexample.png" /&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;a href="http://research.microsoft.com/stubs" target="_blank"&gt;Stubs&lt;/a&gt;: generic
methods&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
The &lt;a href="http://research.microsoft.com/stubs" target="_blank"&gt;Stubs&lt;/a&gt; framework
now supports stubbing generic methods by providing particular instantiations of that
method. In the following example, the generic Bar&amp;lt;T&amp;gt; method is stubbed for the
particular Bar&amp;lt;int&amp;gt; instantiation:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb.png" width="435" height="119" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Stubs and Pex: Pex will choose the stubs behavior by default&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
We provide a new custom attribute, PexChooseAsStubFallbackBehaviorAttribute, that
hooks Pex choices to the Stub fallback behavior. To illustrate what this means, let’s
modify slightly the example above by removing the stub of ReadAllText:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_1.png" width="455" height="216" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
If this test was to be run without the PexChooseAsStubFallbackBehavior attribute,
it would throw a StubNotImplementedException. However, with the PexChooseAsStubFallbackBehavior
attribute, the fallback behavior calls into PexChoose to ask Pex for a new string.
In this example in particular, on each call to ReadAllText, Pex will generate a new
string for the result. You can see this string as a new parameter to the parameterized
unit test. Therefore, when we run this test under Pex, we see different behavior happening,
including the “hello world” file:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_2.png" width="584" height="90" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Note that all the necessary attributes are added at the assembly level by the Pex
Wizard.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Miscellanous bug fixes and improvements&lt;/strong&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
[fixed] Dialogs do not render correctly under high DPI 
&lt;/li&gt;
&lt;li&gt;
When a generic parameterized unit tests does not have any generic argument instantiations,
Pex makes a guess for you. 
&lt;/li&gt;
&lt;li&gt;
When a test parameter is an interface or an abstract class, Pex now searches the known
assemblies for implementations and concrete classes. In particular, that means that
Pex will often automatically use the automatically generated Stubs implementations
for interfaces or abstract classes. 
&lt;/li&gt;
&lt;li&gt;
Static parameterized unit tests are supported (if static tests are supported by your
test framework) 
&lt;/li&gt;
&lt;li&gt;
Better solving of decimal and floating point constraints. We will report on the details
later. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;strong&gt;Breaking Changes&lt;/strong&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
The PexFactoryClassAttribute is no longer needed and has been removed. Now, Pex will
pick up object factory methods marked with the PexFactoryMethodAttribute from any &lt;i&gt;static
class&lt;/i&gt; in the test project containing the parameterized unit tests. If the generated
tests are stored in a separate project, that project is not searched. 
&lt;/li&gt;
&lt;li&gt;
The PexStore API has been renamed to PexObserve. 
&lt;/li&gt;
&lt;li&gt;
Pex is compatible with Code Contracts versions strictly newer than v1.1.20309.13.
Unfortunately, v1.1.20309.13 is the currently available version of Code &lt;a href="http://research.microsoft.com/contracts" target="_blank"&gt;Contracts&lt;/a&gt;.
The Code Contracts team is planning on a release soon. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
Happy Pexing!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=83fde01f-786e-456d-b1c4-c8dd52448e69" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,83fde01f-786e-456d-b1c4-c8dd52448e69.aspx</comments>
      <category>Code Contracts</category>
      <category>MbUnit</category>
      <category>Pex</category>
      <category>RiSE</category>
      <category>Stubs</category>
      <category>Testing</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/04/10/PexV010404080NUnitMbUnitXUnitNetVisualBasicNETFAndMore.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=5a6044a6-c289-44a7-b921-f06e5b7bafb6</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,5a6044a6-c289-44a7-b921-f06e5b7bafb6.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,5a6044a6-c289-44a7-b921-f06e5b7bafb6.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=5a6044a6-c289-44a7-b921-f06e5b7bafb6</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I just released a new version of <strong>QuickGraph for Silverlight</strong> on <a href="http://quickgraph.codeplex.com">http://quickgraph.codeplex.com</a> .
You can grad it to run your favorite graph algorithm in the silverlight browser!
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=5a6044a6-c289-44a7-b921-f06e5b7bafb6" />
      </body>
      <title>QuickGraph for Silverlight (new release)</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,5a6044a6-c289-44a7-b921-f06e5b7bafb6.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/ZpEhelpXjwo/QuickGraphForSilverlightNewRelease.aspx</link>
      <pubDate>Thu, 09 Apr 2009 12:29:58 GMT</pubDate>
      <description>&lt;p&gt;
I just released a new version of &lt;strong&gt;QuickGraph for Silverlight&lt;/strong&gt; on &lt;a href="http://quickgraph.codeplex.com"&gt;http://quickgraph.codeplex.com&lt;/a&gt; .
You can grad it to run your favorite graph algorithm in the silverlight browser!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=5a6044a6-c289-44a7-b921-f06e5b7bafb6" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,5a6044a6-c289-44a7-b921-f06e5b7bafb6.aspx</comments>
      <category>QuickGraph</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/04/09/QuickGraphForSilverlightNewRelease.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=f6460df9-7923-4374-968b-480448f73990</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,f6460df9-7923-4374-968b-480448f73990.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,f6460df9-7923-4374-968b-480448f73990.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=f6460df9-7923-4374-968b-480448f73990</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The videos of TechDays are up:
</p>
        <ul>
          <li>
            <a title="TOOL302 Code Contracts, Pex and CHESS- 3 Tools, One Talk (englanninkielinen)" href="http://seminaarit.codezone.fi/video/techdays2009/pe-208-2/">TOOL302
Code Contracts, Pex and CHESS- 3 Tools, One Talk (englanninkielinen)</a>
          </li>
          <li>
            <a title="TOOL404 Pex – Automated White Box Testing for .NET (englanninkielinen)" href="http://seminaarit.codezone.fi/video/techdays2009/pe-208-4/">TOOL404
Pex – Automated White Box Testing for .NET (englanninkielinen)</a>
          </li>
        </ul>
        <p>
While attending TechDays Finland in Helsinki, I had the opportunity (thanks Vesa)
to take a swim in the baltic <strong>frozen</strong> sea along with fellow Microsoftie <a href="http://www.mostlylucid.net/" target="_blank">Scott
Galloway</a> (i’ll spare you the video of the actual bath).
</p>
        <p>
Great way to dust off the remaining of jetlag.
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/images/TechDaysBalticSeaSwimming_8120/P3060024.jpg">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="P3060024" border="0" alt="P3060024" src="http://blog.dotnetwiki.org/images/TechDaysBalticSeaSwimming_8120/P3060024_thumb.jpg" width="644" height="484" />
          </a>
        </p>
        <p>
ps: Yes we are standing on the sea.
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=f6460df9-7923-4374-968b-480448f73990" />
      </body>
      <title>TechDays Videos and Baltic Sea Swimming</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,f6460df9-7923-4374-968b-480448f73990.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/oA127iCEFhA/TechDaysVideosAndBalticSeaSwimming.aspx</link>
      <pubDate>Fri, 20 Mar 2009 00:28:22 GMT</pubDate>
      <description>&lt;p&gt;
The videos of TechDays are up:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a title="TOOL302 Code Contracts, Pex and CHESS- 3 Tools, One Talk (englanninkielinen)" href="http://seminaarit.codezone.fi/video/techdays2009/pe-208-2/"&gt;TOOL302
Code Contracts, Pex and CHESS- 3 Tools, One Talk (englanninkielinen)&lt;/a&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;a title="TOOL404 Pex – Automated White Box Testing for .NET (englanninkielinen)" href="http://seminaarit.codezone.fi/video/techdays2009/pe-208-4/"&gt;TOOL404
Pex – Automated White Box Testing for .NET (englanninkielinen)&lt;/a&gt; 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
While attending TechDays Finland in Helsinki, I had the opportunity (thanks Vesa)
to take a swim in the baltic &lt;strong&gt;frozen&lt;/strong&gt; sea along with fellow Microsoftie &lt;a href="http://www.mostlylucid.net/" target="_blank"&gt;Scott
Galloway&lt;/a&gt; (i’ll spare you the video of the actual bath).
&lt;/p&gt;
&lt;p&gt;
Great way to dust off the remaining of jetlag.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/images/TechDaysBalticSeaSwimming_8120/P3060024.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="P3060024" border="0" alt="P3060024" src="http://blog.dotnetwiki.org/images/TechDaysBalticSeaSwimming_8120/P3060024_thumb.jpg" width="644" height="484" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
ps: Yes we are standing on the sea.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=f6460df9-7923-4374-968b-480448f73990" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,f6460df9-7923-4374-968b-480448f73990.aspx</comments>
      <category>Code Contracts</category>
      <category>Personal</category>
      <category>Pex</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/03/20/TechDaysVideosAndBalticSeaSwimming.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=f586ceed-c585-437e-ac44-31644505b7a9</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,f586ceed-c585-437e-ac44-31644505b7a9.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,f586ceed-c585-437e-ac44-31644505b7a9.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=f586ceed-c585-437e-ac44-31644505b7a9</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The next version of Moq 3.0 will work better for <a href="http://research.microsoft.com/pex" target="_blank">Pex</a>:
</p>
        <blockquote>
          <p>
            <a title="http://www.clariusconsulting.net/blogs/kzu/archive/2009/03/05/120009.aspx" href="http://www.clariusconsulting.net/blogs/kzu/archive/2009/03/05/120009.aspx">http://www.clariusconsulting.net/blogs/kzu/archive/2009/03/05/120009.aspx</a>
          </p>
        </blockquote>
        <p>
In the past, Pex would analyze the Moq ‘engine’ code and spend a large amount of time
trying to understand the internals of that framework. In this release, Daniel has
added special annotations (see <a title="Extension Writer Handbook (PDF)" href="http://research.microsoft.com/en-us/projects/pex/guidancepexextensions.pdf">extension
writer Handbook)</a> that shut down the Pex monitoring for certain areas of Moq which
don’t matter to analyse the code under test.
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=f586ceed-c585-437e-ac44-31644505b7a9" />
      </body>
      <title>Moq 3.0 gets Pex friendly</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,f586ceed-c585-437e-ac44-31644505b7a9.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/RZT3AY_69J0/Moq30GetsPexFriendly.aspx</link>
      <pubDate>Sat, 07 Mar 2009 03:15:27 GMT</pubDate>
      <description>&lt;p&gt;
The next version of Moq 3.0 will work better for &lt;a href="http://research.microsoft.com/pex" target="_blank"&gt;Pex&lt;/a&gt;:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;a title="http://www.clariusconsulting.net/blogs/kzu/archive/2009/03/05/120009.aspx" href="http://www.clariusconsulting.net/blogs/kzu/archive/2009/03/05/120009.aspx"&gt;http://www.clariusconsulting.net/blogs/kzu/archive/2009/03/05/120009.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
In the past, Pex would analyze the Moq ‘engine’ code and spend a large amount of time
trying to understand the internals of that framework. In this release, Daniel has
added special annotations (see &lt;a title="Extension Writer Handbook (PDF)" href="http://research.microsoft.com/en-us/projects/pex/guidancepexextensions.pdf"&gt;extension
writer Handbook)&lt;/a&gt; that shut down the Pex monitoring for certain areas of Moq which
don’t matter to analyse the code under test.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=f586ceed-c585-437e-ac44-31644505b7a9" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,f586ceed-c585-437e-ac44-31644505b7a9.aspx</comments>
      <category>Pex</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/03/07/Moq30GetsPexFriendly.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=35666880-fe92-4d7e-8e37-aa74796f87a6</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,35666880-fe92-4d7e-8e37-aa74796f87a6.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,35666880-fe92-4d7e-8e37-aa74796f87a6.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=35666880-fe92-4d7e-8e37-aa74796f87a6</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://blog.dotnetwiki.org/images/QuickGraphonCodeContracts_6BA/image.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/images/QuickGraphonCodeContracts_6BA/image_thumb.png" width="244" height="101" />
          </a>
        </p>
        <p>
Ealier this week, we released the <a href="http://research.microsoft.com/contracts" target="_blank">Code
Contracts</a> library for .NET. Since then, I’ve implemented a lot for contracts for
the data structures in <a href="http://www.codeplex.com/quickgraph" target="_blank">QuickGraph</a> .
In this post, I’ll talk about my experience with the contracts…
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/images/QuickGraphonCodeContracts_6BA/image_3.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/images/QuickGraphonCodeContracts_6BA/image_thumb_3.png" width="311" height="569" />
          </a>
        </p>
        <p>
          <strong>Walking through some contracts.</strong>
        </p>
        <p>
Let’s take a look at the contracts of AddEdge, a method that adds an edge to a graph.
Adding an edge to a graph is certainly a fun adventure, when you write contracts for
it. Let’s take a look:
</p>
        <pre class="code">
          <span style="color: blue">public interface </span>
          <span style="color: #2b91af">IMutableEdgeListGraph</span>&lt;TVertex,
TEdge&gt; : ... <span style="color: blue">where </span>TEdge : <span style="color: #2b91af">IEdge</span>&lt;TVertex&gt;
{ <span style="color: gray">/// &lt;summary&gt; /// </span><span style="color: green">Adds
the edge to the graph </span><span style="color: gray">/// &lt;/summary&gt; /// &lt;param
name="edge"&gt;&lt;/param&gt; /// &lt;returns&gt;</span><span style="color: green">true
if the edge was added, otherwise false.</span><span style="color: gray">&lt;/returns&gt; </span><span style="color: blue">bool </span>AddEdge(TEdge
edge);</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
          <strong>Interface contracts</strong>
        </p>
        <p>
Since IMutableEdgeListGraph is an interface, we need to store the contracts in separate
class. To do so,  we ‘bind’ the interface and the contract class to each other
using the ContractClassForAttribute/ContractClassAttribute.
</p>
        <pre class="code">    [<span style="color: #2b91af">ContractClass</span>(<span style="color: blue">typeof</span>(<span style="color: #2b91af">IMutableEdgeListGraphContract</span>&lt;,&gt;))] <span style="color: blue"> public
interface </span><span style="color: #2b91af">IMutableEdgeListGraph</span>&lt;TVertex,
TEdge&gt; ...</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <pre class="code">    [<span style="color: #2b91af">ContractClassFor</span>(<span style="color: blue">typeof</span>(<span style="color: #2b91af">IMutableEdgeListGraph</span>&lt;,&gt;))] <span style="color: blue"> sealed
class </span><span style="color: #2b91af">IMutableEdgeListGraphContract</span>&lt;TVertex,
TEdge&gt; : <span style="color: #2b91af">IMutableEdgeListGraph</span>&lt;TVertex,
TEdge&gt; <span style="color: blue">where </span>TEdge : <span style="color: #2b91af">IEdge</span>&lt;TVertex&gt;</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
Once both types are bound, you can start implementing the contracts of the interface
in the contract class. Note that the contract class must use <i>explicit</i> interface
implementations for all methods.
</p>
        <p>
          <strong>Basic null checks</strong>
        </p>
        <p>
If you care about null references, the first contract will probably to ensure the
edge is not null. To make it quick and painless, make sure you use the <strong><em>crn</em></strong> snippet.
Note that since the method body of the contracts does not matter, we simply return
the default value.
</p>
        <pre class="code">
          <span style="color: blue">bool </span>
          <span style="color: #2b91af">IMutableEdgeListGraph</span>&lt;TVertex,
TEdge&gt;.AddEdge(TEdge e) { <strong><span style="color: #2b91af">Contract</span>.Requires(e
!= <span style="color: blue">null</span>); <span style="color: blue">return default</span>(<span style="color: blue">bool</span>); </strong>}</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
        </p>
        <p>
          <strong>More pre-conditions</strong>
        </p>
        <p>
One of the <em>implicit</em> requirement of AddEdge is that both vertices should already
belong to the graph. We want to make this <em>explicit</em> as a pre-condition as
well:
</p>
        <pre class="code">
          <span style="color: blue">bool </span>
          <span style="color: #2b91af">IMutableEdgeListGraph</span>&lt;TVertex,
TEdge&gt;.AddEdge(TEdge e) { <span style="color: #2b91af">IMutableEdgeListGraph</span>&lt;TVertex,
TEdge&gt; ithis = <span style="color: blue">this</span>; <span style="color: #2b91af">Contract</span>.Requires(e
!= <span style="color: blue">null</span>); <strong><span style="color: #2b91af">Contract</span>.Requires(ithis.ContainsVertex(e.Source)); <span style="color: #2b91af">Contract</span>.Requires(ithis.ContainsVertex(e.Target));</strong></pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
There are two things to notice here: (1) we had to cast the “this” pointer to the
interface we are writing contracts for, IMutableEdgeListGraph&lt;,&gt;. Because the
methods in a contract class must be explicit interface implementations, we do not
have access to the members of this interface from the “this” pointer, (2) ContainsVertex
had to be annotated with [Pure], as any method called from a contract must be pure: 
</p>
        <pre class="code">[<span style="color: #2b91af">Pure</span>] <span style="color: blue">bool </span>ContainsVertex(TVertex
vertex);</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
          <strong>What about post-conditions</strong>
        </p>
        <p>
One of my favorite feature of Code Contracts is to be able to state post-conditions.
This is done by calling the Contracts.Ensures method. For example, we start by expressing
that the edge must belong to the graph when we leave AddEdge:
</p>
        <pre class="code">
          <span style="color: blue">bool </span>
          <span style="color: #2b91af">IMutableEdgeListGraph</span>&lt;TVertex,
TEdge&gt;.AddEdge(TEdge e) { <span style="color: #2b91af">IMutableEdgeListGraph</span>&lt;TVertex,
TEdge&gt; ithis = <span style="color: blue">this</span>;<br />
... 
<br /><span style="color: #2b91af">Contract</span>.Ensures(ithis.ContainsEdge(e));</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
          <strong>Result and Old</strong>
        </p>
        <p>
Since the method returns a boolean, we should also state something about the result
value. To refer to the result, one has to use the Contract.Result&lt;T&gt;() method.
In this case,  the method returns true if the edge was new, false if it was already
in the graph. We can refer to a pre-state, i.e. the value of this.Contains(e) at the
beginning of the method***:
</p>
        <pre class="code">
          <span style="color: #2b91af">Contract</span>.Ensures(<span style="color: #2b91af">Contract</span>.Result&lt;<span style="color: blue">bool</span>&gt;() 
<br />
== <span style="color: #2b91af">Contract</span>.OldValue(!ithis.ContainsEdge(e)));</pre>
        <p>
Lastly, we can also make sure the edge count has been incremented, if an edge was
actually added (as you can see, we could use an implication operator in C#):
</p>
        <p>
          <span style="color: #2b91af">Contract</span>.Ensures(ithis.EdgeCount 
<br />
== <span style="color: #2b91af">Contract</span>.OldValue(ithis.EdgeCount) + (<span style="color: #2b91af">Contract</span>.Result&lt;<span style="color: blue">bool</span>&gt;()
? 1 : 0));
</p>
        <p>
*** The OldState value is evaluated after the preconditions.
</p>
        <p>
          <strong>Where to go next?</strong>
        </p>
        <p>
In the next post, I’ll show how to leverage these Contracts with <a href="http://research.microsoft.com/pex" target="_blank">Pex</a>…
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=35666880-fe92-4d7e-8e37-aa74796f87a6" />
      </body>
      <title>QuickGraph on Code Contracts</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,35666880-fe92-4d7e-8e37-aa74796f87a6.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/ZnWMth_usA8/QuickGraphOnCodeContracts.aspx</link>
      <pubDate>Sat, 28 Feb 2009 16:33:15 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/images/QuickGraphonCodeContracts_6BA/image.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/images/QuickGraphonCodeContracts_6BA/image_thumb.png" width="244" height="101" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Ealier this week, we released the &lt;a href="http://research.microsoft.com/contracts" target="_blank"&gt;Code
Contracts&lt;/a&gt; library for .NET. Since then, I’ve implemented a lot for contracts for
the data structures in &lt;a href="http://www.codeplex.com/quickgraph" target="_blank"&gt;QuickGraph&lt;/a&gt; .
In this post, I’ll talk about my experience with the contracts…
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/images/QuickGraphonCodeContracts_6BA/image_3.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/images/QuickGraphonCodeContracts_6BA/image_thumb_3.png" width="311" height="569" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Walking through some contracts.&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Let’s take a look at the contracts of AddEdge, a method that adds an edge to a graph.
Adding an edge to a graph is certainly a fun adventure, when you write contracts for
it. Let’s take a look:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public interface &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IMutableEdgeListGraph&lt;/span&gt;&amp;lt;TVertex,
TEdge&amp;gt; : ... &lt;span style="color: blue"&gt;where &lt;/span&gt;TEdge : &lt;span style="color: #2b91af"&gt;IEdge&lt;/span&gt;&amp;lt;TVertex&amp;gt;
{ &lt;span style="color: gray"&gt;/// &amp;lt;summary&amp;gt; /// &lt;/span&gt;&lt;span style="color: green"&gt;Adds
the edge to the graph &lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt; /// &amp;lt;param
name=&amp;quot;edge&amp;quot;&amp;gt;&amp;lt;/param&amp;gt; /// &amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;true
if the edge was added, otherwise false.&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/returns&amp;gt; &lt;/span&gt;&lt;span style="color: blue"&gt;bool &lt;/span&gt;AddEdge(TEdge
edge);&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
&lt;strong&gt;Interface contracts&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Since IMutableEdgeListGraph is an interface, we need to store the contracts in separate
class. To do so,&amp;#160; we ‘bind’ the interface and the contract class to each other
using the ContractClassForAttribute/ContractClassAttribute.
&lt;/p&gt;
&lt;pre class="code"&gt;    [&lt;span style="color: #2b91af"&gt;ContractClass&lt;/span&gt;(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;IMutableEdgeListGraphContract&lt;/span&gt;&amp;lt;,&amp;gt;))] &lt;span style="color: blue"&gt; public
interface &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IMutableEdgeListGraph&lt;/span&gt;&amp;lt;TVertex,
TEdge&amp;gt; ...&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; &lt;pre class="code"&gt;    [&lt;span style="color: #2b91af"&gt;ContractClassFor&lt;/span&gt;(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;IMutableEdgeListGraph&lt;/span&gt;&amp;lt;,&amp;gt;))] &lt;span style="color: blue"&gt; sealed
class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IMutableEdgeListGraphContract&lt;/span&gt;&amp;lt;TVertex,
TEdge&amp;gt; : &lt;span style="color: #2b91af"&gt;IMutableEdgeListGraph&lt;/span&gt;&amp;lt;TVertex,
TEdge&amp;gt; &lt;span style="color: blue"&gt;where &lt;/span&gt;TEdge : &lt;span style="color: #2b91af"&gt;IEdge&lt;/span&gt;&amp;lt;TVertex&amp;gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
Once both types are bound, you can start implementing the contracts of the interface
in the contract class. Note that the contract class must use &lt;i&gt;explicit&lt;/i&gt; interface
implementations for all methods.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Basic null checks&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
If you care about null references, the first contract will probably to ensure the
edge is not null. To make it quick and painless, make sure you use the &lt;strong&gt;&lt;em&gt;crn&lt;/em&gt;&lt;/strong&gt; snippet.
Note that since the method body of the contracts does not matter, we simply return
the default value.
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;bool &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IMutableEdgeListGraph&lt;/span&gt;&amp;lt;TVertex,
TEdge&amp;gt;.AddEdge(TEdge e) { &lt;strong&gt; &lt;span style="color: #2b91af"&gt;Contract&lt;/span&gt;.Requires(e
!= &lt;span style="color: blue"&gt;null&lt;/span&gt;); &lt;span style="color: blue"&gt;return default&lt;/span&gt;(&lt;span style="color: blue"&gt;bool&lt;/span&gt;); &lt;/strong&gt;}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;More pre-conditions&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
One of the &lt;em&gt;implicit&lt;/em&gt; requirement of AddEdge is that both vertices should already
belong to the graph. We want to make this &lt;em&gt;explicit&lt;/em&gt; as a pre-condition as
well:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;bool &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IMutableEdgeListGraph&lt;/span&gt;&amp;lt;TVertex,
TEdge&amp;gt;.AddEdge(TEdge e) { &lt;span style="color: #2b91af"&gt;IMutableEdgeListGraph&lt;/span&gt;&amp;lt;TVertex,
TEdge&amp;gt; ithis = &lt;span style="color: blue"&gt;this&lt;/span&gt;; &lt;span style="color: #2b91af"&gt;Contract&lt;/span&gt;.Requires(e
!= &lt;span style="color: blue"&gt;null&lt;/span&gt;); &lt;strong&gt; &lt;span style="color: #2b91af"&gt;Contract&lt;/span&gt;.Requires(ithis.ContainsVertex(e.Source)); &lt;span style="color: #2b91af"&gt;Contract&lt;/span&gt;.Requires(ithis.ContainsVertex(e.Target));&lt;/strong&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
There are two things to notice here: (1) we had to cast the “this” pointer to the
interface we are writing contracts for, IMutableEdgeListGraph&amp;lt;,&amp;gt;. Because the
methods in a contract class must be explicit interface implementations, we do not
have access to the members of this interface from the “this” pointer, (2) ContainsVertex
had to be annotated with [Pure], as any method called from a contract must be pure: 
&lt;/p&gt;
&lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;Pure&lt;/span&gt;] &lt;span style="color: blue"&gt;bool &lt;/span&gt;ContainsVertex(TVertex
vertex);&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
&lt;strong&gt;What about post-conditions&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
One of my favorite feature of Code Contracts is to be able to state post-conditions.
This is done by calling the Contracts.Ensures method. For example, we start by expressing
that the edge must belong to the graph when we leave AddEdge:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;bool &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IMutableEdgeListGraph&lt;/span&gt;&amp;lt;TVertex,
TEdge&amp;gt;.AddEdge(TEdge e) { &lt;span style="color: #2b91af"&gt;IMutableEdgeListGraph&lt;/span&gt;&amp;lt;TVertex,
TEdge&amp;gt; ithis = &lt;span style="color: blue"&gt;this&lt;/span&gt;;&lt;br /&gt;
... 
&lt;br /&gt;
&lt;span style="color: #2b91af"&gt;Contract&lt;/span&gt;.Ensures(ithis.ContainsEdge(e));&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
&lt;strong&gt;Result and Old&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Since the method returns a boolean, we should also state something about the result
value. To refer to the result, one has to use the Contract.Result&amp;lt;T&amp;gt;() method.
In this case,&amp;#160; the method returns true if the edge was new, false if it was already
in the graph. We can refer to a pre-state, i.e. the value of this.Contains(e) at the
beginning of the method***:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;Contract&lt;/span&gt;.Ensures(&lt;span style="color: #2b91af"&gt;Contract&lt;/span&gt;.Result&amp;lt;&lt;span style="color: blue"&gt;bool&lt;/span&gt;&amp;gt;() 
&lt;br /&gt;
== &lt;span style="color: #2b91af"&gt;Contract&lt;/span&gt;.OldValue(!ithis.ContainsEdge(e)));&lt;/pre&gt;
&lt;p&gt;
Lastly, we can also make sure the edge count has been incremented, if an edge was
actually added (as you can see, we could use an implication operator in C#):
&lt;/p&gt;
&lt;p&gt;
&lt;span style="color: #2b91af"&gt;Contract&lt;/span&gt;.Ensures(ithis.EdgeCount 
&lt;br /&gt;
== &lt;span style="color: #2b91af"&gt;Contract&lt;/span&gt;.OldValue(ithis.EdgeCount) + (&lt;span style="color: #2b91af"&gt;Contract&lt;/span&gt;.Result&amp;lt;&lt;span style="color: blue"&gt;bool&lt;/span&gt;&amp;gt;()
? 1 : 0));
&lt;/p&gt;
&lt;p&gt;
*** The OldState value is evaluated after the preconditions.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Where to go next?&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
In the next post, I’ll show how to leverage these Contracts with &lt;a href="http://research.microsoft.com/pex" target="_blank"&gt;Pex&lt;/a&gt;…
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=35666880-fe92-4d7e-8e37-aa74796f87a6" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,35666880-fe92-4d7e-8e37-aa74796f87a6.aspx</comments>
      <category>Code Contracts</category>
      <category>Pex</category>
      <category>QuickGraph</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/02/28/QuickGraphOnCodeContracts.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=b98ce5ca-514f-4514-81f4-b43d47767dfa</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,b98ce5ca-514f-4514-81f4-b43d47767dfa.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,b98ce5ca-514f-4514-81f4-b43d47767dfa.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=b98ce5ca-514f-4514-81f4-b43d47767dfa</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I’ll be travelling in Europe next month and presenting <a href="http://research.microsoft.com/pex" target="_blank">Pex</a>, <a href="http://research.microsoft.com/contracts" target="_blank">Code
Contracts</a> and <a href="http://research.microsoft.com/chess" target="_blank">CHESS</a> in
various events. Don’t forget to swing by, shake a hand and talk about geek stuff.
</p>
        <ul>
          <li>
March 5-6: <a href="http://www.techdays.fi/" target="_blank">TechDays Finland</a>,
in Helsinki, 
</li>
          <li>
March 9: <a href="http://www.dotned.nl/blogs/hassan_fadili/archive/2009/02/18/958.aspx" target="_blank">The
Netherlands .NET user group</a>, in Amsterdam, 
</li>
          <li>
March 10: <a href="http://dnug.org.uk/" target="_blank">London .NET user group</a>,
in London of course, 
</li>
          <li>
March 11-12: <a href="http://www.microsoft.com/belux/techdays/agenda.aspx" target="_blank">TechDays
Belgium</a>, in Antwerp, 
</li>
          <li>
March 13: Katholieke Universiteit Leuven, in Leuven 
</li>
        </ul>
        <p>
See you there!
</p>
        <p>
          <a href="http://www.microsoft.com/belux/techdays/about.aspx">
            <img style="display: inline; margin-left: 0px; margin-right: 0px" title="nav_brain_01" border="0" alt="nav_brain_01" src="http://blogs.msdn.com/blogfiles/charles_sterling/WindowsLiveWriter/TechDaysBelgiumtoStarourveryownTestBrain_A18C/nav_brain_01_3.jpg" width="219" height="184" />
          </a>
        </p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=b98ce5ca-514f-4514-81f4-b43d47767dfa" />
      </body>
      <title>Pex Europe Tour March’09</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,b98ce5ca-514f-4514-81f4-b43d47767dfa.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/srjBmUHvs0c/PexEuropeTourMarch09.aspx</link>
      <pubDate>Wed, 18 Feb 2009 06:45:33 GMT</pubDate>
      <description>&lt;p&gt;
I’ll be travelling in Europe next month and presenting &lt;a href="http://research.microsoft.com/pex" target="_blank"&gt;Pex&lt;/a&gt;, &lt;a href="http://research.microsoft.com/contracts" target="_blank"&gt;Code
Contracts&lt;/a&gt; and &lt;a href="http://research.microsoft.com/chess" target="_blank"&gt;CHESS&lt;/a&gt; in
various events. Don’t forget to swing by, shake a hand and talk about geek stuff.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
March 5-6: &lt;a href="http://www.techdays.fi/" target="_blank"&gt;TechDays Finland&lt;/a&gt;,
in Helsinki, 
&lt;/li&gt;
&lt;li&gt;
March 9: &lt;a href="http://www.dotned.nl/blogs/hassan_fadili/archive/2009/02/18/958.aspx" target="_blank"&gt;The
Netherlands .NET user group&lt;/a&gt;, in Amsterdam, 
&lt;/li&gt;
&lt;li&gt;
March 10: &lt;a href="http://dnug.org.uk/" target="_blank"&gt;London .NET user group&lt;/a&gt;,
in London of course, 
&lt;/li&gt;
&lt;li&gt;
March 11-12: &lt;a href="http://www.microsoft.com/belux/techdays/agenda.aspx" target="_blank"&gt;TechDays
Belgium&lt;/a&gt;, in Antwerp, 
&lt;/li&gt;
&lt;li&gt;
March 13: Katholieke Universiteit Leuven, in Leuven 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
See you there!
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.microsoft.com/belux/techdays/about.aspx"&gt;&lt;img style="display: inline; margin-left: 0px; margin-right: 0px" title="nav_brain_01" border="0" alt="nav_brain_01" src="http://blogs.msdn.com/blogfiles/charles_sterling/WindowsLiveWriter/TechDaysBelgiumtoStarourveryownTestBrain_A18C/nav_brain_01_3.jpg" width="219" height="184" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=b98ce5ca-514f-4514-81f4-b43d47767dfa" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,b98ce5ca-514f-4514-81f4-b43d47767dfa.aspx</comments>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/02/18/PexEuropeTourMarch09.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=28bacbcd-71a1-4915-bfdc-cba598b25584</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,28bacbcd-71a1-4915-bfdc-cba598b25584.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,28bacbcd-71a1-4915-bfdc-cba598b25584.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=28bacbcd-71a1-4915-bfdc-cba598b25584</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
 
</p>
        <p>
Ben presented a talk on <a href="http://research.microsoft.com/pex" target="_blank">Pex</a> a
couple months ago at <a href="http://www.developerday.co.uk/">DDD7</a>. The video
of the talk is now up on the web. Check it out!
</p>
        <p>
          <a href="http://blog.benhall.me.uk/2009/02/ddd7-session-video-microsoft-pex-future.html">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/images/BenHallonPexDDD7VideoPosted_75FC/image.png" width="244" height="212" />
          </a>
        </p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=28bacbcd-71a1-4915-bfdc-cba598b25584" />
      </body>
      <title>Ben Hall on Pex – DDD7 Video Posted</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,28bacbcd-71a1-4915-bfdc-cba598b25584.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/y3Zgcd0LkwA/BenHallOnPexDDD7VideoPosted.aspx</link>
      <pubDate>Tue, 03 Feb 2009 16:38:53 GMT</pubDate>
      <description>&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
Ben presented a talk on &lt;a href="http://research.microsoft.com/pex" target="_blank"&gt;Pex&lt;/a&gt; a
couple months ago at &lt;a href="http://www.developerday.co.uk/"&gt;DDD7&lt;/a&gt;. The video
of the talk is now up on the web. Check it out!
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.benhall.me.uk/2009/02/ddd7-session-video-microsoft-pex-future.html"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/images/BenHallonPexDDD7VideoPosted_75FC/image.png" width="244" height="212" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=28bacbcd-71a1-4915-bfdc-cba598b25584" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,28bacbcd-71a1-4915-bfdc-cba598b25584.aspx</comments>
      <category>Pex</category>
      <category>Testing</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/02/03/BenHallOnPexDDD7VideoPosted.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=2ba3e093-9a77-4e79-ad10-c8d29a5fb405</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,2ba3e093-9a77-4e79-ad10-c8d29a5fb405.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,2ba3e093-9a77-4e79-ad10-c8d29a5fb405.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=2ba3e093-9a77-4e79-ad10-c8d29a5fb405</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <img style="display: inline; margin-left: 0px; margin-right: 0px" align="right" src="http://research.microsoft.com/en-us/projects/chess/ChessLogoWebpage.png" />A
while ago at PDC, a couple of my colleagues presented <a href="http://research.microsoft.com/chess" target="_blank">CHESS</a> but
unfortunately weren’t ready to release it. Well, you don’t have to wait anymore: <a href="http://msdn.microsoft.com/en-us/devlabs/cc950526.aspx" target="_blank">CHESS
is now available for download at DevLabs</a> for Visual Studio 2008 Team Dev or Team
Test. CHESS comes under the same pre-release license as <a href="http://research.microsoft.com/pex" target="_blank">Pex</a> or
under <a href="http://research.microsoft.com/en-us/projects/chess/download.aspx" target="_blank">an
academic license</a>.
</p>
        <p>
          <strong>
          </strong>
        </p>
        <p>
          <strong>CHESS = Unit Testing of Concurrent Programs</strong>
        </p>
        <p>
CHESS is a tool that finds and reproduces “<a href="http://en.wikipedia.org/wiki/Unusual_software_bug" target="_blank">Heisenbugs</a>”
in concurrent programs (both Win32 and .NET)… You know those kind of bugs that do
not reproduce under the debugger or only in production environment, the kind of bugs
where you scratch your head for days in front of a process dump before giving up.
</p>
        <p>
I also recently recorded a great <a href="http://channel9.msdn.com/posts/Peli/Getting-started-with-CHESS-in-Visual-Studio-2008/" target="_blank">‘getting
started’ CHESS tutorial</a> for CHESS in Visual Studio Unit Test: you can take a unit
test*** and turn it into a CHESS test by adding the <strong>[HostType(“Chess”)]</strong> attribute!
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/images/CHE.1releasedonDevlabsFindingandReproduc_11322/image.png">
            <img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/images/CHE.1releasedonDevlabsFindingandReproduc_11322/image_thumb.png" width="297" height="115" />
          </a>
        </p>
        <p>
          <strong>*** </strong>That unit test should involve threads, otherwise CHESS will have
not effect.
</p>
        <p>
          <strong>CHESS and Pex</strong>
        </p>
        <p>
In order to control the scheduling of .NET programs, CHESS instruments the threading
APIs using <a href="http://research.microsoft.com/en-us/um/redmond/projects/pex/wiki/Microsoft.ExtendedReflection.html" target="_blank">ExtendedReflection</a>,
the code instrumentation framework that was built for Pex. In the future, we would
also like to combine both approach to explore data inputs and thread schedules together.
</p>
        <p>
Well enough said… go and try it out!
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=2ba3e093-9a77-4e79-ad10-c8d29a5fb405" />
      </body>
      <title>CHESS 0.1 released on Devlabs: Finding and Reproducing Heisenbugs in Concurrent Programs</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,2ba3e093-9a77-4e79-ad10-c8d29a5fb405.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/ZcWcFwFLwCQ/CHESS01ReleasedOnDevlabsFindingAndReproducingHeisenbugsInConcurrentPrograms.aspx</link>
      <pubDate>Fri, 30 Jan 2009 20:52:08 GMT</pubDate>
      <description>&lt;p&gt;
&lt;img style="display: inline; margin-left: 0px; margin-right: 0px" align="right" src="http://research.microsoft.com/en-us/projects/chess/ChessLogoWebpage.png" /&gt;A
while ago at PDC, a couple of my colleagues presented &lt;a href="http://research.microsoft.com/chess" target="_blank"&gt;CHESS&lt;/a&gt; but
unfortunately weren’t ready to release it. Well, you don’t have to wait anymore: &lt;a href="http://msdn.microsoft.com/en-us/devlabs/cc950526.aspx" target="_blank"&gt;CHESS
is now available for download at DevLabs&lt;/a&gt; for Visual Studio 2008 Team Dev or Team
Test. CHESS comes under the same pre-release license as &lt;a href="http://research.microsoft.com/pex" target="_blank"&gt;Pex&lt;/a&gt; or
under &lt;a href="http://research.microsoft.com/en-us/projects/chess/download.aspx" target="_blank"&gt;an
academic license&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;CHESS = Unit Testing of Concurrent Programs&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
CHESS is a tool that finds and reproduces “&lt;a href="http://en.wikipedia.org/wiki/Unusual_software_bug" target="_blank"&gt;Heisenbugs&lt;/a&gt;”
in concurrent programs (both Win32 and .NET)… You know those kind of bugs that do
not reproduce under the debugger or only in production environment, the kind of bugs
where you scratch your head for days in front of a process dump before giving up.
&lt;/p&gt;
&lt;p&gt;
I also recently recorded a great &lt;a href="http://channel9.msdn.com/posts/Peli/Getting-started-with-CHESS-in-Visual-Studio-2008/" target="_blank"&gt;‘getting
started’ CHESS tutorial&lt;/a&gt; for CHESS in Visual Studio Unit Test: you can take a unit
test*** and turn it into a CHESS test by adding the &lt;strong&gt;[HostType(“Chess”)]&lt;/strong&gt; attribute!
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/images/CHE.1releasedonDevlabsFindingandReproduc_11322/image.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/images/CHE.1releasedonDevlabsFindingandReproduc_11322/image_thumb.png" width="297" height="115" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;*** &lt;/strong&gt;That unit test should involve threads, otherwise CHESS will have
not effect.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;CHESS and Pex&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
In order to control the scheduling of .NET programs, CHESS instruments the threading
APIs using &lt;a href="http://research.microsoft.com/en-us/um/redmond/projects/pex/wiki/Microsoft.ExtendedReflection.html" target="_blank"&gt;ExtendedReflection&lt;/a&gt;,
the code instrumentation framework that was built for Pex. In the future, we would
also like to combine both approach to explore data inputs and thread schedules together.
&lt;/p&gt;
&lt;p&gt;
Well enough said… go and try it out!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=2ba3e093-9a77-4e79-ad10-c8d29a5fb405" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,2ba3e093-9a77-4e79-ad10-c8d29a5fb405.aspx</comments>
      <category>CHESS</category>
      <category>Pex</category>
      <category>RiSE</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/01/30/CHESS01ReleasedOnDevlabsFindingAndReproducingHeisenbugsInConcurrentPrograms.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=f5e8607a-aaad-419c-bc6e-9832dd06a063</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,f5e8607a-aaad-419c-bc6e-9832dd06a063.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,f5e8607a-aaad-419c-bc6e-9832dd06a063.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=f5e8607a-aaad-419c-bc6e-9832dd06a063</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.simple-talk.com/dotnet/.net-tools/annotating-code-with-.net-reflector-and-review-add-in/" target="_blank">Ben
Hall wrote a review</a> of my <a href="http://www.codeplex.com/reflectoraddins/Wiki/View.aspx?title=Review&amp;referringTitle=Home" target="_blank">Reflector
Review</a> addin. Nice tutorial on how to use this little helper.
</p>
        <p>
The Review addin lets you annotate and comments any metadata inside of Reflector.
</p>
        <p>
          <img alt="review.png" src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=reflectoraddins&amp;DownloadId=7281" />
        </p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=f5e8607a-aaad-419c-bc6e-9832dd06a063" />
      </body>
      <title>Reflector’s Review’s Review</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,f5e8607a-aaad-419c-bc6e-9832dd06a063.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/viNSNxWPDbw/ReflectorsReviewsReview.aspx</link>
      <pubDate>Tue, 27 Jan 2009 21:24:08 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://www.simple-talk.com/dotnet/.net-tools/annotating-code-with-.net-reflector-and-review-add-in/" target="_blank"&gt;Ben
Hall wrote a review&lt;/a&gt; of my &lt;a href="http://www.codeplex.com/reflectoraddins/Wiki/View.aspx?title=Review&amp;amp;referringTitle=Home" target="_blank"&gt;Reflector
Review&lt;/a&gt; addin. Nice tutorial on how to use this little helper.
&lt;/p&gt;
&lt;p&gt;
The Review addin lets you annotate and comments any metadata inside of Reflector.
&lt;/p&gt;
&lt;p&gt;
&lt;img alt="review.png" src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=reflectoraddins&amp;amp;DownloadId=7281" /&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=f5e8607a-aaad-419c-bc6e-9832dd06a063" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,f5e8607a-aaad-419c-bc6e-9832dd06a063.aspx</comments>
      <category>Reflector</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/01/27/ReflectorsReviewsReview.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=e327a7c9-a2f6-43ce-b96f-57ec42b2c467</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,e327a7c9-a2f6-43ce-b96f-57ec42b2c467.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,e327a7c9-a2f6-43ce-b96f-57ec42b2c467.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=e327a7c9-a2f6-43ce-b96f-57ec42b2c467</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <title>Named Formats Pex Testimonium</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,e327a7c9-a2f6-43ce-b96f-57ec42b2c467.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/HG3DiWUpSfE/NamedFormatsPexTestimonium.aspx</link>
      <pubDate>Fri, 16 Jan 2009 00:38:25 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a target="_blank" href="http://www.haacked.com/"&gt;Phil Haacked&lt;/a&gt; has started an &lt;a target="_blank" href="http://www.haacked.com/archive/2009/01/14/named-formats-redux.aspx"&gt;interresting
discussion&lt;/a&gt; on the implementation of a &lt;strong&gt;named formatter &lt;/strong&gt;whose format
strings are of the form {name} instead of {0}. In fact, he started with 3 implementations
and his reader submitted 2 more! Since Phil was kind enough to package all the implementations
(and the unit tests) in a solution, I took the liberty to run &lt;a target="_blank" href="http://research.microsoft.com/pex"&gt;Pex&lt;/a&gt; on
them and see if there was any issue lurking out. The goal of this post is not really
to show that those implementation are correct or not, but give you an idea where Pex
could be applicable in your code.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;But wait, it’s already Unit Tested!&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Indeed, Phil diligently wrote a unit test suite that covers many different use cases.
Does it mean you are done with testing? The named format syntax can be tricky since
may involve escaping curly braces… What is the named format syntax anyway? It’s pretty
obvious that it should let you write something like “{Name} is {Status}” instead of
“{0} is {1}” but that still pretty vague. In particular, what are the syntactic rules
for escaping curly braces (what’s the meaning {{}{}{{}}}, etc…) or is there even a
grammar describing named formats. 
&lt;/p&gt;
&lt;p&gt;
As it is often the case, there is no clear and definitive answer – at least I could
not find it –. In this post, I’ll show 2 techniques that can be used here out of the
many &lt;a href="http://research.microsoft.com/en-us/projects/pex/pexpatterns.pdf"&gt;patterns&lt;/a&gt; for
Pex which we documented.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Technique 1: Explore for runtime errors (&lt;/strong&gt;&lt;a target="_blank" href="http://research.microsoft.com/en-us/projects/pex/pexpatterns.pdf"&gt;pattern
2.12 – parameterized stub&lt;/a&gt;&lt;strong&gt;)&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
The most basic way of running Pex is to simply apply Pex on a method without adding
any assertions. At this point, you are looking for NullReferenceException, IndexOutOfRanceException
or other violations of lower level APIs. Although this kind of testing won’t help
you answer whether your code is correct, it may give you back instances where it is
wrong. For example, by passing any format and object into the format method in a parameterized
unit test; the code below is a parameterized unit test for which Pex can generate
relevant inputs:
&lt;/p&gt;
&lt;blockquote&gt; &lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;PexMethod&lt;/span&gt;] &lt;span style="color: blue"&gt;public
void &lt;/span&gt;HenriFormat(&lt;span style="color: blue"&gt;string &lt;/span&gt;format, &lt;span style="color: blue"&gt;object &lt;/span&gt;o)
{ format.HenriFormat(o); }&lt;/pre&gt;
&lt;/blockquote&gt; &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
Note that it took a couple runs of Pex to figure the right set of assemblies to be
instrumented. Hopefully, this process is mostly automated and you simply have to apply
the changes that Pex suggests.
&lt;/p&gt;
&lt;p&gt;
The screenshot below shows the input generated by Pex. Intuitively, I would think
that FormatException is expected and part of properly rejecting invalid inputs. However,
there are ArgumentOutOfRanceExceptions triggered inside of the DataBinder code that
probably should intercepted earlier. If this implementation uses the DataBinder code,
it should make sure that it only gets acceptable values. Whether those issues are
worth fixing is a tricky question: maybe the programmer intended to let this behavior
happen.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/images/NamedFormatsPexus_D1D0/image.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/images/NamedFormatsPexus_D1D0/image_thumb.png" width="798" height="451" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Technique 2: Compare different implementations (&lt;a target="_blank" href="http://research.microsoft.com/en-us/projects/pex/pexpatterns.pdf"&gt;pattern
2.7 – same observable behavior&lt;/a&gt;)&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
A second approach is to compare the output of the different implementations. Since
all the implementations implement the same (underspecified) named format specification,
their behavior should match with respect to any input. This property makes it really
easy to write really powerful &lt;a target="_blank" href="http://research.microsoft.com/pex"&gt;parameterized
unit tests&lt;/a&gt;. For example, the following test asserts that the Haacked and Hanselman
implementation have the same observable behavior, i.e. return the same string or throw
the same exception type (PexAssert.AreBehaviorEqual takes care of asserting this):
&lt;/p&gt;
&lt;blockquote&gt; &lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;PexMethod&lt;/span&gt;] &lt;span style="color: blue"&gt;public
void &lt;/span&gt;HaackVsHansel(&lt;span style="color: blue"&gt;string &lt;/span&gt;format, &lt;span style="color: blue"&gt;object &lt;/span&gt;o)
{ &lt;span style="color: #2b91af"&gt;PexAssert&lt;/span&gt;.AreBehaviorsEqual( () =&gt; format.HaackFormat(o),
() =&gt; format.HanselFormat(o) ); }&lt;/pre&gt;
&lt;/blockquote&gt; &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
Again, this kind of testing will not help to answer if the code is correct but it
will give you instance where the different implementations behave differently, which
means one of the two (or even both) have a bug. This is a great technique to test
a new implementation against an old (fully tested) implementation which can be used
as oracle. We run the test and Pex comes back with this list of test cases. For example,
the format string “\0\0{{{{“ leads to different output for both implementation. From
the different outputs, “\0\0{{“ vs “\0\0{{{{“, it seems that curly braces are escaped
differently. If I wanted to dig deeper, I could also simply debug the generated test
case.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/images/NamedFormatsPexus_D1D0/image_3.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/images/NamedFormatsPexus_D1D0/image_thumb_3.png" width="752" height="448" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Comparing All Implementations&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Now that we’ve seen that Phil and Scott were not agreeing, could we apply this to
the other formatters. I quickly set up a &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/bb126445.aspx"&gt;T4
template&lt;/a&gt; to generate the code for all the parameterized unit tests between each
formatters. Note that order matters for Pex: calling A then B might lead to a different
test suite compared to B then A, just because Pex explores the code in different orders.
&lt;/p&gt;
&lt;blockquote&gt; &lt;pre class="code"&gt;&lt;#@ template language="C#" #&gt;

&lt;# string[] formatters = new string[] {
        "Hansel",
        "Henri",
        "James",
        "Oskar",
        "Haack"
    };
#&gt;
using System; using Microsoft.Pex.Framework; using Microsoft.Pex.Framework.Validation;
using Microsoft.VisualStudio.TestTools.UnitTesting; using UnitTests; using StringLib;
namespace UnitTests { [TestClass] [PexClass(MaxConstraintSolverTime = 2, MaxRunsWithoutNewTests
= 200)] public partial class StringFormatterTestsTest { 
&lt;# foreach(string left in formatters) { 
           foreach(string right in formatters) {
               if (left == right) continue;    
        #&gt;&lt;#= left #&gt;&lt;#= right #&gt;&lt;#= left #&gt;&lt;#= right #&gt;
[PexMethod] public void Vs(string format, object o) { PexAssert.AreBehaviorsEqual(
() =&gt; format.Format(o), () =&gt; format.Format(o) ); } 
&lt;#
           } 
        } #&gt;
} }
&lt;/pre&gt;
&lt;/blockquote&gt; &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
The answer that Pex returns is interresting and scary: &lt;strong&gt;none of the implementation
behaviors match. &lt;/strong&gt;This is somewhat not surprising since they all use radically
different approaches to solve this problem: regex vs string api etc…
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Try it for yourself.&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
The &lt;a target="_blank" href="http://research.microsoft.com/en-us/projects/pex/namedstringformatsolution.zip"&gt;full
modified source is available for download here&lt;/a&gt;. You will need to install Pex from &lt;a href="http://research.microsoft.com/pex/downloads.aspx"&gt;http://research.microsoft.com/pex/downloads.aspx&lt;/a&gt; to
re-execute the parameterized unit tests.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=e327a7c9-a2f6-43ce-b96f-57ec42b2c467" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,e327a7c9-a2f6-43ce-b96f-57ec42b2c467.aspx</comments>
      <category>Pex</category>
      <category>Testing</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/01/16/NamedFormatsPexTestimonium.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=327254b0-3b54-4e4b-ae7e-c0812023980b</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,327254b0-3b54-4e4b-ae7e-c0812023980b.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,327254b0-3b54-4e4b-ae7e-c0812023980b.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=327254b0-3b54-4e4b-ae7e-c0812023980b</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Today, we released the 0.9.40105.0 version of <a target="_blank" href="http://research.microsoft.com/pex">Pex</a>.
The major highlights of this release are: <strong>Pre-Release license for Visual Studio
2008, better test framework integration and partial support for Visual Basic.NET/F# </strong>(<a target="_blank" href="http://research.microsoft.com/pex/releasenotes.aspx">read
the full release notes</a>)<strong>.</strong></p>
        <p>
          <a target="_blank" href="http://research.microsoft.com/chess">CHESS</a>, another project
from <a target="_blank" href="http://research.microsoft.com/rise">RiSE</a>, also released
it’s first public download today. CHESS finds and reproduces heisenbugs in concurrent
programs. CHESS uses the Pex code instrumentation technology to monitor and control
the .Net threading APIs, and one day we hope to combine Pex and CHESS…
</p>
        <p>
Enjoy and don’t forget to give us your feedback through the <a target="_blank" href="http://social.msdn.microsoft.com/Forums/en-US/pex/threads/">MSDN
forums</a>.
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=327254b0-3b54-4e4b-ae7e-c0812023980b" />
      </body>
      <title>Pex 0.9 released: Pre-Release license for VS2008, better Test Framework integration and partial support for Visual Basic.NET/F#.</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,327254b0-3b54-4e4b-ae7e-c0812023980b.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/JF_vTJ19_OQ/Pex09ReleasedPreReleaseLicenseForVS2008BetterTestFrameworkIntegrationAndPartialSupportForVisualBasicNETF.aspx</link>
      <pubDate>Wed, 14 Jan 2009 20:21:29 GMT</pubDate>
      <description>&lt;p&gt;
Today, we released the 0.9.40105.0 version of &lt;a target="_blank" href="http://research.microsoft.com/pex"&gt;Pex&lt;/a&gt;.
The major highlights of this release are: &lt;strong&gt;Pre-Release license for Visual Studio
2008, better test framework integration and partial support for Visual Basic.NET/F# &lt;/strong&gt;(&lt;a target="_blank" href="http://research.microsoft.com/pex/releasenotes.aspx"&gt;read
the full release notes&lt;/a&gt;)&lt;strong&gt;.&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a target="_blank" href="http://research.microsoft.com/chess"&gt;CHESS&lt;/a&gt;, another project
from &lt;a target="_blank" href="http://research.microsoft.com/rise"&gt;RiSE&lt;/a&gt;, also released
it’s first public download today. CHESS finds and reproduces heisenbugs in concurrent
programs. CHESS uses the Pex code instrumentation technology to monitor and control
the .Net threading APIs, and one day we hope to combine Pex and CHESS…
&lt;/p&gt;
&lt;p&gt;
Enjoy and don’t forget to give us your feedback through the &lt;a target="_blank" href="http://social.msdn.microsoft.com/Forums/en-US/pex/threads/"&gt;MSDN
forums&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=327254b0-3b54-4e4b-ae7e-c0812023980b" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,327254b0-3b54-4e4b-ae7e-c0812023980b.aspx</comments>
      <category>Pex</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/01/14/Pex09ReleasedPreReleaseLicenseForVS2008BetterTestFrameworkIntegrationAndPartialSupportForVisualBasicNETF.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=1969e7c2-fd47-43cd-83e9-4f11889dd99d</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,1969e7c2-fd47-43cd-83e9-4f11889dd99d.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,1969e7c2-fd47-43cd-83e9-4f11889dd99d.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=1969e7c2-fd47-43cd-83e9-4f11889dd99d</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <title>Introduction to the Stubs Framework</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,1969e7c2-fd47-43cd-83e9-4f11889dd99d.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/IZ-HL0uW3_c/IntroductionToTheStubsFramework.aspx</link>
      <pubDate>Sat, 10 Jan 2009 15:41:32 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a target="_blank" href="http://blog.dotnetwiki.org/PexGetsAStubsFrameworkISaidStubsNotMocks.aspx"&gt;Stubs&lt;/a&gt; is
a framework for generating stubs (that &lt;a target="_blank" href="http://blog.dotnetwiki.org/PexGetsAStubsFrameworkISaidStubsNotMocks.aspx"&gt;we
announced earlier with Pex&lt;/a&gt;). The framework generates stubs (not mocks) that are 
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
lightweight, i.e. relying on delegates only, 
&lt;/li&gt;
&lt;li&gt;
strongly typed, i.e. no magic strings – refactoring friendly, 
&lt;/li&gt;
&lt;li&gt;
source code generated, i.e. no dynamic code or expression trees, 
&lt;/li&gt;
&lt;li&gt;
great debugging experience, i.e. break and step through stubs, 
&lt;/li&gt;
&lt;li&gt;
minimalistic API (there is almost none), 
&lt;/li&gt;
&lt;li&gt;
friendly for &lt;a target="_blank" href="http://research.microsoft.com/pex"&gt;Pex&lt;/a&gt;! 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
More details about Stubs are also available in the &lt;a target="_blank" href="http://research.microsoft.com/en-us/projects/pex/stubs.pdf"&gt;stubs
reference document&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Quick Start&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Let’s start from a simple interface &lt;font face="Courier New"&gt;IFileSystem &lt;/font&gt;for
which we want to write stubs:
&lt;/p&gt;
&lt;blockquote&gt; &lt;pre class="code"&gt;&lt;span style="color: blue;"&gt;public interface &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;IFileSystem &lt;/span&gt;{ &lt;span style="color: blue;"&gt;void &lt;/span&gt;WriteAllText(&lt;span style="color: blue;"&gt;string &lt;/span&gt;fileName, &lt;span style="color: blue;"&gt;string &lt;/span&gt;content); &lt;span style="color: blue;"&gt;string &lt;/span&gt;ReadAllText(&lt;span style="color: blue;"&gt;string &lt;/span&gt;fileName);
}&lt;/pre&gt;
&lt;/blockquote&gt; &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
&lt;strong&gt;Stubs&lt;/strong&gt; relies solely on delegates to attach behaviors, and leverages
the lambda syntax from C# 3.0 to accomplish pretty much anything:
&lt;/p&gt;
&lt;blockquote&gt; &lt;pre class="code"&gt;&lt;span style="color: green;"&gt;// SFileSystem was generated
by Stubs and stubs IFileSystem &lt;/span&gt;&lt;span style="color: blue;"&gt;var &lt;/span&gt;stub = &lt;span style="color: blue;"&gt;new &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;SFileSystem&lt;/span&gt;(); &lt;span style="color: green;"&gt;//
always returns “...” &lt;/span&gt;stub.ReadAllText = (me, file) =&gt; &lt;span style="color: rgb(163, 21, 21);"&gt;"..."&lt;/span&gt;; &lt;span style="color: green;"&gt;//
expectations: checks file = “foo.txt” &lt;/span&gt;stub.ReadAllText = (me, file) =&gt; { &lt;span style="color: rgb(43, 145, 175);"&gt;Assert&lt;/span&gt;.AreEqual(&lt;span style="color: rgb(163, 21, 21);"&gt;"foo.txt"&lt;/span&gt;,
file); &lt;span style="color: blue;"&gt;return &lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"..."&lt;/span&gt;;
}; &lt;span style="color: green;"&gt;// storing side effects in closures: written saves
content &lt;/span&gt;&lt;span style="color: blue;"&gt;string &lt;/span&gt;written = &lt;span style="color: blue;"&gt;null&lt;/span&gt;;
stub.WriteAllText = (me, file, content) =&gt; written = content; &lt;span style="color: green;"&gt;//
hey, we can do whatever we want! &lt;/span&gt;stub.ReadAllText = (me, file) =&gt; { &lt;span style="color: blue;"&gt;if &lt;/span&gt;(file
== &lt;span style="color: blue;"&gt;null&lt;/span&gt;) &lt;span style="color: blue;"&gt;throw new &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;ArgumentNullException&lt;/span&gt;(); &lt;span style="color: blue;"&gt;return &lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"..."&lt;/span&gt;;
};&lt;/pre&gt;
&lt;pre class="code"&gt;&lt;span style="color: green;"&gt;// downcast to the interface to use
it &lt;/span&gt;IFileSystem fs = stubs;&lt;/pre&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Anything is possible… as long as C# (or your favorite language) allows it.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Anatomy of a Stub&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Each stubbed method has an associated field delegate that can be set freely (e.g. &lt;font face="Courier New"&gt;WriteAllText &lt;/font&gt;and &lt;font face="Courier New"&gt;ReadAllText&lt;/font&gt;).
If this delegate field is set, it will used when the method is called; otherwize a
default action occurs. Let’s see this with a simplified stub of the &lt;font face="Courier New"&gt;IFileSystem &lt;/font&gt;interface, &lt;font face="Courier New"&gt;SFileSystem&lt;/font&gt;,
which shows how the &lt;font face="Courier New"&gt;IFileSystem.WriteAllText&lt;/font&gt; is implemented:
&lt;/p&gt;
&lt;blockquote&gt; &lt;pre class="code"&gt;&lt;span style="color: blue;"&gt;class &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;SFileSystem &lt;/span&gt;: &lt;span style="color: rgb(43, 145, 175);"&gt;StubBase&lt;/span&gt;&lt;&lt;span style="color: rgb(43, 145, 175);"&gt;SFileSystem&gt;&gt;
, &lt;span style="color: rgb(43, 145, 175);"&gt;IFileSystem &lt;/span&gt;{ &lt;span style="color: blue;"&gt;public &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;Action&lt;/span&gt;&lt;&lt;span style="color: rgb(43, 145, 175);"&gt;SFileSystem&gt;, &lt;span style="color: blue;"&gt;string&lt;/span&gt;, &lt;span style="color: blue;"&gt;string&lt;/span&gt;&gt;
WriteAllText; // attach here &lt;span style="color: blue;"&gt;void &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;IFileSystem&lt;/span&gt;.WriteAllText(&lt;span style="color: blue;"&gt;string &lt;/span&gt;fileName, &lt;span style="color: blue;"&gt;string &lt;/span&gt;content)
{ &lt;span style="color: blue;"&gt;var &lt;/span&gt;stub = &lt;span style="color: blue;"&gt;this&lt;/span&gt;.WriteAllText; &lt;span style="color: blue;"&gt;if &lt;/span&gt;(stub
!= &lt;span style="color: blue;"&gt;null&lt;/span&gt;) stub(&lt;span style="color: blue;"&gt;this&lt;/span&gt;,
fileName, content); // your code executed here &lt;span style="color: blue;"&gt;else this&lt;/span&gt;.DefaultStub.VoidResult(&lt;span style="color: blue;"&gt;this&lt;/span&gt;);
} }&lt;/pre&gt;
&lt;/blockquote&gt; &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
The actual generated code may look more complicated because it contains custom attributes
for debugging, comments and globally qualified types to avoid name clashing:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/images/StubspartIGettingStarted_F368/image.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="image" alt="image" src="http://blog.dotnetwiki.org/images/StubspartIGettingStarted_F368/image_thumb.png" width="604" border="0" height="387"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Code generation: How does it work?&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Stubs&lt;/strong&gt; is a single file generator that pre-generates stubs to source
code. &lt;strong&gt;Stubs&lt;/strong&gt; also monitors the build and regenerates the source code
when a change occurs.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/images/StubspartIGettingStarted_F368/image_3.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="image" alt="image" src="http://blog.dotnetwiki.org/images/StubspartIGettingStarted_F368/image_thumb_3.png" width="243" border="0" height="277"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
The stub generation is configured through an XML file (&lt;strong&gt;.stubx&lt;/strong&gt; file)
that contains which code and how it should be generated. The generated code is saved
in a ‘Designer’ file, similarly to other code generation tools (type dataset etc…). 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/images/StubspartIGettingStarted_F368/image_4.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="image" alt="image" src="http://blog.dotnetwiki.org/images/StubspartIGettingStarted_F368/image_thumb_4.png" width="476" border="0" height="71"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Great debugging experience&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
A cool side effect of simply using delegates: you can step through and debug your
stubs! This is usually not the case with mock framework using dynamic code. Below,
you can see that one can set breakpoints in the body of a stub and debug as usual.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/images/StubspartIGettingStarted_F368/image_5.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="image" alt="image" src="http://blog.dotnetwiki.org/images/StubspartIGettingStarted_F368/image_thumb_5.png" width="687" border="0" height="323"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Where do I get it?&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
The Stubs framework comes with Pex but you can use it in any unit testing activity.
It provides a simple lightweight alternative to define stub for testing. Pex can be
downloaded from &lt;a href="http://research.microsoft.com/pex"&gt;http://research.microsoft.com/pex&lt;/a&gt; .
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=1969e7c2-fd47-43cd-83e9-4f11889dd99d" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,1969e7c2-fd47-43cd-83e9-4f11889dd99d.aspx</comments>
      <category>Pex</category>
      <category>Stubs</category>
      <category>Testing</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/01/10/IntroductionToTheStubsFramework.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=0970233e-8ce3-435a-b2e5-2fc6ccd0bb8f</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,0970233e-8ce3-435a-b2e5-2fc6ccd0bb8f.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,0970233e-8ce3-435a-b2e5-2fc6ccd0bb8f.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=0970233e-8ce3-435a-b2e5-2fc6ccd0bb8f</wfw:commentRss>
      <title>Tarjan Offline Least Common Ancestor in C# (with QuickGraph)</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,0970233e-8ce3-435a-b2e5-2fc6ccd0bb8f.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/DBYHdk2x0m4/TarjanOfflineLeastCommonAncestorInCWithQuickGraph.aspx</link>
      <pubDate>Thu, 08 Jan 2009 08:32:54 GMT</pubDate>
      <description>&lt;p&gt;
Following the implementation of the &lt;a target="_blank" href="http://blog.dotnetwiki.org/WritingADisjointSetInCWithTheHelpOfCodeContractsAndPex.aspx"&gt;disjointset&lt;/a&gt;,
another fun algorithm to implement was the offline &lt;a target="_blank" href="http://en.wikipedia.org/wiki/Lowest_common_ancestor"&gt;least
common ancestor problem&lt;/a&gt;. &lt;a target="_blank" href="http://en.wikipedia.org/wiki/Tarjan%27s_off-line_least_common_ancestors_algorithm"&gt;Tarjan
proposed a algorithm&lt;/a&gt; based on the disjoint-set and a DFS traversal. Given that
I now have all those ingredients in &lt;a target="_blank" href="http://www.codeplex.com/quickgraph"&gt;QuickGraph&lt;/a&gt;,
it was just a matter of hooking together the implementation with the right events.
The beef of the implementation looks as follows (and looks quite elegant to me):
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;gpair = &lt;span style="color: #2b91af"&gt;GraphExtensions&lt;/span&gt;.ToAdjacencyGraph(&lt;span style="color: blue"&gt;this&lt;/span&gt;.pairs);
// for fast lookup &lt;span style="color: blue"&gt;var &lt;/span&gt;disjointSet = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ForestDisjointSet&lt;/span&gt;
&lt;TVertex&gt;
(); &lt;span style="color: blue"&gt;var &lt;/span&gt;vancestors = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Dictionary&lt;/span&gt;&lt;TVertex, TVertex&gt;(); &lt;span style="color: blue"&gt;var &lt;/span&gt;dfs
= &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DepthFirstSearchAlgorithm&lt;/span&gt;&lt;TVertex, TEdge&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;, &lt;span style="color: blue"&gt;this&lt;/span&gt;.VisitedGraph, &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Dictionary&lt;/span&gt;&lt;TVertex, &lt;span style="color: #2b91af"&gt;GraphColor&gt;&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.VisitedGraph.VertexCount));
dfs.InitializeVertex += (sender, args) =&gt; disjointSet.MakeSet(args.Vertex); dfs.DiscoverVertex
+= (sender, args) =&gt; vancestors[args.Vertex] = args.Vertex; dfs.TreeEdge += (sender,
args) =&gt; { &lt;span style="color: blue"&gt;var &lt;/span&gt;edge = args.Edge; disjointSet.Union(edge.Source,
edge.Target); vancestors[disjointSet.FindSet(edge.Source)] = edge.Source; }; dfs.FinishVertex
+= (sender, args) =&gt; { &lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;e &lt;span style="color: blue"&gt;in &lt;/span&gt;gpair.OutEdges(args.Vertex)) &lt;span style="color: blue"&gt;if &lt;/span&gt;(dfs.VertexColors[e.Target]
== &lt;span style="color: #2b91af"&gt;GraphColor&lt;/span&gt;.Black) &lt;span style="color: blue"&gt;this&lt;/span&gt;.ancestors[&lt;span style="color: #2b91af"&gt;EdgeExtensions&lt;/span&gt;.ToVertexPair(e)]
= vancestors[disjointSet.FindSet(e.Target)]; }; &lt;span style="color: green"&gt;// go! &lt;/span&gt;dfs.Compute(root);
&lt;/pre&gt;&lt;/blockquote&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
Enjoy!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=0970233e-8ce3-435a-b2e5-2fc6ccd0bb8f" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,0970233e-8ce3-435a-b2e5-2fc6ccd0bb8f.aspx</comments>
      <category>QuickGraph</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/01/08/TarjanOfflineLeastCommonAncestorInCWithQuickGraph.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=e52cfaba-ca74-4841-8067-9fd229873685</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,e52cfaba-ca74-4841-8067-9fd229873685.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,e52cfaba-ca74-4841-8067-9fd229873685.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=e52cfaba-ca74-4841-8067-9fd229873685</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The <a target="_blank" href="http://www.nist.gov/dads/HTML/kthShortestPath.html"><strong>k-shortest
paths</strong></a> computes the <em>k</em> first shortest path between two vertices
in a directed graph. If you put this in the context of route planning, it gives you <em>k</em> alternative
routes in case the shortest path is blocked by snow :) While the <a target="_blank" href="http://en.wikipedia.org/wiki/Shortest_path_problem">single
source shortest</a> path is well-known and implemented in many languages, there are
not many implementations available for this problem, although it has been extensively
studied. After looking around, I stumbled on a <a target="_blank" href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.54.3286">nice
article comparing various approaches</a>. The authors pointed out <a target="_blank" href="http://citeseerx.ist.psu.edu/showciting?cid=463224">an
algorithm from 1959 from Hoffman and Pavley</a> that solved this problem (there are
actually many others). This algorithm looked like a good fit:
</p>
        <ul>
          <li>
it requires a single call to a single-source shortest path algorithm. Other approaches
will require as much as <em>kn</em> calls to a shortest path algorithm.</li>
          <li>
it sounded simple and did not require new specialized data structures.</li>
        </ul>
        <p>
          <strong>I want to try it!</strong>
        </p>
        <p align="left">
The algorithm is available in <a target="_blank" href="http://www.codeplex.com/quickgraph">QuickGraph</a> 3.1.40104.00
and up. You can take a look at it at <a title="http://www.codeplex.com/quickgraph/SourceControl/changeset/view/29858#377982" href="http://www.codeplex.com/quickgraph/SourceControl/changeset/view/29858#377982">http://www.codeplex.com/quickgraph/SourceControl/changeset/view/29858#377982</a>.
To use it on a <em>BidirectionalGraph</em>, 
</p>
        <blockquote>
          <p>
IBidirectionalGraph&lt;TVertex, TEdge&gt; g = …;<br />
foreach(IEnumerable&lt;TEdge&gt; path in g.RankedShortestPathHoffmanPavley(weights,
source, goal, 4))<br />
     …
</p>
        </blockquote>
        <p>
          <strong>A glimpse at the Hoffmann-Pavley algorithm</strong>
        </p>
        <p>
The algorithm works in 2 phases. 
</p>
        <p>
On the first phase, we build a minimum ‘successor’ tree towards the goal vertex. This
tree can be used to build a shortest path from any (reachable) vertex to the goal
vertex. To build this tree, we can simply apply the Dijkstra shortest path algorithm
on the reversed graph. This can be done in a couple lines with QuickGraph.
</p>
        <p>
As for many other <em>k</em>-shortest path algorithm, phase works by building deviation
path and picking the best one. In the case of the Hoffman-Pavley algorithm, it works
as follows: pick the latest shortest path, for each vertex of this path, build a deviation
path (more later) for each out-edge and add it to a priority queue. Then start again:
</p>
        <blockquote>
          <p>
var queue = new PriorityQueue&lt;Path&gt;();<br />
queue.Enqueue(shortestpath);<br />
while(queue.Count &gt; 0) {<br />
    var path = queue.Dequeue();<br />
    foreach(var vertex in path)<br />
        foreach(var edge in graph.OutEdges(vertex))<br />
             queue.Enqueue(CreateDeviation(path,
vertex, edge));<br />
}
</p>
        </blockquote>
        <p>
A deviation path is composed of three parts: 
</p>
        <ol>
          <li>
the initial part of the ‘seeding’ path, i.e. the edges before the deviation edge,</li>
          <li>
the deviation edge</li>
          <li>
the remaining shortest path to the goal. When we build the deviation path, we also
compute it’s weight. A nice property of the deviation paths is that they can be ‘built’
when needed. This saves a lot of space and computation as most deviation paths will
probably not end up in the winning set of paths – instead of storing a full path,
we store a path index and an edge index.</li>
        </ol>
        <p>
That’s it! The details contain more code to deal with self-edges and loops but the
main idea is there. This is definitely a very elegant algorithm!
</p>
        <p>
          <strong>What about testing!</strong>
        </p>
        <p>
Algorithm authors usually illustrate their approach with an example. This is a good
way to get started on a small graph example and ensure that the algorithm works as
the original author expected. This is the kind of unit test I get started with.
</p>
        <p>
The next step is to apply the algorithm to a large number of graph instances. Unfortunately,
I do not have any other k-shortest path algorithm, so the oracle is harder to build
here. Nevertheless, the result of the algorithm, i.e. the shortest path collection,
has a couple of properties that should always be true:
</p>
        <ul>
          <li>
the algorithm produces loopless paths,</li>
          <li>
path <em>k</em> is lower or equal to path <em>k</em> + 1.</li>
        </ul>
        <p>
The problem with this test is that it does not guarantee that some shortest path have
been missed. At this point, I’m a bit puzzled on how to test that.
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=e52cfaba-ca74-4841-8067-9fd229873685" />
      </body>
      <title>A K-Shortest Path implementation in .Net</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,e52cfaba-ca74-4841-8067-9fd229873685.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/8rC1osEz7Yw/AKShortestPathImplementationInNet.aspx</link>
      <pubDate>Mon, 05 Jan 2009 07:05:14 GMT</pubDate>
      <description>&lt;p&gt;
The &lt;a target="_blank" href="http://www.nist.gov/dads/HTML/kthShortestPath.html"&gt;&lt;strong&gt;k-shortest
paths&lt;/strong&gt;&lt;/a&gt; computes the &lt;em&gt;k&lt;/em&gt; first shortest path between two vertices
in a directed graph. If you put this in the context of route planning, it gives you &lt;em&gt;k&lt;/em&gt; alternative
routes in case the shortest path is blocked by snow :) While the &lt;a target="_blank" href="http://en.wikipedia.org/wiki/Shortest_path_problem"&gt;single
source shortest&lt;/a&gt; path is well-known and implemented in many languages, there are
not many implementations available for this problem, although it has been extensively
studied. After looking around, I stumbled on a &lt;a target="_blank" href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.54.3286"&gt;nice
article comparing various approaches&lt;/a&gt;. The authors pointed out &lt;a target="_blank" href="http://citeseerx.ist.psu.edu/showciting?cid=463224"&gt;an
algorithm from 1959 from Hoffman and Pavley&lt;/a&gt; that solved this problem (there are
actually many others). This algorithm looked like a good fit:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
it requires a single call to a single-source shortest path algorithm. Other approaches
will require as much as &lt;em&gt;kn&lt;/em&gt; calls to a shortest path algorithm.&lt;/li&gt;
&lt;li&gt;
it sounded simple and did not require new specialized data structures.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;strong&gt;I want to try it!&lt;/strong&gt;
&lt;/p&gt;
&lt;p align="left"&gt;
The algorithm is available in &lt;a target="_blank" href="http://www.codeplex.com/quickgraph"&gt;QuickGraph&lt;/a&gt; 3.1.40104.00
and up. You can take a look at it at &lt;a title="http://www.codeplex.com/quickgraph/SourceControl/changeset/view/29858#377982" href="http://www.codeplex.com/quickgraph/SourceControl/changeset/view/29858#377982"&gt;http://www.codeplex.com/quickgraph/SourceControl/changeset/view/29858#377982&lt;/a&gt;.
To use it on a &lt;em&gt;BidirectionalGraph&lt;/em&gt;, 
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
IBidirectionalGraph&amp;lt;TVertex, TEdge&amp;gt; g = …;&lt;br&gt;
foreach(IEnumerable&amp;lt;TEdge&amp;gt; path in g.RankedShortestPathHoffmanPavley(weights,
source, goal, 4))&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; …
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&lt;strong&gt;A glimpse at the Hoffmann-Pavley algorithm&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
The algorithm works in 2 phases. 
&lt;/p&gt;
&lt;p&gt;
On the first phase, we build a minimum ‘successor’ tree towards the goal vertex. This
tree can be used to build a shortest path from any (reachable) vertex to the goal
vertex. To build this tree, we can simply apply the Dijkstra shortest path algorithm
on the reversed graph. This can be done in a couple lines with QuickGraph.
&lt;/p&gt;
&lt;p&gt;
As for many other &lt;em&gt;k&lt;/em&gt;-shortest path algorithm, phase works by building deviation
path and picking the best one. In the case of the Hoffman-Pavley algorithm, it works
as follows: pick the latest shortest path, for each vertex of this path, build a deviation
path (more later) for each out-edge and add it to a priority queue. Then start again:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
var queue = new PriorityQueue&amp;lt;Path&amp;gt;();&lt;br&gt;
queue.Enqueue(shortestpath);&lt;br&gt;
while(queue.Count &amp;gt; 0) {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; var path = queue.Dequeue();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach(var vertex in path)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach(var edge in graph.OutEdges(vertex))&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; queue.Enqueue(CreateDeviation(path,
vertex, edge));&lt;br&gt;
}
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
A deviation path is composed of three parts: 
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
the initial part of the ‘seeding’ path, i.e. the edges before the deviation edge,&lt;/li&gt;
&lt;li&gt;
the deviation edge&lt;/li&gt;
&lt;li&gt;
the remaining shortest path to the goal. When we build the deviation path, we also
compute it’s weight. A nice property of the deviation paths is that they can be ‘built’
when needed. This saves a lot of space and computation as most deviation paths will
probably not end up in the winning set of paths – instead of storing a full path,
we store a path index and an edge index.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
That’s it! The details contain more code to deal with self-edges and loops but the
main idea is there. This is definitely a very elegant algorithm!
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;What about testing!&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Algorithm authors usually illustrate their approach with an example. This is a good
way to get started on a small graph example and ensure that the algorithm works as
the original author expected. This is the kind of unit test I get started with.
&lt;/p&gt;
&lt;p&gt;
The next step is to apply the algorithm to a large number of graph instances. Unfortunately,
I do not have any other k-shortest path algorithm, so the oracle is harder to build
here. Nevertheless, the result of the algorithm, i.e. the shortest path collection,
has a couple of properties that should always be true:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
the algorithm produces loopless paths,&lt;/li&gt;
&lt;li&gt;
path &lt;em&gt;k&lt;/em&gt; is lower or equal to path &lt;em&gt;k&lt;/em&gt; + 1.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
The problem with this test is that it does not guarantee that some shortest path have
been missed. At this point, I’m a bit puzzled on how to test that.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=e52cfaba-ca74-4841-8067-9fd229873685" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,e52cfaba-ca74-4841-8067-9fd229873685.aspx</comments>
      <category>Fun with graphs</category>
      <category>QuickGraph</category>
      <category>Testing</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/01/05/AKShortestPathImplementationInNet.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=32bd1002-4f51-4702-a6e3-7a8b6c2bde0d</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,32bd1002-4f51-4702-a6e3-7a8b6c2bde0d.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,32bd1002-4f51-4702-a6e3-7a8b6c2bde0d.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=32bd1002-4f51-4702-a6e3-7a8b6c2bde0d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <blockquote>
          <p>
When you implement an algorithm that computes an optimal solution (i.e. minimum/maximum
with respect to a cost function), how do you test that the solution is actually optimal? 
</p>
        </blockquote>
        <p>
This is the kind of question I face when implementing algorithms in <a target="_blank" href="http://www.codeplex.com/quickgraph">QuickGraph</a>.
For example, I was recently looking at the <a target="_blank" href="http://en.wikipedia.org/wiki/Minimum_spanning_tree">minimum
spanning tree of a graph</a> (MST)? While checking that the result tree is a spanning
tree is easy, checking that it is <em>minimum</em> is not obvious: nobody has written <em>Assert.IsMinimum</em> yet
:). Here are a couple techniques that I found useful along the way: 
</p>
        <p>
          <strong>Input-Output table</strong>
        </p>
        <p>
The most obvious approach is to pre-compute the result for a number of problems and
assert the solution of the algorithm matches. In this MST case, use a small set of
graphs for which the MST is well known, and check that the computed MST has the correct
weight. This approach will take you only so far and requires a lot of manual work
since you need to solve the problem (or find a known solution) for a number of representative
cases.
</p>
        <p>
          <strong>Solution Perturbation</strong>
        </p>
        <p>
If the algorithm computes a solution that is minimal with respect to a cost function,
one can try to perturbate the solution to see if there’s a smaller one. If so, it
clearly violates the fact that the solution should be minimal, thus you just found
a bug. In the case of MST, this would mean randomly picking edges that are not in
the minimum spanning tree, swapping them and evaluate if the result tree is smaller.
</p>
        <p>
This is kind of approach is actually used in optimization where the search space might
have local minima (see <a target="_blank" href="http://en.wikipedia.org/wiki/Simulated_annealing">simulated
annealing</a>).
</p>
        <p>
          <strong>Multiple Implementations</strong>
        </p>
        <p>
A nice thing about graph problems is that there are usually many (vastly) different
ways to solve them. If multiple implementations are available, we can simply compare
the result of each algorithm against each other and make sure that they match each
other. Each algorithm might have bugs but it is unlikely that they share common ones.
Since we have now a good oracle, we can apply this approach that a large number of
inputs to increase our coverage.
</p>
        <p>
In the MST case, two popular algorithms are <a target="_blank" href="http://en.wikipedia.org/wiki/Prim's_algorithm">Prim’s</a> and <a target="_blank" href="http://en.wikipedia.org/wiki/Kruskal's_algorithm">Kruskal’s</a>.
Those are 2 different approaches: Prim is built on top of <a target="_blank" href="http://en.wikipedia.org/wiki/Dijkstra's_algorithm">Dijkstra
single source shortest path</a>, while Kruskal is built on top of the <a target="_blank" href="http://blog.dotnetwiki.org/WritingADisjointSetInCWithTheHelpOfCodeContractsAndPex.aspx">disjoint-set</a> data
structure. By carefully picking the weights of the edges, we can assert different
things:
</p>
        <ul>
          <li>
if the edge weights are all equals, any spanning tree is minimal. So we can compare
the result to a depth-first-search algorithm (which can easily compute a spanning
tree). 
</li>
          <li>
if some edge weights are different, there may be many minimum spanning tree. In this
case, we can still assert that weight of the tree is minimum. 
</li>
          <li>
if all the edge weights are different, then the MST is unique. This fact can be used
to precisely pinpoint the differences in solution during testing.</li>
        </ul>
        <p>
There is a corner case that needs to be checked: if all algorithm are no-op, i.e.
they don’t do anything. There solution will always match!
</p>
        <p>
Happy New Year!
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=32bd1002-4f51-4702-a6e3-7a8b6c2bde0d" />
      </body>
      <title>Testing Graph Algorithms With Optimal Solutions</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,32bd1002-4f51-4702-a6e3-7a8b6c2bde0d.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/Uk4jPVWI5WQ/TestingGraphAlgorithmsWithOptimalSolutions.aspx</link>
      <pubDate>Thu, 01 Jan 2009 17:03:14 GMT</pubDate>
      <description>&lt;blockquote&gt; 
&lt;p&gt;
When you implement an algorithm that computes an optimal solution (i.e. minimum/maximum
with respect to a cost function), how do you test that the solution is actually optimal? 
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
This is the kind of question I face when implementing algorithms in &lt;a target="_blank" href="http://www.codeplex.com/quickgraph"&gt;QuickGraph&lt;/a&gt;.
For example, I was recently looking at the &lt;a target="_blank" href="http://en.wikipedia.org/wiki/Minimum_spanning_tree"&gt;minimum
spanning tree of a graph&lt;/a&gt; (MST)? While checking that the result tree is a spanning
tree is easy, checking that it is &lt;em&gt;minimum&lt;/em&gt; is not obvious: nobody has written &lt;em&gt;Assert.IsMinimum&lt;/em&gt; yet
:). Here are a couple techniques that I found useful along the way: 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Input-Output table&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
The most obvious approach is to pre-compute the result for a number of problems and
assert the solution of the algorithm matches. In this MST case, use a small set of
graphs for which the MST is well known, and check that the computed MST has the correct
weight. This approach will take you only so far and requires a lot of manual work
since you need to solve the problem (or find a known solution) for a number of representative
cases.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Solution Perturbation&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
If the algorithm computes a solution that is minimal with respect to a cost function,
one can try to perturbate the solution to see if there’s a smaller one. If so, it
clearly violates the fact that the solution should be minimal, thus you just found
a bug. In the case of MST, this would mean randomly picking edges that are not in
the minimum spanning tree, swapping them and evaluate if the result tree is smaller.
&lt;/p&gt;
&lt;p&gt;
This is kind of approach is actually used in optimization where the search space might
have local minima (see &lt;a target="_blank" href="http://en.wikipedia.org/wiki/Simulated_annealing"&gt;simulated
annealing&lt;/a&gt;).
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Multiple Implementations&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
A nice thing about graph problems is that there are usually many (vastly) different
ways to solve them. If multiple implementations are available, we can simply compare
the result of each algorithm against each other and make sure that they match each
other. Each algorithm might have bugs but it is unlikely that they share common ones.
Since we have now a good oracle, we can apply this approach that a large number of
inputs to increase our coverage.
&lt;/p&gt;
&lt;p&gt;
In the MST case, two popular algorithms are &lt;a target="_blank" href="http://en.wikipedia.org/wiki/Prim's_algorithm"&gt;Prim’s&lt;/a&gt; and &lt;a target="_blank" href="http://en.wikipedia.org/wiki/Kruskal's_algorithm"&gt;Kruskal’s&lt;/a&gt;.
Those are 2 different approaches: Prim is built on top of &lt;a target="_blank" href="http://en.wikipedia.org/wiki/Dijkstra's_algorithm"&gt;Dijkstra
single source shortest path&lt;/a&gt;, while Kruskal is built on top of the &lt;a target="_blank" href="http://blog.dotnetwiki.org/WritingADisjointSetInCWithTheHelpOfCodeContractsAndPex.aspx"&gt;disjoint-set&lt;/a&gt; data
structure. By carefully picking the weights of the edges, we can assert different
things:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
if the edge weights are all equals, any spanning tree is minimal. So we can compare
the result to a depth-first-search algorithm (which can easily compute a spanning
tree). 
&lt;li&gt;
if some edge weights are different, there may be many minimum spanning tree. In this
case, we can still assert that weight of the tree is minimum. 
&lt;li&gt;
if all the edge weights are different, then the MST is unique. This fact can be used
to precisely pinpoint the differences in solution during testing.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
There is a corner case that needs to be checked: if all algorithm are no-op, i.e.
they don’t do anything. There solution will always match!
&lt;/p&gt;
&lt;p&gt;
Happy New Year!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=32bd1002-4f51-4702-a6e3-7a8b6c2bde0d" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,32bd1002-4f51-4702-a6e3-7a8b6c2bde0d.aspx</comments>
      <category>QuickGraph</category>
      <category>Testing</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2009/01/01/TestingGraphAlgorithmsWithOptimalSolutions.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=06a6b1c8-6cc3-4728-9791-c129619219eb</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,06a6b1c8-6cc3-4728-9791-c129619219eb.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,06a6b1c8-6cc3-4728-9791-c129619219eb.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=06a6b1c8-6cc3-4728-9791-c129619219eb</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I recently implemented a <a target="_blank" href="http://en.wikipedia.org/wiki/Disjoint-set_data_structure">Disjoint-Set</a> data
structure in <a target="_blank" href="http://www.codeplex.com/quickgraph">QuickGraph</a>,
which is the main building block of the <a target="_blank" href="http://en.wikipedia.org/wiki/Kruskal%27s_algorithm">Kruskal’s
minimum spanning tree algorithm</a>. This is a fun data-structure to look at, as it
purpose is quite different from the ‘main’ BCL collections. The disjoint-set is useful
to partition elements into sets, and defines 2 main operation to that purpose: <em>Find</em>,
finds the set an element belongs to (can be used to check if 2 elements are in the
same set), <em>Union</em> merges two sets.
</p>
        <p>
The <a target="_blank" href="http://www.codeplex.com/quickgraph/SourceControl/changeset/view/29499#343829">source
of the disjoint-set</a> is in the QuickGraph source, if you are curious about the
details.
</p>
        <p>
          <strong>Testing the disjoint-set</strong>
        </p>
        <p>
There is not much left to TDD when it comes to write data structure. Such data structure
are usually described in details in an article, and you ‘just’ have to follow the
authors instruction to implement. Nevertheless, unit testing is really critical to
ensure that the implementation is correct – but there is a risk of having to re-implement
the algorithm to test it. 
</p>
        <p>
For the disjoint-set, I used 2 tools developed at <a target="_blank" href="http://research.microsoft.com/rise">RiSE</a>: <a target="_blank" href="http://research.microsoft.com/contracts">Code
Contracts</a> and… <a target="_blank" href="http://research.microsoft.com/pex">Pex</a>.
When implementing data structure from the literature, I usually start ‘dumping’ the
code and the contracts. As much as possible, any invariant or property that the author
describes should be translated to contracts. It will give more opportunities for Pex
to find bugs in my code.
</p>
        <p>
          <strong>Contracts First</strong>
        </p>
        <p>
For example, the contracts for the <strong>Union</strong> method look as follows:
</p>
        <blockquote>
          <pre class="code">
            <span style="color: blue">private bool </span>Union(<span style="color: #2b91af">Element </span>left, <span style="color: #2b91af">Element </span>right)
{ <span style="color: #2b91af">Contract</span>.Requires(left != <span style="color: blue">null</span>); <span style="color: #2b91af">Contract</span>.Requires(right
!= <span style="color: blue">null</span>); <span style="color: #2b91af">Contract</span>.Ensures(<span style="color: #2b91af">Contract</span>.Result&lt;<span style="color: blue">bool</span>&gt;()
? <span style="color: #2b91af">Contract</span>.OldValue(<span style="color: blue">this</span>.SetCount)
- 1 == <span style="color: blue">this</span>.SetCount : <span style="color: #2b91af">Contract</span>.OldValue(<span style="color: blue">this</span>.SetCount)
== <span style="color: blue">this</span>.SetCount ); <span style="color: #2b91af">Contract</span>.Ensures(<span style="color: blue">this</span>.FindNoCompression(left)
== <span style="color: blue">this</span>.FindNoCompression(right)); </pre>
        </blockquote>
        <a href="http://11011.net/software/vspaste">
        </a>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
The two first requires clauses do the usual null checks. The first ensures clause
checks that if <em>Union</em> returns true, a merge has been done and the number of
sets has decreased by 1. The last ensures checks that left and right belong to the
same set at the end of the union. 
</p>
        <p>
Note that so far, I did not have to provide any kind of implementation details. The
other methods in the implementation receive the same treatment.
</p>
        <p>
          <strong>A Parameterized Unit Test</strong>
        </p>
        <p>
I wrote a single parameterized unit test while writing/debugging the implementation
of the forest. It could probably have been re-factored into many smaller tests, but
for the sake of laziness, I used a single one.
</p>
        <p>
The parameterized unit test implement a common scenario: add elements to the disjoint-set,
then apply a bunch of union operations. Along the way, we can rely on test assertion
and code contracts to check the correctness of our implementation.
</p>
        <p>
Let’s start with the test method signature:
</p>
        <blockquote>
          <pre class="code">[<span style="color: #2b91af">PexMethod</span>] <span style="color: blue">public
void </span>Unions(<span style="color: blue">int </span>elementCount, [<span style="color: #2b91af">PexAssumeNotNull</span>]<span style="color: #2b91af">KeyValuePair</span>&lt;<span style="color: blue">int</span>,<span style="color: blue">int</span>&gt;[]
unions) {</pre>
        </blockquote>
        <p>
The test takes a number of element to add and a sequence of unions to apply. The input
data as is needs to be refined to be useful. In that sense, we add <strong>assumptions</strong>,
under the form of calls to <em>PexAssume</em>, to tell Pex ‘how it should shape’ the
input data. In this case, we want to ensure that <em>elementCount</em> is positive
and relatively small; and that the values in unions are within the <em>[0…elementCount)</em> range.
</p>
        <blockquote>
          <pre class="code">
            <span style="color: #2b91af">
              <font color="#000000">
              </font>PexAssume</span>.IsTrue(0
&lt; elementCount); <span style="color: #2b91af">PexSymbolicValue</span>.Minimize(elementCount); <span style="color: #2b91af">PexAssume</span>.TrueForAll(
unions, u =&gt; 0 &lt;= u.Key &amp;&amp; u.Key &lt; elementCount &amp;&amp; 0 &lt;=
u.Value &amp;&amp; u.Value &lt; elementCount );</pre>
        </blockquote>
        <p>
Now that we have some data, we can start writing the first part of the scenario: filling
the disjoint-set. To do so, we simply add the integers from <em>[0..elementCount)</em>.
Along the way, we check that the <em>Contains,</em><em>ElementCount</em>, <em>SetCount</em> all
behave as expected:
</p>
        <blockquote>
          <pre class="code">
            <span style="color: blue">
              <font color="#000000">
              </font>var </span>target
= <span style="color: blue">new </span><span style="color: #2b91af">ForestDisjointSet</span>&lt;<span style="color: blue">int</span>&gt;(); <span style="color: green">//
fill up with 0..elementCount - 1 </span><span style="color: blue">for </span>(<span style="color: blue">int </span>i
= 0; i &lt; elementCount; i++) { target.MakeSet(i); <span style="color: #2b91af">Assert</span>.IsTrue(target.Contains(i)); <span style="color: #2b91af">Assert</span>.AreEqual(i
+ 1, target.ElementCount); <span style="color: #2b91af">Assert</span>.AreEqual(i +
1, target.SetCount); }</pre>
        </blockquote>
        <p>
The second part gets more interesting. Each element of the unions array is a ‘union’
action between 2 elements:
</p>
        <blockquote>
          <pre class="code">
            <span style="color: green">
              <font color="#000000">
              </font>//
apply Union for pairs unions[i], unions[i+1] </span>
            <span style="color: blue">for </span>(<span style="color: blue">int </span>i
= 0; i &lt; unions.Length; i++) { <span style="color: blue">var </span>left = unions[i].Key; <span style="color: blue">var </span>right=
unions[i].Value; <span style="color: blue">var </span>setCount = target.SetCount; <span style="color: blue">bool </span>unioned
= target.Union(left, right);</pre>
        </blockquote>
        <p>
There is 2 things we want to assert here: first, then left and right now belong to
the same set. Secondly, that the <em>SetCount</em> has been updated correctly: if <em>unioned</em> is
true, it should have decreased by one.
</p>
        <blockquote>
          <p>
        <span style="color: green">// should be
in the same set now<br />
       </span><span style="color: #2b91af">Assert</span>.IsTrue(target.AreInSameSet(left,
right));<br />
        <span style="color: green">// if unioned,
the count decreased by 1<br />
       </span><span style="color: #2b91af">PexAssert</span>.ImpliesIsTrue(unioned,
() =&gt; setCount - 1 == target.SetCount);<br />
    }<br />
}
</p>
        </blockquote>
        <p>
From this parameterized unit test, I could work on the implementation, and refine
again and again until it had all passing tests (I did not write <strong>any</strong> other
test code)<strong>.</strong> 
</p>
        <p>
          <strong>Happy Ending</strong>
        </p>
        <p>
The resulting test suite generated by Pex is summarized in the screenshot below: the
number of elements does not really matter, what is interesting is the sequence of
unions performed. This test suite achieves 100% coverage of the methods under test
:).
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/images/DisjointSetclassinC_8E4B/image.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/images/DisjointSetclassinC_8E4B/image_thumb.png" width="458" height="287" />
          </a>
        </p>
        <p>
In fact, the <em>Union</em> method involved some tricky branches to cover, due to
some optimization occurring in the disjoint-set. Pex managed to generate unit tests
for each of the branches. 
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/images/DisjointSetclassinC_8E4B/image_3.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/images/DisjointSetclassinC_8E4B/image_thumb_3.png" width="369" height="273" />
          </a>
        </p>
        <p>
        </p>
        <p>
          <strong>Thanks to the contracts, the test assertions, and the high code coverage of
the generated test suite, I have now a good confidence that my code is properly tested. </strong>The
End!
</p>
        <p>
(Next time, we will talk about testing minimum spanning tree implementations…)
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=06a6b1c8-6cc3-4728-9791-c129619219eb" />
      </body>
      <title>Writing a DisjointSet in C# with the help of Code Contracts and Pex.</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,06a6b1c8-6cc3-4728-9791-c129619219eb.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/ayyvQkZnhjs/WritingADisjointSetInCWithTheHelpOfCodeContractsAndPex.aspx</link>
      <pubDate>Tue, 30 Dec 2008 19:41:45 GMT</pubDate>
      <description>&lt;p&gt;
I recently implemented a &lt;a target="_blank" href="http://en.wikipedia.org/wiki/Disjoint-set_data_structure"&gt;Disjoint-Set&lt;/a&gt; data
structure in &lt;a target="_blank" href="http://www.codeplex.com/quickgraph"&gt;QuickGraph&lt;/a&gt;,
which is the main building block of the &lt;a target="_blank" href="http://en.wikipedia.org/wiki/Kruskal%27s_algorithm"&gt;Kruskal’s
minimum spanning tree algorithm&lt;/a&gt;. This is a fun data-structure to look at, as it
purpose is quite different from the ‘main’ BCL collections. The disjoint-set is useful
to partition elements into sets, and defines 2 main operation to that purpose: &lt;em&gt;Find&lt;/em&gt;,
finds the set an element belongs to (can be used to check if 2 elements are in the
same set), &lt;em&gt;Union&lt;/em&gt; merges two sets.
&lt;/p&gt;
&lt;p&gt;
The &lt;a target="_blank" href="http://www.codeplex.com/quickgraph/SourceControl/changeset/view/29499#343829"&gt;source
of the disjoint-set&lt;/a&gt; is in the QuickGraph source, if you are curious about the
details.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Testing the disjoint-set&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
There is not much left to TDD when it comes to write data structure. Such data structure
are usually described in details in an article, and you ‘just’ have to follow the
authors instruction to implement. Nevertheless, unit testing is really critical to
ensure that the implementation is correct – but there is a risk of having to re-implement
the algorithm to test it. 
&lt;/p&gt;
&lt;p&gt;
For the disjoint-set, I used 2 tools developed at &lt;a target="_blank" href="http://research.microsoft.com/rise"&gt;RiSE&lt;/a&gt;: &lt;a target="_blank" href="http://research.microsoft.com/contracts"&gt;Code
Contracts&lt;/a&gt; and… &lt;a target="_blank" href="http://research.microsoft.com/pex"&gt;Pex&lt;/a&gt;.
When implementing data structure from the literature, I usually start ‘dumping’ the
code and the contracts. As much as possible, any invariant or property that the author
describes should be translated to contracts. It will give more opportunities for Pex
to find bugs in my code.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Contracts First&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
For example, the contracts for the &lt;strong&gt;Union&lt;/strong&gt; method look as follows:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private bool &lt;/span&gt;Union(&lt;span style="color: #2b91af"&gt;Element &lt;/span&gt;left, &lt;span style="color: #2b91af"&gt;Element &lt;/span&gt;right)
{ &lt;span style="color: #2b91af"&gt;Contract&lt;/span&gt;.Requires(left != &lt;span style="color: blue"&gt;null&lt;/span&gt;); &lt;span style="color: #2b91af"&gt;Contract&lt;/span&gt;.Requires(right
!= &lt;span style="color: blue"&gt;null&lt;/span&gt;); &lt;span style="color: #2b91af"&gt;Contract&lt;/span&gt;.Ensures(&lt;span style="color: #2b91af"&gt;Contract&lt;/span&gt;.Result&amp;lt;&lt;span style="color: blue"&gt;bool&lt;/span&gt;&amp;gt;()
? &lt;span style="color: #2b91af"&gt;Contract&lt;/span&gt;.OldValue(&lt;span style="color: blue"&gt;this&lt;/span&gt;.SetCount)
- 1 == &lt;span style="color: blue"&gt;this&lt;/span&gt;.SetCount : &lt;span style="color: #2b91af"&gt;Contract&lt;/span&gt;.OldValue(&lt;span style="color: blue"&gt;this&lt;/span&gt;.SetCount)
== &lt;span style="color: blue"&gt;this&lt;/span&gt;.SetCount ); &lt;span style="color: #2b91af"&gt;Contract&lt;/span&gt;.Ensures(&lt;span style="color: blue"&gt;this&lt;/span&gt;.FindNoCompression(left)
== &lt;span style="color: blue"&gt;this&lt;/span&gt;.FindNoCompression(right)); &lt;/pre&gt;&lt;/blockquote&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
The two first requires clauses do the usual null checks. The first ensures clause
checks that if &lt;em&gt;Union&lt;/em&gt; returns true, a merge has been done and the number of
sets has decreased by 1. The last ensures checks that left and right belong to the
same set at the end of the union. 
&lt;/p&gt;
&lt;p&gt;
Note that so far, I did not have to provide any kind of implementation details. The
other methods in the implementation receive the same treatment.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;A Parameterized Unit Test&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
I wrote a single parameterized unit test while writing/debugging the implementation
of the forest. It could probably have been re-factored into many smaller tests, but
for the sake of laziness, I used a single one.
&lt;/p&gt;
&lt;p&gt;
The parameterized unit test implement a common scenario: add elements to the disjoint-set,
then apply a bunch of union operations. Along the way, we can rely on test assertion
and code contracts to check the correctness of our implementation.
&lt;/p&gt;
&lt;p&gt;
Let’s start with the test method signature:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;PexMethod&lt;/span&gt;] &lt;span style="color: blue"&gt;public
void &lt;/span&gt;Unions(&lt;span style="color: blue"&gt;int &lt;/span&gt;elementCount, [&lt;span style="color: #2b91af"&gt;PexAssumeNotNull&lt;/span&gt;]&lt;span style="color: #2b91af"&gt;KeyValuePair&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;,&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;[]
unions) {&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
The test takes a number of element to add and a sequence of unions to apply. The input
data as is needs to be refined to be useful. In that sense, we add &lt;strong&gt;assumptions&lt;/strong&gt;,
under the form of calls to &lt;em&gt;PexAssume&lt;/em&gt;, to tell Pex ‘how it should shape’ the
input data. In this case, we want to ensure that &lt;em&gt;elementCount&lt;/em&gt; is positive
and relatively small; and that the values in unions are within the &lt;em&gt;[0…elementCount)&lt;/em&gt; range.
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;&lt;font color="#000000"&gt; &lt;/font&gt;PexAssume&lt;/span&gt;.IsTrue(0
&amp;lt; elementCount); &lt;span style="color: #2b91af"&gt;PexSymbolicValue&lt;/span&gt;.Minimize(elementCount); &lt;span style="color: #2b91af"&gt;PexAssume&lt;/span&gt;.TrueForAll(
unions, u =&amp;gt; 0 &amp;lt;= u.Key &amp;amp;&amp;amp; u.Key &amp;lt; elementCount &amp;amp;&amp;amp; 0 &amp;lt;=
u.Value &amp;amp;&amp;amp; u.Value &amp;lt; elementCount );&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
Now that we have some data, we can start writing the first part of the scenario: filling
the disjoint-set. To do so, we simply add the integers from &lt;em&gt;[0..elementCount)&lt;/em&gt;.
Along the way, we check that the &lt;em&gt;Contains,&lt;/em&gt; &lt;em&gt;ElementCount&lt;/em&gt;, &lt;em&gt;SetCount&lt;/em&gt; all
behave as expected:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&lt;font color="#000000"&gt; &lt;/font&gt;var &lt;/span&gt;target
= &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ForestDisjointSet&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;(); &lt;span style="color: green"&gt;//
fill up with 0..elementCount - 1 &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;int &lt;/span&gt;i
= 0; i &amp;lt; elementCount; i++) { target.MakeSet(i); &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.IsTrue(target.Contains(i)); &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.AreEqual(i
+ 1, target.ElementCount); &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.AreEqual(i +
1, target.SetCount); }&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
The second part gets more interesting. Each element of the unions array is a ‘union’
action between 2 elements:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="code"&gt;&lt;span style="color: green"&gt;&lt;font color="#000000"&gt; &lt;/font&gt;//
apply Union for pairs unions[i], unions[i+1] &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;int &lt;/span&gt;i
= 0; i &amp;lt; unions.Length; i++) { &lt;span style="color: blue"&gt;var &lt;/span&gt;left = unions[i].Key; &lt;span style="color: blue"&gt;var &lt;/span&gt;right=
unions[i].Value; &lt;span style="color: blue"&gt;var &lt;/span&gt;setCount = target.SetCount; &lt;span style="color: blue"&gt;bool &lt;/span&gt;unioned
= target.Union(left, right);&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
There is 2 things we want to assert here: first, then left and right now belong to
the same set. Secondly, that the &lt;em&gt;SetCount&lt;/em&gt; has been updated correctly: if &lt;em&gt;unioned&lt;/em&gt; is
true, it should have decreased by one.
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green"&gt;// should be
in the same set now&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.IsTrue(target.AreInSameSet(left,
right));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green"&gt;// if unioned,
the count decreased by 1&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: #2b91af"&gt;PexAssert&lt;/span&gt;.ImpliesIsTrue(unioned,
() =&amp;gt; setCount - 1 == target.SetCount);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
}
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
From this parameterized unit test, I could work on the implementation, and refine
again and again until it had all passing tests (I did not write &lt;strong&gt;any&lt;/strong&gt; other
test code)&lt;strong&gt;.&lt;/strong&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Happy Ending&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
The resulting test suite generated by Pex is summarized in the screenshot below: the
number of elements does not really matter, what is interesting is the sequence of
unions performed. This test suite achieves 100% coverage of the methods under test
:).
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/images/DisjointSetclassinC_8E4B/image.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/images/DisjointSetclassinC_8E4B/image_thumb.png" width="458" height="287"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
In fact, the &lt;em&gt;Union&lt;/em&gt; method involved some tricky branches to cover, due to
some optimization occurring in the disjoint-set. Pex managed to generate unit tests
for each of the branches. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/images/DisjointSetclassinC_8E4B/image_3.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/images/DisjointSetclassinC_8E4B/image_thumb_3.png" width="369" height="273"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Thanks to the contracts, the test assertions, and the high code coverage of
the generated test suite, I have now a good confidence that my code is properly tested. &lt;/strong&gt;The
End!
&lt;/p&gt;
&lt;p&gt;
(Next time, we will talk about testing minimum spanning tree implementations…)
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=06a6b1c8-6cc3-4728-9791-c129619219eb" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,06a6b1c8-6cc3-4728-9791-c129619219eb.aspx</comments>
      <category>Pex</category>
      <category>QuickGraph</category>
      <category>Testing</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2008/12/30/WritingADisjointSetInCWithTheHelpOfCodeContractsAndPex.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=8f4d7c0c-d999-4374-aa1c-c7273db0e971</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,8f4d7c0c-d999-4374-aa1c-c7273db0e971.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,8f4d7c0c-d999-4374-aa1c-c7273db0e971.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=8f4d7c0c-d999-4374-aa1c-c7273db0e971</wfw:commentRss>
      <slash:comments>7</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p align="left">
My second son <strong>Emile de Halleux</strong> was born on Monday with 4.204g and
lots of hair. He and his mother are enjoying a nice hot fire while the winter storm
is slamming Seattle (glad he decided to come out<em> before </em>the icy mess). Happy
Holidays!
</p>
        <p align="left">
          <a href="http://www.flickr.com/photos/pelionore/3111504285/">
            <img alt="" src="http://farm4.static.flickr.com/3185/3111504285_54b448b25b.jpg" />
          </a>
        </p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=8f4d7c0c-d999-4374-aa1c-c7273db0e971" />
      </body>
      <title>Welcome Emile de Halleux</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,8f4d7c0c-d999-4374-aa1c-c7273db0e971.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/q-Y5L7TsO-s/WelcomeEmileDeHalleux.aspx</link>
      <pubDate>Fri, 19 Dec 2008 00:19:09 GMT</pubDate>
      <description>&lt;p align="left"&gt;
My second son &lt;strong&gt;Emile de Halleux&lt;/strong&gt; was born on Monday with 4.204g and
lots of hair. He and his mother are enjoying a nice hot fire while the winter storm
is slamming Seattle (glad he decided to come out&lt;em&gt; before &lt;/em&gt;the icy mess). Happy
Holidays!
&lt;/p&gt;
&lt;p align="left"&gt;
&lt;a href="http://www.flickr.com/photos/pelionore/3111504285/"&gt;&lt;img alt="" src="http://farm4.static.flickr.com/3185/3111504285_54b448b25b.jpg"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=8f4d7c0c-d999-4374-aa1c-c7273db0e971" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,8f4d7c0c-d999-4374-aa1c-c7273db0e971.aspx</comments>
      <category>Personal</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2008/12/19/WelcomeEmileDeHalleux.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=23babb8f-9c26-41d1-ae6c-b8349e214fcb</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,23babb8f-9c26-41d1-ae6c-b8349e214fcb.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,23babb8f-9c26-41d1-ae6c-b8349e214fcb.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=23babb8f-9c26-41d1-ae6c-b8349e214fcb</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I just <a target="_blank" href="http://www.codeplex.com/quickgraph/Release/ProjectReleases.aspx?ReleaseId=20160">released
a new version</a> of <a target="_blank" href="http://www.codeplex.com/quickgraph">QuickGraph</a>.
Among many small improvements here and there, the big news are:
</p>
        <ul>
          <li>
.net 2.0 support is back! QuickGraph now builds both for .net 2.0 and .net 3.5 (with
extension methods).</li>
          <li>
The Dijkstra algorithm use a Fibonacci Heap under the hood, which is way more efficient.
Courtesy of Roy Williams!</li>
          <li>
better serialization support and other bug fixes.</li>
        </ul>
        <p>
Enjoy, Peli.
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=23babb8f-9c26-41d1-ae6c-b8349e214fcb" />
      </body>
      <title>QuickGraph 3.1 &amp;ndash; .net 2.0 support &amp;ndash; Fibonacci Heap</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,23babb8f-9c26-41d1-ae6c-b8349e214fcb.aspx</guid>
      <link>http://feedproxy.google.com/~r/PelisFarm/~3/IwCyToPHKJQ/QuickGraph31NdashNet20SupportNdashFibonacciHeap.aspx</link>
      <pubDate>Thu, 04 Dec 2008 08:28:30 GMT</pubDate>
      <description>&lt;p&gt;
I just &lt;a target="_blank" href="http://www.codeplex.com/quickgraph/Release/ProjectReleases.aspx?ReleaseId=20160"&gt;released
a new version&lt;/a&gt; of &lt;a target="_blank" href="http://www.codeplex.com/quickgraph"&gt;QuickGraph&lt;/a&gt;.
Among many small improvements here and there, the big news are:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
.net 2.0 support is back! QuickGraph now builds both for .net 2.0 and .net 3.5 (with
extension methods).&lt;/li&gt;
&lt;li&gt;
The Dijkstra algorithm use a Fibonacci Heap under the hood, which is way more efficient.
Courtesy of Roy Williams!&lt;/li&gt;
&lt;li&gt;
better serialization support and other bug fixes.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Enjoy, Peli.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=23babb8f-9c26-41d1-ae6c-b8349e214fcb" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,23babb8f-9c26-41d1-ae6c-b8349e214fcb.aspx</comments>
      <category>QuickGraph</category>
    <feedburner:origLink>http://blog.dotnetwiki.org/2008/12/04/QuickGraph31NdashNet20SupportNdashFibonacciHeap.aspx</feedburner:origLink></item>
  </channel>
</rss>
