<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" version="2.0">
  <channel>
    <title>Eleutian SpeakENG Development Blog - frameworks</title>
    <link>http://blog.eleutian.com/</link>
    <description />
    <language>en-us</language>
    <copyright>Eleutian Technology</copyright>
    <lastBuildDate>Tue, 02 Sep 2008 21:49:51 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>aaron@eleutian.com</managingEditor>
    <webMaster>aaron@eleutian.com</webMaster>
    <item>
      <trackback:ping>http://blog.eleutian.com/Trackback.aspx?guid=ff788dca-fce2-4ad7-856d-c1a7745a2517</trackback:ping>
      <pingback:server>http://blog.eleutian.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.eleutian.com/PermaLink,guid,ff788dca-fce2-4ad7-856d-c1a7745a2517.aspx</pingback:target>
      <dc:creator>Aaron</dc:creator>
      <wfw:comment>http://blog.eleutian.com/CommentView,guid,ff788dca-fce2-4ad7-856d-c1a7745a2517.aspx</wfw:comment>
      <wfw:commentRss>http://blog.eleutian.com/SyndicationService.asmx/GetEntryCommentsRss?guid=ff788dca-fce2-4ad7-856d-c1a7745a2517</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
It's been a while, but we've gotten several new things into Machine.Specifications
(MSpec). I'm excited to finally release them for everyone to start playing with. You
can grab the bits <a href="http://www.assembla.com/spaces/machine/documents/aNW0n0Etir3yXNab7jnrAJ/download/mspec-0.2.zip">here</a>.
</p>
        <p>
Let's talk about what's new though. Here's an example of a new context/spec:
</p>
        <pre class="c-sharp" name="code">  [Concern("Console runner")]
  public class when_specifying_a_missing_assembly_on_the_command_line
  {
    Establish context = ()=&gt;
    {
      console = new FakeConsole();
      program = new Program(console);
    };

    Because of = ()=&gt;
      exitCode = program.Run(new string[] {missingAssemblyName});

    It should_output_an_error_message_with_the_name_of_the_missing_assembly = ()=&gt;
      console.Lines.ShouldContain(string.Format(Resources.MissingAssemblyError, 
      missingAssemblyName));

    It should_return_the_Error_exit_code = ()=&gt;
      exitCode.ShouldEqual(ExitCode.Error);

    const string missingAssemblyName = "Some.Missing.Assembly.dll";
    public static ExitCode exitCode;
    public static Program program;
    public static FakeConsole console;
  }
</pre>
        <p>
          <strong>There have been a few semantic changes</strong>
        </p>
        <ul>
          <li>
The Description attribute has been removed. There is now an optional Concern attribute
that allows you to specify a type and/or a string that the context/spec is concerned
with. 
</li>
          <li>
            <strong>Context before_each</strong> is now <strong>Establish context</strong>. 
</li>
          <li>
            <strong>Context before_all</strong> is now <strong>Establish context_once</strong>. 
</li>
          <li>
            <strong>Context after_each </strong>is now <strong>Cleanup after_each</strong>. 
</li>
          <li>
            <strong>Context after_all</strong> is now <strong>Cleanup after_each</strong>. 
</li>
          <li>
            <strong>When {...}</strong> is now <strong>Because of</strong>. This is closer to
SpecUnit.NET's verbage, and doesn't force you to specify the "when" twice. 
</li>
        </ul>
        <p>
          <strong>There is now a console runner</strong>
        </p>
        <p>
We don't quite have all the options we want yet, but the basics of the runner are
working. Here's the help from the runner:
</p>
        <img height="163" src="http://content.screencast.com/users/ajensen/folders/Jing/media/0b6d7837-d45c-4124-93f7-38bc37a7fa7b/2008-09-02_1429.png" width="588" border="0" />
        <p>
We also stole Bellware's SpecUnit.NET reporting stuff and ported it over. You can
now generate a report on your specs with the --html 
<file.html>
switch. Here's an example run:
</file.html></p>
        <img height="355" src="http://content.screencast.com/users/ajensen/folders/Jing/media/aef95516-cf4e-4df0-b428-a890624abcfe/2008-09-02_1436.png" width="588" border="0" />
        <p>
          <a href="http://blog.eleutian.com/download/mspec-0.2run.html">This is the report it
generates.</a>
        </p>
        <p>
Want to try it out?
</p>
        <ol>
          <li>
Grab the drop <a href="http://www.assembla.com/spaces/machine/documents/aNW0n0Etir3yXNab7jnrAJ/download/mspec-0.2.zip">here</a>. 
</li>
          <li>
Extract it somewhere. Put it somewhere semi-permanent because the <a href="http://testdriven.net/">TestDriven.NET</a> runner
will need a static location for the MSpec TDNet Runner. 
</li>
          <li>
If you want TestDriven.NET support, run <strong>InstallTDNetRunner.bat</strong></li>
          <li>
Check out the example in <strong>Machine.Specifications.Example</strong>. Note that
you can run with TD.NET. 
</li>
          <li>
Create a project of your own. Just add <strong>Machine.Specifications.dll</strong> and
get started. 
</li>
          <li>
Send me feedback! Leave comments, email me, <a href="http://twitter.com/aaronjensen">tweet
me</a>, whatever. 
</li>
        </ol>
        <p>
Also, this is part of <a href="http://www.assembla.com/wiki/show/machine">Machine</a>,
so feel free to take a <a href="http://svn2.assembla.com/svn/machine/trunk/">look
at the code</a> and/or submit patches. There's also a <a href="http://www.gallio.org/">Gallio</a> adapter
in there, but I didn't include it in the release as it's not quite polished enough
yet. If you're interested in it, talk to me. Special thanks to <a href="http://twitter.com/sbellware">Scott
Bellware</a>, <a href="http://blog.bits-in-motion.com/">Jeff Brown</a> and <a href="http://weblogs.asp.net/nunitaddin/default.aspx">Jamie
Cansdale</a> for their help and support. Also, extra special thanks to Eleutian's
newest dev, Jeff Olson for much of the recent work that has gone into MSpec!
</p>
        <img width="0" height="0" src="http://blog.eleutian.com/aggbug.ashx?id=ff788dca-fce2-4ad7-856d-c1a7745a2517" />
      </body>
      <title>MSpec v0.2</title>
      <guid isPermaLink="false">http://blog.eleutian.com/PermaLink,guid,ff788dca-fce2-4ad7-856d-c1a7745a2517.aspx</guid>
      <link>http://blog.eleutian.com/2008/09/02/MSpecV02.aspx</link>
      <pubDate>Tue, 02 Sep 2008 21:49:51 GMT</pubDate>
      <description>&lt;p&gt;
It's been a while, but we've gotten several new things into Machine.Specifications
(MSpec). I'm excited to finally release them for everyone to start playing with. You
can grab the bits &lt;a href="http://www.assembla.com/spaces/machine/documents/aNW0n0Etir3yXNab7jnrAJ/download/mspec-0.2.zip"&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Let's talk about what's new though. Here's an example of a new context/spec:
&lt;/p&gt;
&lt;pre class="c-sharp" name="code"&gt;  [Concern("Console runner")]
  public class when_specifying_a_missing_assembly_on_the_command_line
  {
    Establish context = ()=&amp;gt;
    {
      console = new FakeConsole();
      program = new Program(console);
    };

    Because of = ()=&amp;gt;
      exitCode = program.Run(new string[] {missingAssemblyName});

    It should_output_an_error_message_with_the_name_of_the_missing_assembly = ()=&amp;gt;
      console.Lines.ShouldContain(string.Format(Resources.MissingAssemblyError, 
      missingAssemblyName));

    It should_return_the_Error_exit_code = ()=&amp;gt;
      exitCode.ShouldEqual(ExitCode.Error);

    const string missingAssemblyName = "Some.Missing.Assembly.dll";
    public static ExitCode exitCode;
    public static Program program;
    public static FakeConsole console;
  }
&lt;/pre&gt;
&lt;p&gt;
&lt;strong&gt;There have been a few semantic changes&lt;/strong&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
The Description attribute has been removed. There is now an optional Concern attribute
that allows you to specify a type and/or a string that the context/spec is concerned
with. 
&lt;li&gt;
&lt;strong&gt;Context before_each&lt;/strong&gt; is now &lt;strong&gt;Establish context&lt;/strong&gt;. 
&lt;li&gt;
&lt;strong&gt;Context before_all&lt;/strong&gt; is now &lt;strong&gt;Establish context_once&lt;/strong&gt;. 
&lt;li&gt;
&lt;strong&gt;Context after_each &lt;/strong&gt;is now &lt;strong&gt;Cleanup after_each&lt;/strong&gt;. 
&lt;li&gt;
&lt;strong&gt;Context after_all&lt;/strong&gt; is now &lt;strong&gt;Cleanup after_each&lt;/strong&gt;. 
&lt;li&gt;
&lt;strong&gt;When {...}&lt;/strong&gt; is now &lt;strong&gt;Because of&lt;/strong&gt;. This is closer to
SpecUnit.NET's verbage, and doesn't force you to specify the "when" twice. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;strong&gt;There is now a console runner&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
We don't quite have all the options we want yet, but the basics of the runner are
working. Here's the help from the runner:
&lt;/p&gt;
&lt;img height="163" src="http://content.screencast.com/users/ajensen/folders/Jing/media/0b6d7837-d45c-4124-93f7-38bc37a7fa7b/2008-09-02_1429.png" width="588" border="0"&gt; 
&lt;p&gt;
We also stole Bellware's SpecUnit.NET reporting stuff and ported it over. You can
now generate a report on your specs with the --html 
&lt;file.html&gt;
switch. Here's an example run:
&lt;/p&gt;
&lt;img height="355" src="http://content.screencast.com/users/ajensen/folders/Jing/media/aef95516-cf4e-4df0-b428-a890624abcfe/2008-09-02_1436.png" width="588" border="0"&gt; 
&lt;p&gt;
&lt;a href="http://blog.eleutian.com/download/mspec-0.2run.html"&gt;This is the report it
generates.&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Want to try it out?
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Grab the drop &lt;a href="http://www.assembla.com/spaces/machine/documents/aNW0n0Etir3yXNab7jnrAJ/download/mspec-0.2.zip"&gt;here&lt;/a&gt;. 
&lt;li&gt;
Extract it somewhere. Put it somewhere semi-permanent because the &lt;a href="http://testdriven.net/"&gt;TestDriven.NET&lt;/a&gt; runner
will need a static location for the MSpec TDNet Runner. 
&lt;li&gt;
If you want TestDriven.NET support, run &lt;strong&gt;InstallTDNetRunner.bat&lt;/strong&gt; 
&lt;li&gt;
Check out the example in &lt;strong&gt;Machine.Specifications.Example&lt;/strong&gt;. Note that
you can run with TD.NET. 
&lt;li&gt;
Create a project of your own. Just add &lt;strong&gt;Machine.Specifications.dll&lt;/strong&gt; and
get started. 
&lt;li&gt;
Send me feedback! Leave comments, email me, &lt;a href="http://twitter.com/aaronjensen"&gt;tweet
me&lt;/a&gt;, whatever. 
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
Also, this is part of &lt;a href="http://www.assembla.com/wiki/show/machine"&gt;Machine&lt;/a&gt;,
so feel free to take a &lt;a href="http://svn2.assembla.com/svn/machine/trunk/"&gt;look
at the code&lt;/a&gt; and/or submit patches. There's also a &lt;a href="http://www.gallio.org/"&gt;Gallio&lt;/a&gt; adapter
in there, but I didn't include it in the release as it's not quite polished enough
yet. If you're interested in it, talk to me. Special thanks to &lt;a href="http://twitter.com/sbellware"&gt;Scott
Bellware&lt;/a&gt;, &lt;a href="http://blog.bits-in-motion.com/"&gt;Jeff Brown&lt;/a&gt; and &lt;a href="http://weblogs.asp.net/nunitaddin/default.aspx"&gt;Jamie
Cansdale&lt;/a&gt; for their help and support. Also, extra special thanks to Eleutian's
newest dev, Jeff Olson for much of the recent work that has gone into MSpec!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.eleutian.com/aggbug.ashx?id=ff788dca-fce2-4ad7-856d-c1a7745a2517" /&gt;</description>
      <comments>http://blog.eleutian.com/CommentView,guid,ff788dca-fce2-4ad7-856d-c1a7745a2517.aspx</comments>
      <category>bdd</category>
      <category>frameworks</category>
    </item>
    <item>
      <trackback:ping>http://blog.eleutian.com/Trackback.aspx?guid=b9a23177-84da-4932-894c-877f59e8ca0f</trackback:ping>
      <pingback:server>http://blog.eleutian.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.eleutian.com/PermaLink,guid,b9a23177-84da-4932-894c-877f59e8ca0f.aspx</pingback:target>
      <dc:creator>Aaron</dc:creator>
      <wfw:comment>http://blog.eleutian.com/CommentView,guid,b9a23177-84da-4932-894c-877f59e8ca0f.aspx</wfw:comment>
      <wfw:commentRss>http://blog.eleutian.com/SyndicationService.asmx/GetEntryCommentsRss?guid=b9a23177-84da-4932-894c-877f59e8ca0f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Just wanted to quickly note that I tracked down the performance issue in Rhino.Mocks
and <a href="http://rhino-tools.svn.sourceforge.net/viewvc/rhino-tools?view=rev&amp;revision=1382">patched
it</a>. I also updated the <a href="http://blog.eleutian.com/2008/05/08/MockFrameworkBenchmarks.aspx">original
post</a> with the new numbers. Enjoy!
</p>
        <img width="0" height="0" src="http://blog.eleutian.com/aggbug.ashx?id=b9a23177-84da-4932-894c-877f59e8ca0f" />
      </body>
      <title>Rhino.Mocks Performance Issue Fixed</title>
      <guid isPermaLink="false">http://blog.eleutian.com/PermaLink,guid,b9a23177-84da-4932-894c-877f59e8ca0f.aspx</guid>
      <link>http://blog.eleutian.com/2008/05/09/RhinoMocksPerformanceIssueFixed.aspx</link>
      <pubDate>Fri, 09 May 2008 05:56:48 GMT</pubDate>
      <description>&lt;p&gt;
Just wanted to quickly note that I tracked down the performance issue in Rhino.Mocks
and &lt;a href="http://rhino-tools.svn.sourceforge.net/viewvc/rhino-tools?view=rev&amp;amp;revision=1382"&gt;patched
it&lt;/a&gt;. I also updated the &lt;a href="http://blog.eleutian.com/2008/05/08/MockFrameworkBenchmarks.aspx"&gt;original
post&lt;/a&gt; with the new numbers. Enjoy!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.eleutian.com/aggbug.ashx?id=b9a23177-84da-4932-894c-877f59e8ca0f" /&gt;</description>
      <comments>http://blog.eleutian.com/CommentView,guid,b9a23177-84da-4932-894c-877f59e8ca0f.aspx</comments>
      <category>development</category>
      <category>frameworks</category>
      <category>mocking</category>
    </item>
    <item>
      <trackback:ping>http://blog.eleutian.com/Trackback.aspx?guid=96b7cc98-7d7d-4aae-8734-42347fcf8464</trackback:ping>
      <pingback:server>http://blog.eleutian.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.eleutian.com/PermaLink,guid,96b7cc98-7d7d-4aae-8734-42347fcf8464.aspx</pingback:target>
      <dc:creator>Aaron</dc:creator>
      <wfw:comment>http://blog.eleutian.com/CommentView,guid,96b7cc98-7d7d-4aae-8734-42347fcf8464.aspx</wfw:comment>
      <wfw:commentRss>http://blog.eleutian.com/SyndicationService.asmx/GetEntryCommentsRss?guid=96b7cc98-7d7d-4aae-8734-42347fcf8464</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <strong>UPDATE: I tracked down the issue
and committed a patch to Rhino.Mocks. Rhino.Mocks is now much more competetive performance
wise, our CI build time nearly halved, and about 4 minutes out of 7 of our test time
has disappeared. New numbers below.</strong>
        <p>
I've complained before that <a href="http://blog.eleutian.com/2007/12/15/MockingIsSlow.aspx">Mocking
is Slow</a> but I never really dove further into it. Today I decided to actually compare
Rhino.Mocks to other mock frameworks on a pure performance basis to see if it was
a global problem. I timed 2000 unit tests across 100 classes with 20 tests each. The
results were a bit surprising:
</p>
        <table>
          <tbody>
            <tr>
              <th>
Framework</th>
              <th>
                <a href="http://testdriven.net/">TD.NET</a> Time</th>
              <th>
nunit-console Time</th>
            </tr>
            <tr>
              <td>
                <a href="http://www.ayende.com/projects/rhino-mocks.aspx">Rhino.Mocks</a> old trunk</td>
              <td>
57.36s</td>
              <td>
28.82s</td>
            </tr>
            <tr>
              <td>
                <a href="http://www.ayende.com/projects/rhino-mocks.aspx">Rhino.Mocks</a> new trunk</td>
              <td>
22.94s</td>
              <td>
7.59s</td>
            </tr>
            <tr>
              <td>
                <a href="http://code.google.com/p/moq/">Moq</a> trunk</td>
              <td>
18.30s</td>
              <td>
5.91s</td>
            </tr>
            <tr>
              <td>
                <a href="http://www.typemock.com/">TypeMock</a> 4.2.3 Reflective Mocks</td>
              <td>
15.36s</td>
              <td>
9.35s</td>
            </tr>
            <tr>
              <td>
                <a href="http://www.typemock.com/">TypeMock</a> 4.2.3 Natural Mocks</td>
              <td>
16.92s</td>
              <td>
9.56s</td>
            </tr>
          </tbody>
        </table>
        <p>
That's right, according to these tests, <a href="http://www.ayende.com/projects/rhino-mocks.aspx">Rhino.Mocks</a> is
at least 3 times slower than the other frameworks when under heavy load in TD.NET
and five times slower in the console according to these tests. It's also interesting
to note that <a href="http://www.typemock.com/">TypeMock</a> is faster than <a href="http://code.google.com/p/moq/">Moq</a> in
TD.NET, but slower in the console runner.
</p>
        <p>
While running the Rhino.Mocks tests it is very clear that there is a degrading performance
issue. All the other frameworks executed tests with a near constant speed per test,
but Rhino.Mocks slowed down noticeably about half way through.
</p>
        <p>
Please feel free to try it yourself, grab the project <a href="http://blog.eleutian.com/download/BenchMock.zip">here</a>.
You should be able to just run the 4 strategy .bat files (run-rhino, run-moq, run-tmock-reflective,
run-tmock-natural). Let me know if you find anything interesting.
</p>
        <img width="0" height="0" src="http://blog.eleutian.com/aggbug.ashx?id=96b7cc98-7d7d-4aae-8734-42347fcf8464" />
      </body>
      <title>Mock Framework Benchmarks</title>
      <guid isPermaLink="false">http://blog.eleutian.com/PermaLink,guid,96b7cc98-7d7d-4aae-8734-42347fcf8464.aspx</guid>
      <link>http://blog.eleutian.com/2008/05/08/MockFrameworkBenchmarks.aspx</link>
      <pubDate>Thu, 08 May 2008 15:52:30 GMT</pubDate>
      <description>&lt;strong&gt;UPDATE: I tracked down the issue and committed a patch to Rhino.Mocks. Rhino.Mocks
is now much more competetive performance wise, our CI build time nearly halved, and
about 4 minutes out of 7 of our test time has disappeared. New numbers below.&lt;/strong&gt; 
&lt;p&gt;
I've complained before that &lt;a href="http://blog.eleutian.com/2007/12/15/MockingIsSlow.aspx"&gt;Mocking
is Slow&lt;/a&gt; but I never really dove further into it. Today I decided to actually compare
Rhino.Mocks to other mock frameworks on a pure performance basis to see if it was
a global problem. I timed 2000 unit tests across 100 classes with 20 tests each. The
results were a bit surprising:
&lt;/p&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;th&gt;
Framework&lt;/th&gt;
&lt;th&gt;
&lt;a href="http://testdriven.net/"&gt;TD.NET&lt;/a&gt; Time&lt;/th&gt;
&lt;th&gt;
nunit-console Time&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="http://www.ayende.com/projects/rhino-mocks.aspx"&gt;Rhino.Mocks&lt;/a&gt; old trunk&lt;/td&gt;
&lt;td&gt;
57.36s&lt;/td&gt;
&lt;td&gt;
28.82s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="http://www.ayende.com/projects/rhino-mocks.aspx"&gt;Rhino.Mocks&lt;/a&gt; new trunk&lt;/td&gt;
&lt;td&gt;
22.94s&lt;/td&gt;
&lt;td&gt;
7.59s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="http://code.google.com/p/moq/"&gt;Moq&lt;/a&gt; trunk&lt;/td&gt;
&lt;td&gt;
18.30s&lt;/td&gt;
&lt;td&gt;
5.91s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="http://www.typemock.com/"&gt;TypeMock&lt;/a&gt; 4.2.3 Reflective Mocks&lt;/td&gt;
&lt;td&gt;
15.36s&lt;/td&gt;
&lt;td&gt;
9.35s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="http://www.typemock.com/"&gt;TypeMock&lt;/a&gt; 4.2.3 Natural Mocks&lt;/td&gt;
&lt;td&gt;
16.92s&lt;/td&gt;
&lt;td&gt;
9.56s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
That's right, according to these tests, &lt;a href="http://www.ayende.com/projects/rhino-mocks.aspx"&gt;Rhino.Mocks&lt;/a&gt; is
at least 3 times slower than the other frameworks when under heavy load in TD.NET
and five times slower in the console according to these tests. It's also interesting
to note that &lt;a href="http://www.typemock.com/"&gt;TypeMock&lt;/a&gt; is faster than &lt;a href="http://code.google.com/p/moq/"&gt;Moq&lt;/a&gt; in
TD.NET, but slower in the console runner.
&lt;/p&gt;
&lt;p&gt;
While running the Rhino.Mocks tests it is very clear that there is a degrading performance
issue. All the other frameworks executed tests with a near constant speed per test,
but Rhino.Mocks slowed down noticeably about half way through.
&lt;/p&gt;
&lt;p&gt;
Please feel free to try it yourself, grab the project &lt;a href="http://blog.eleutian.com/download/BenchMock.zip"&gt;here&lt;/a&gt;.
You should be able to just run the 4 strategy .bat files (run-rhino, run-moq, run-tmock-reflective,
run-tmock-natural). Let me know if you find anything interesting.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.eleutian.com/aggbug.ashx?id=96b7cc98-7d7d-4aae-8734-42347fcf8464" /&gt;</description>
      <comments>http://blog.eleutian.com/CommentView,guid,96b7cc98-7d7d-4aae-8734-42347fcf8464.aspx</comments>
      <category>development</category>
      <category>frameworks</category>
      <category>mocking</category>
    </item>
    <item>
      <trackback:ping>http://blog.eleutian.com/Trackback.aspx?guid=2e4f933f-e00c-445e-ab64-17bf9a64d96f</trackback:ping>
      <pingback:server>http://blog.eleutian.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.eleutian.com/PermaLink,guid,2e4f933f-e00c-445e-ab64-17bf9a64d96f.aspx</pingback:target>
      <dc:creator>Aaron</dc:creator>
      <wfw:comment>http://blog.eleutian.com/CommentView,guid,2e4f933f-e00c-445e-ab64-17bf9a64d96f.aspx</wfw:comment>
      <wfw:commentRss>http://blog.eleutian.com/SyndicationService.asmx/GetEntryCommentsRss?guid=2e4f933f-e00c-445e-ab64-17bf9a64d96f</wfw:commentRss>
      <slash:comments>8</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
As some of you who follow <a href="http://twitter.com/aaronjensen">me on twitter</a> know,
I've been working on Yet Another Context/Specification Framework as an experiment.
Yeah, I know we already have <a href="http://nspec.tigris.org/">NSpec</a> and <a href="http://nbehave.org/">NBehave</a>,
and they're great and all, but MSpec takes things on from a slightly different angle,
and it's just an experiment (for now). Here's a sample Description:
</p>
        <pre name="code">[Description]
public class Transferring_between_from_account_and_to_account
{
  static Account fromAccount;
  static Account toAccount;

  Context before_each =()=&gt;
  {
    fromAccount = new Account {Balance = 1m};
    toAccount = new Account {Balance = 1m};
  };
  
  When the_transfer_is_made =()=&gt;
  {
    fromAccount.Transfer(1m, toAccount);
  };
   
  It should_debit_the_from_account_by_the_amount_transferred =()=&gt;
  {
    fromAccount.Balance.ShouldEqual(0m);
  };

  It should_credit_the_to_account_by_the_amount_transferred =()=&gt;
  {
    toAccount.Balance.ShouldEqual(2m);
  };
}
</pre>
        <p>
And a TestDriven.NET run:
</p>
        <pre>------ Test started: Assembly: Machine.Specifications.Example.dll ------

Transferring between from account and to account
  When the transfer is made
    * It should debit the from account by the amount transferred
    * It should credit the to account by the amount transferred


2 passed, 0 failed, 0 skipped, took 0.79 seconds.
</pre>
        <br />
        <h3>Err, What?
</h3>
        <p>
Different eh? The idea was heavily inspired by <a href="http://twitter.com/sbellware">Scott
Bellware</a>'s SpecUnit.Net framework he showed at the ALT.NET conference. It also
took heavy cues from <a href="http://rspec.info/">RSpec</a> and my insanity. I realize
that the the code doesn't look much like C# code and I'm OK with that. Many have and
will ask why I don't just use Boo or RSpec w/ IronRuby eventually or even one of the
existing Context/Spec/BDD frameworks. Those are good questions, but my main motivations
are tooling and syntax. I enjoy the tooling I get in C# and I personally like the
syntax in this library considering the limitations imposed by C#.
</p>
        <h3>How's it work?
</h3>
        <p>
The simplest way to describe it is to compare it to a normal *Unit style testing framework: 
</p>
        <ul>
          <li>
Description = TestContext 
</li>
          <li>
Context before_each = SetUp 
</li>
          <li>
Context before_all = SetUpFixture 
</li>
          <li>
Context after_each = TearDown 
</li>
          <li>
Context after_all = TearDownFixture 
</li>
          <li>
When = Also SetUp, but happens after Context before_each 
</li>
          <li>
It = Test 
</li>
        </ul>
        <p>
Rather than methods and attributes, MSpec uses named delegates and anonymous functions.
The only reason for this is readability. You'll also notice that the fields used in
the context are static. This is necessary so that the anonymous functions in the field
initializers can access them. Probably the first thing you noticed is the =()=&gt;
construct. I won't mention the names that this was given on twitter, but I think it's
an acceptable thing to have to deal with in exchange for the cleanliness of the rest
of the syntax.
</p>
        <h3>Ok, you're crazy, but how do I try it?
</h3>
        <p>
First, this is a very rough cut. Everything is subject to change as we experiment
with the language. That said, here's how you play with it:
</p>
        <ol>
          <li>
Grab the drop <a href="http://blog.eleutian.com/download/mspec-0.1.zip">here</a>. 
</li>
          <li>
Extract it somewhere. Put it somewhere semi-permanent because the <a href="http://testdriven.net/">TestDriven.NET</a> runner
will need a static location for the MSpec TDNet Runner. 
</li>
          <li>
If you want TestDriven.NET support, run <strong>InstallTDNetRunner.bat</strong></li>
          <li>
Check out the example in <strong>Machine.Specifications.Example</strong>. Note that
you can run with TD.NET. 
</li>
          <li>
Create a project of your own. Just add <strong>Machine.Specifications.dll</strong> and
get started. 
</li>
          <li>
Send me feedback! Leave comments, email me, <a href="http://twitter.com/aaronjensen">tweet
me</a>, whatever. 
</li>
        </ol>
        <p>
Also, this is part of <a href="http://www.assembla.com/wiki/show/machine">Machine</a>,
so feel free to take a <a href="http://svn2.assembla.com/svn/machine/trunk/">look
at the code</a> and/or submit patches. There's also a <a href="http://www.gallio.org/">Gallio</a> adapter
in there, but I didn't include it in the release as it's not quite polished enough
yet. If you're interested in it, talk to me. Special thanks to <a href="http://twitter.com/sbellware">Scott
Bellware</a>, <a href="http://blog.bits-in-motion.com/">Jeff Brown</a> and <a href="http://weblogs.asp.net/nunitaddin/default.aspx">Jamie
Cansdale</a> for their help and support.
</p>
        <img width="0" height="0" src="http://blog.eleutian.com/aggbug.ashx?id=2e4f933f-e00c-445e-ab64-17bf9a64d96f" />
      </body>
      <title>Introducing Machine.Specifications (or MSpec for short)</title>
      <guid isPermaLink="false">http://blog.eleutian.com/PermaLink,guid,2e4f933f-e00c-445e-ab64-17bf9a64d96f.aspx</guid>
      <link>http://blog.eleutian.com/2008/05/08/IntroducingMachineSpecificationsOrMSpecForShort.aspx</link>
      <pubDate>Thu, 08 May 2008 07:11:27 GMT</pubDate>
      <description>&lt;p&gt;
As some of you who follow &lt;a href="http://twitter.com/aaronjensen"&gt;me on twitter&lt;/a&gt; know,
I've been working on Yet Another Context/Specification Framework as an experiment.
Yeah, I know we already have &lt;a href="http://nspec.tigris.org/"&gt;NSpec&lt;/a&gt; and &lt;a href="http://nbehave.org/"&gt;NBehave&lt;/a&gt;,
and they're great and all, but MSpec takes things on from a slightly different angle,
and it's just an experiment (for now). Here's a sample Description:
&lt;/p&gt;
&lt;pre name="code"&gt;[Description]
public class Transferring_between_from_account_and_to_account
{
  static Account fromAccount;
  static Account toAccount;

  Context before_each =()=&amp;gt;
  {
    fromAccount = new Account {Balance = 1m};
    toAccount = new Account {Balance = 1m};
  };
  
  When the_transfer_is_made =()=&amp;gt;
  {
    fromAccount.Transfer(1m, toAccount);
  };
   
  It should_debit_the_from_account_by_the_amount_transferred =()=&amp;gt;
  {
    fromAccount.Balance.ShouldEqual(0m);
  };

  It should_credit_the_to_account_by_the_amount_transferred =()=&amp;gt;
  {
    toAccount.Balance.ShouldEqual(2m);
  };
}
&lt;/pre&gt;
&lt;p&gt;
And a TestDriven.NET run:
&lt;/p&gt;
&lt;pre&gt;------ Test started: Assembly: Machine.Specifications.Example.dll ------

Transferring between from account and to account
  When the transfer is made
    * It should debit the from account by the amount transferred
    * It should credit the to account by the amount transferred


2 passed, 0 failed, 0 skipped, took 0.79 seconds.
&lt;/pre&gt;
&lt;br&gt;
&lt;h3&gt;Err, What?
&lt;/h3&gt;
&lt;p&gt;
Different eh? The idea was heavily inspired by &lt;a href="http://twitter.com/sbellware"&gt;Scott
Bellware&lt;/a&gt;'s SpecUnit.Net framework he showed at the ALT.NET conference. It also
took heavy cues from &lt;a href="http://rspec.info/"&gt;RSpec&lt;/a&gt; and my insanity. I realize
that the the code doesn't look much like C# code and I'm OK with that. Many have and
will ask why I don't just use Boo or RSpec w/ IronRuby eventually or even one of the
existing Context/Spec/BDD frameworks. Those are good questions, but my main motivations
are tooling and syntax. I enjoy the tooling I get in C# and I personally like the
syntax in this library considering the limitations imposed by C#.
&lt;/p&gt;
&lt;h3&gt;How's it work?
&lt;/h3&gt;
&lt;p&gt;
The simplest way to describe it is to compare it to a normal *Unit style testing framework: 
&lt;ul&gt;
&lt;li&gt;
Description = TestContext 
&lt;li&gt;
Context before_each = SetUp 
&lt;li&gt;
Context before_all = SetUpFixture 
&lt;li&gt;
Context after_each = TearDown 
&lt;li&gt;
Context after_all = TearDownFixture 
&lt;li&gt;
When = Also SetUp, but happens after Context before_each 
&lt;li&gt;
It = Test 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Rather than methods and attributes, MSpec uses named delegates and anonymous functions.
The only reason for this is readability. You'll also notice that the fields used in
the context are static. This is necessary so that the anonymous functions in the field
initializers can access them. Probably the first thing you noticed is the =()=&amp;gt;
construct. I won't mention the names that this was given on twitter, but I think it's
an acceptable thing to have to deal with in exchange for the cleanliness of the rest
of the syntax.
&lt;/p&gt;
&lt;h3&gt;Ok, you're crazy, but how do I try it?
&lt;/h3&gt;
&lt;p&gt;
First, this is a very rough cut. Everything is subject to change as we experiment
with the language. That said, here's how you play with it:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Grab the drop &lt;a href="http://blog.eleutian.com/download/mspec-0.1.zip"&gt;here&lt;/a&gt;. 
&lt;li&gt;
Extract it somewhere. Put it somewhere semi-permanent because the &lt;a href="http://testdriven.net/"&gt;TestDriven.NET&lt;/a&gt; runner
will need a static location for the MSpec TDNet Runner. 
&lt;li&gt;
If you want TestDriven.NET support, run &lt;strong&gt;InstallTDNetRunner.bat&lt;/strong&gt; 
&lt;li&gt;
Check out the example in &lt;strong&gt;Machine.Specifications.Example&lt;/strong&gt;. Note that
you can run with TD.NET. 
&lt;li&gt;
Create a project of your own. Just add &lt;strong&gt;Machine.Specifications.dll&lt;/strong&gt; and
get started. 
&lt;li&gt;
Send me feedback! Leave comments, email me, &lt;a href="http://twitter.com/aaronjensen"&gt;tweet
me&lt;/a&gt;, whatever. 
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
Also, this is part of &lt;a href="http://www.assembla.com/wiki/show/machine"&gt;Machine&lt;/a&gt;,
so feel free to take a &lt;a href="http://svn2.assembla.com/svn/machine/trunk/"&gt;look
at the code&lt;/a&gt; and/or submit patches. There's also a &lt;a href="http://www.gallio.org/"&gt;Gallio&lt;/a&gt; adapter
in there, but I didn't include it in the release as it's not quite polished enough
yet. If you're interested in it, talk to me. Special thanks to &lt;a href="http://twitter.com/sbellware"&gt;Scott
Bellware&lt;/a&gt;, &lt;a href="http://blog.bits-in-motion.com/"&gt;Jeff Brown&lt;/a&gt; and &lt;a href="http://weblogs.asp.net/nunitaddin/default.aspx"&gt;Jamie
Cansdale&lt;/a&gt; for their help and support.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.eleutian.com/aggbug.ashx?id=2e4f933f-e00c-445e-ab64-17bf9a64d96f" /&gt;</description>
      <comments>http://blog.eleutian.com/CommentView,guid,2e4f933f-e00c-445e-ab64-17bf9a64d96f.aspx</comments>
      <category>development</category>
      <category>frameworks</category>
      <category>open source</category>
      <category>test driven development</category>
    </item>
    <item>
      <trackback:ping>http://blog.eleutian.com/Trackback.aspx?guid=40a71cf3-47c7-49ac-bb9c-ab9074adf0d1</trackback:ping>
      <pingback:server>http://blog.eleutian.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.eleutian.com/PermaLink,guid,40a71cf3-47c7-49ac-bb9c-ab9074adf0d1.aspx</pingback:target>
      <dc:creator>Aaron</dc:creator>
      <wfw:comment>http://blog.eleutian.com/CommentView,guid,40a71cf3-47c7-49ac-bb9c-ab9074adf0d1.aspx</wfw:comment>
      <wfw:commentRss>http://blog.eleutian.com/SyndicationService.asmx/GetEntryCommentsRss?guid=40a71cf3-47c7-49ac-bb9c-ab9074adf0d1</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Currently in Rhino.Mocks, making mocks fire events and ensuring that an event on your
SUT was fired are both awkward and verbose at best. Here is an example of both things
at once:
</p>
        <pre class="c-sharp" name="code">[Test]
public void ViewFiresBeginDrag_Always_FiresChangedEvent()
{
  IEventRaiser raiser;
  bool eventFired = false;
  using (Record)
  {
    The&lt;ICardView&gt;().BeginDrag += null;
    raiser = LastCall.IgnoreArguments().GetEventRaiser();

    Target.Changed += (x,y) =&gt; eventFired = true;
  }

  using (Playback)
  {
    raiser.Raise(The&lt;ICardView&gt;(), EventArgs.Empty);
    Assert.IsTrue(eventFired);
  }
}</pre>
        <p>
Nice eh? First, is there a better way to do either of these things that I'm missing?
Please tell me if so. Next, if not, what can we do to clean this up?
</p>
        <p>
Well, Ayende and I <a href="http://www.ayende.com/Blog/archive/2007/06/09/Rhino-Mocks-Events-Twisting-the-Syntax.aspx">discussed
this</a> in the past and Ayende spiked it and <a href="http://www.ayende.com/Blog/archive/2007/06/23/Natural-Event-Syntax-for-Rhino-Mocks.aspx">asked
for feedback</a>. The feedback was mixed and for one reason or another it never made
it into Rhino.Mocks that I know of.
</p>
        <p>
Well, today while I was working on <a href="http://svn2.assembla.com/svn/machine/trunk/Machine.Testing/">Machine.Testing</a> and
another side project, I decided to give something else a shot. What I ended up with
is this:
</p>
        <pre class="c-sharp" name="code">[Test]
public void ViewFiresBeginDrag_Always_FiresChangedEvent()
{
  using (Record)
  {
    PrimeEventFiringOn&lt;ICardView&gt;(x =&gt; x.BeginDrag += null);
    Target.Changed += NewEventFireExpectation&lt;EventHandler&gt;();
  }

  using (Playback)
  {
    FireEventOn&lt;ICardView&gt;(EventArgs.Empty);
  }
}</pre>
        <p>
Better, but I still don't think it's perfect. Also, it probably requires some explanation,
so let's pick it apart piece by piece:
</p>
        <pre class="c-sharp" name="code">    PrimeEventFiringOn&lt;ICardView&gt;(x =&gt; x.BeginDrag += null);</pre>
        <p>
=&gt; +=??? Ugly huh? I really wish we could just refer to an event somehow without
having to do +=/-=. At least I'm <a href="http://twitter.com/jbogard/statuses/788133552">not
using vb though</a>... Alas, we cannot access them easily so we're stuck hacking away
like this. So this particular method will basically get the mock or stub ICardView.BeginDrag
ready to be fired. This needs to be done during the record phase it seems. You can
only prime one event at a time per mock, so if you need to do more than one you can
revert to the normal Rhino.Mocks syntax.
</p>
        <pre class="c-sharp" name="code">    Target.Changed += NewEventFireExpectation&lt;EventHandler&gt;();</pre>
        <p>
This was a fun method. This method actually creates a new DynamicMethod in the signature
required by the event and creates a new delegate. The method tracks whether or not
it was fired, and at the end of the Playback phase in my fixture it will assert that
all of the events were actually fired.
</p>
        <pre class="c-sharp" name="code">    FireEventOn&lt;ICardView&gt;(EventArgs.Empty);</pre>
        <p>
This actually fires the event we set up in the Prime call. It can only be called after
you've primed an event.
</p>
        <p>
So, the whole thing is kind of "magic", but it's less code if you can accept the magic.
I think we can make things even better though, but it'd require changes to Rhino.Mocks
and it's time for bed so maybe Ayende can swing by the Eleutian office while in Seattle
and we can work on it. Here's what I'm thinking:
</p>
        <pre class="c-sharp" name="code">[Test]
public void ViewFiresBeginDrag_Always_FiresChangedEvent()
{
  using (Record)
  {
    Target.Changed += Mocks.CreateEventHandler&lt;EventHandler&gt;();
  }

  using (Playback)
  {
    EventRaiser.Raise(() =&gt; The<icardview>
().BeginDrag += null, The&lt;ICardView&gt;(), EventArgs.Empty); } }
</icardview></pre>
        <p>
There's probably more you can do with the CreateEventHandler syntax like add more
specific expectations, assert its not fired, assert that it's fired X times, etc.
The EventRaiser syntax is ugly, but it doesn't involve strings or the fire from the
right hand side like the syntax I mentioned at the beginning of the post.
</p>
        <p>
You can get the source <a href="http://svn2.assembla.com/svn/machine/trunk/Machine.Testing/">here</a>,
but I warn you it's first draft and there are hacky bits.
</p>
        <p>
Oh, and here's some example tests using the TestsFor fixture:
</p>
        <pre class="c-sharp" name="code">[TestFixture]
public class CardPresenterTests : TestsFor&lt;CardPresenter&gt;
{
  private Card _card;

  public override void SetupContainer()
  {
    Override&lt;ICardView&gt;(With.Stub);
  }

  public override void BeforeEachTest()
  {
    _card = new Card(0);
  }

  [Test]
  public void OnBeginDrag_Always_SetsIsInFluxToTrue()
  {
    using (Record)
    {
      PrimeEventFiringOn&lt;ICardView&gt;(x =&gt; x.BeginDrag += null);
    }

    using (Playback)
    {
      FireEventOn<icardview>
(EventArgs.Empty); Assert.That(The&lt;ICardView&gt;().IsInFlux, Is.True); } } [Test]
public void OnBeginDrag_Always_FiresChangedEvent() { using (Record) { PrimeEventFiringOn&lt;ICardView&gt;(x
=&gt; x.BeginDrag += null); Target.Changed += NewEventFireExpectation&lt;EventHandler&gt;();
} using (Playback) { FireEventOn&lt;ICardView&gt;(EventArgs.Empty); } } }
</icardview></pre>
        <img width="0" height="0" src="http://blog.eleutian.com/aggbug.ashx?id=40a71cf3-47c7-49ac-bb9c-ab9074adf0d1" />
      </body>
      <title>Mocking Events</title>
      <guid isPermaLink="false">http://blog.eleutian.com/PermaLink,guid,40a71cf3-47c7-49ac-bb9c-ab9074adf0d1.aspx</guid>
      <link>http://blog.eleutian.com/2008/04/13/MockingEvents.aspx</link>
      <pubDate>Sun, 13 Apr 2008 08:30:10 GMT</pubDate>
      <description>&lt;p&gt;
Currently in Rhino.Mocks, making mocks fire events and ensuring that an event on your
SUT was fired are both awkward and verbose at best. Here is an example of both things
at once:
&lt;/p&gt;
&lt;pre class="c-sharp" name="code"&gt;[Test]
public void ViewFiresBeginDrag_Always_FiresChangedEvent()
{
  IEventRaiser raiser;
  bool eventFired = false;
  using (Record)
  {
    The&amp;lt;ICardView&amp;gt;().BeginDrag += null;
    raiser = LastCall.IgnoreArguments().GetEventRaiser();

    Target.Changed += (x,y) =&amp;gt; eventFired = true;
  }

  using (Playback)
  {
    raiser.Raise(The&amp;lt;ICardView&amp;gt;(), EventArgs.Empty);
    Assert.IsTrue(eventFired);
  }
}&lt;/pre&gt;
&lt;p&gt;
Nice eh? First, is there a better way to do either of these things that I'm missing?
Please tell me if so. Next, if not, what can we do to clean this up?
&lt;/p&gt;
&lt;p&gt;
Well, Ayende and I &lt;a href="http://www.ayende.com/Blog/archive/2007/06/09/Rhino-Mocks-Events-Twisting-the-Syntax.aspx"&gt;discussed
this&lt;/a&gt; in the past and Ayende spiked it and &lt;a href="http://www.ayende.com/Blog/archive/2007/06/23/Natural-Event-Syntax-for-Rhino-Mocks.aspx"&gt;asked
for feedback&lt;/a&gt;. The feedback was mixed and for one reason or another it never made
it into Rhino.Mocks that I know of.
&lt;/p&gt;
&lt;p&gt;
Well, today while I was working on &lt;a href="http://svn2.assembla.com/svn/machine/trunk/Machine.Testing/"&gt;Machine.Testing&lt;/a&gt; and
another side project, I decided to give something else a shot. What I ended up with
is this:
&lt;/p&gt;
&lt;pre class="c-sharp" name="code"&gt;[Test]
public void ViewFiresBeginDrag_Always_FiresChangedEvent()
{
  using (Record)
  {
    PrimeEventFiringOn&amp;lt;ICardView&amp;gt;(x =&amp;gt; x.BeginDrag += null);
    Target.Changed += NewEventFireExpectation&amp;lt;EventHandler&amp;gt;();
  }

  using (Playback)
  {
    FireEventOn&amp;lt;ICardView&amp;gt;(EventArgs.Empty);
  }
}&lt;/pre&gt;
&lt;p&gt;
Better, but I still don't think it's perfect. Also, it probably requires some explanation,
so let's pick it apart piece by piece:
&lt;/p&gt;
&lt;pre class="c-sharp" name="code"&gt;    PrimeEventFiringOn&amp;lt;ICardView&amp;gt;(x =&amp;gt; x.BeginDrag += null);&lt;/pre&gt;
&lt;p&gt;
=&amp;gt; +=??? Ugly huh? I really wish we could just refer to an event somehow without
having to do +=/-=. At least I'm &lt;a href="http://twitter.com/jbogard/statuses/788133552"&gt;not
using vb though&lt;/a&gt;... Alas, we cannot access them easily so we're stuck hacking away
like this. So this particular method will basically get the mock or stub ICardView.BeginDrag
ready to be fired. This needs to be done during the record phase it seems. You can
only prime one event at a time per mock, so if you need to do more than one you can
revert to the normal Rhino.Mocks syntax.
&lt;/p&gt;
&lt;pre class="c-sharp" name="code"&gt;    Target.Changed += NewEventFireExpectation&amp;lt;EventHandler&amp;gt;();&lt;/pre&gt;
&lt;p&gt;
This was a fun method. This method actually creates a new DynamicMethod in the signature
required by the event and creates a new delegate. The method tracks whether or not
it was fired, and at the end of the Playback phase in my fixture it will assert that
all of the events were actually fired.
&lt;/p&gt;
&lt;pre class="c-sharp" name="code"&gt;    FireEventOn&amp;lt;ICardView&amp;gt;(EventArgs.Empty);&lt;/pre&gt;
&lt;p&gt;
This actually fires the event we set up in the Prime call. It can only be called after
you've primed an event.
&lt;/p&gt;
&lt;p&gt;
So, the whole thing is kind of "magic", but it's less code if you can accept the magic.
I think we can make things even better though, but it'd require changes to Rhino.Mocks
and it's time for bed so maybe Ayende can swing by the Eleutian office while in Seattle
and we can work on it. Here's what I'm thinking:
&lt;/p&gt;
&lt;pre class="c-sharp" name="code"&gt;[Test]
public void ViewFiresBeginDrag_Always_FiresChangedEvent()
{
  using (Record)
  {
    Target.Changed += Mocks.CreateEventHandler&amp;lt;EventHandler&amp;gt;();
  }

  using (Playback)
  {
    EventRaiser.Raise(() =&amp;gt; The&lt;icardview&gt;
().BeginDrag += null, The&amp;lt;ICardView&amp;gt;(), EventArgs.Empty); } }
&lt;/pre&gt;
&lt;p&gt;
There's probably more you can do with the CreateEventHandler syntax like add more
specific expectations, assert its not fired, assert that it's fired X times, etc.
The EventRaiser syntax is ugly, but it doesn't involve strings or the fire from the
right hand side like the syntax I mentioned at the beginning of the post.
&lt;/p&gt;
&lt;p&gt;
You can get the source &lt;a href="http://svn2.assembla.com/svn/machine/trunk/Machine.Testing/"&gt;here&lt;/a&gt;,
but I warn you it's first draft and there are hacky bits.
&lt;/p&gt;
&lt;p&gt;
Oh, and here's some example tests using the TestsFor fixture:
&lt;/p&gt;
&lt;pre class="c-sharp" name="code"&gt;[TestFixture]
public class CardPresenterTests : TestsFor&amp;lt;CardPresenter&amp;gt;
{
  private Card _card;

  public override void SetupContainer()
  {
    Override&amp;lt;ICardView&amp;gt;(With.Stub);
  }

  public override void BeforeEachTest()
  {
    _card = new Card(0);
  }

  [Test]
  public void OnBeginDrag_Always_SetsIsInFluxToTrue()
  {
    using (Record)
    {
      PrimeEventFiringOn&amp;lt;ICardView&amp;gt;(x =&amp;gt; x.BeginDrag += null);
    }

    using (Playback)
    {
      FireEventOn&lt;icardview&gt;
(EventArgs.Empty); Assert.That(The&amp;lt;ICardView&amp;gt;().IsInFlux, Is.True); } } [Test]
public void OnBeginDrag_Always_FiresChangedEvent() { using (Record) { PrimeEventFiringOn&amp;lt;ICardView&amp;gt;(x
=&amp;gt; x.BeginDrag += null); Target.Changed += NewEventFireExpectation&amp;lt;EventHandler&amp;gt;();
} using (Playback) { FireEventOn&amp;lt;ICardView&amp;gt;(EventArgs.Empty); } } }
&lt;/pre&gt;
&lt;img width="0" height="0" src="http://blog.eleutian.com/aggbug.ashx?id=40a71cf3-47c7-49ac-bb9c-ab9074adf0d1" /&gt;</description>
      <comments>http://blog.eleutian.com/CommentView,guid,40a71cf3-47c7-49ac-bb9c-ab9074adf0d1.aspx</comments>
      <category>development</category>
      <category>frameworks</category>
      <category>mocking</category>
    </item>
    <item>
      <trackback:ping>http://blog.eleutian.com/Trackback.aspx?guid=36e031ad-2d2a-4d3a-b509-51bd7a507d1c</trackback:ping>
      <pingback:server>http://blog.eleutian.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.eleutian.com/PermaLink,guid,36e031ad-2d2a-4d3a-b509-51bd7a507d1c.aspx</pingback:target>
      <dc:creator>Aaron</dc:creator>
      <wfw:comment>http://blog.eleutian.com/CommentView,guid,36e031ad-2d2a-4d3a-b509-51bd7a507d1c.aspx</wfw:comment>
      <wfw:commentRss>http://blog.eleutian.com/SyndicationService.asmx/GetEntryCommentsRss?guid=36e031ad-2d2a-4d3a-b509-51bd7a507d1c</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.clariusconsulting.net/kzu">Daniel Cazzulino</a>, author of Moq
posted a good comment on my last post where I suggested looking into a Mockito like
syntax for .NET Mock Frameworks.
</p>
        <p>
          <em>On the surface, Mockito's approach seems good. But if you do the "true" comparison,
you'll see that stub(...) is exactly the same as mock.Expect(...) in Moq.</em>
        </p>
        <p>
          <em>Then, when you do verify(...), you have to basically repeat the exact same expression
you put in stub(...). This might work if you only have a couple calls to verify, but
for anything else, it will be a lot of repeated code, I'm afraid. </em>
        </p>
        <p>
I thought this too. See my comment <a href="http://monkeyisland.pl/2008/02/24/can-i-test-what-i-want-please/#comments">here</a> from
a month ago. <a href="http://monkeyisland.pl/">Szczepan</a> made a good point and
I've thought about it more since then.
</p>
        <p>
When combined with my position on loose vs strict mocks (almost always use loose),
I'd say that *most* of the time you are either stubbing or verifying. Meaning, if
you're verifying you don't need to stub unless of course that method returns something
that is critical to the flow of your test, in which case you don't really need to
verify, because the flow would have verified. That's a mouthful, but does that make
sense?
</p>
        <p>
I haven't used mockito, and I know there are times I use Expect.Call with return values
that matter (which would essentially require you to duplicate stub &amp; verify),
but maybe that's a smell? Maybe if you think you need that you can do state based
testing or change your API?
</p>
        <p>
Here's an example Test using Rhino.Mocks:
</p>
        <pre class="c-sharp" name="code">[Test]
public void SomeMethod_Always_CallsSendMail()
{
  IMailSender sender = mocks.DynamicMock<imailsender>
(); UnderTest underTest = new UnderTest(sender); using (mocks.Record()) { Expect.Call(sender.SendMail()).Returns(true);
} underTest.SomeMethod(); mocks.Verify(sender); }
</imailsender></pre>
        <p>
And some code this is testing (obviously not test driven, but you get the idea):
</p>
        <pre class="c-sharp" name="code">public void SomeMethod()
{
  if (!_sender.SendMail())
  {
    throw new Exception("OH NOS");
  }
}</pre>
        <p>
Notice that here we would need to stub and verify separately with Mockito like syntax.
This would look something like this:
</p>
        <pre class="c-sharp" name="code">[Test]
public void SomeMethod_Always_CallsSendMail()
{
  IMailSender sender = mocks.DynamicMock<imailsender>
(); UnderTest underTest = new UnderTest(sender); Stub.That(() =&gt; sender.SendMail()).Returns(true);
underTest.SomeMethod(); Verify.That(() =&gt; sender.SendMail()).WasCalled(); }
</imailsender></pre>
        <p>
This may violate DRY, but what if you designed your API differently? Maybe SendMail
should throw an exception on failure instead of returning a boolean? This would make
the return value unnecessary and remove the need for the Stub call. Clearly you can't
always do this, especially with unwrapped legacy or API code, but it's something to
think about.
</p>
        <p>
Also, I think you shouldn't be verifying more than one method generally to go along
with the one assert/test rule, so a single repeat would not be that horrendous. Heck,
you could even do:
</p>
        <pre class="c-sharp" name="code">[Test]
public void SomeMethod_Always_CallsSendMail()
{
  IMailSender sender = mocks.DynamicMock<imailsender>
(); UnderTest underTest = new UnderTest(sender); Stub.That(var sendMail = () =&gt;
sender.SendMail()).Returns(true); underTest.SomeMethod(); Verify.That(sendMail).WasCalled();
}
</imailsender></pre>
        <p>
I think the syntax would lead to better, more concise tests. But maybe it would just
be too annoying? I wouldn't know until I tried it for a while I guess.
</p>
        <img width="0" height="0" src="http://blog.eleutian.com/aggbug.ashx?id=36e031ad-2d2a-4d3a-b509-51bd7a507d1c" />
      </body>
      <title>Separate Stub and Verify != Duplicate code necessarily</title>
      <guid isPermaLink="false">http://blog.eleutian.com/PermaLink,guid,36e031ad-2d2a-4d3a-b509-51bd7a507d1c.aspx</guid>
      <link>http://blog.eleutian.com/2008/04/03/SeparateStubAndVerifyDuplicateCodeNecessarily.aspx</link>
      <pubDate>Thu, 03 Apr 2008 16:44:29 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://www.clariusconsulting.net/kzu"&gt;Daniel Cazzulino&lt;/a&gt;, author of Moq
posted a good comment on my last post where I suggested looking into a Mockito like
syntax for .NET Mock Frameworks.
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;On the surface, Mockito's approach seems good. But if you do the "true" comparison,
you'll see that stub(...) is exactly the same as mock.Expect(...) in Moq.&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;Then, when you do verify(...), you have to basically repeat the exact same expression
you put in stub(...). This might work if you only have a couple calls to verify, but
for anything else, it will be a lot of repeated code, I'm afraid. &lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
I thought this too. See my comment &lt;a href="http://monkeyisland.pl/2008/02/24/can-i-test-what-i-want-please/#comments"&gt;here&lt;/a&gt; from
a month ago. &lt;a href="http://monkeyisland.pl/"&gt;Szczepan&lt;/a&gt; made a good point and
I've thought about it more since then.
&lt;/p&gt;
&lt;p&gt;
When combined with my position on loose vs strict mocks (almost always use loose),
I'd say that *most* of the time you are either stubbing or verifying. Meaning, if
you're verifying you don't need to stub unless of course that method returns something
that is critical to the flow of your test, in which case you don't really need to
verify, because the flow would have verified. That's a mouthful, but does that make
sense?
&lt;/p&gt;
&lt;p&gt;
I haven't used mockito, and I know there are times I use Expect.Call with return values
that matter (which would essentially require you to duplicate stub &amp;amp; verify),
but maybe that's a smell? Maybe if you think you need that you can do state based
testing or change your API?
&lt;/p&gt;
&lt;p&gt;
Here's an example Test using Rhino.Mocks:
&lt;/p&gt;
&lt;pre class="c-sharp" name="code"&gt;[Test]
public void SomeMethod_Always_CallsSendMail()
{
  IMailSender sender = mocks.DynamicMock&lt;imailsender&gt;
(); UnderTest underTest = new UnderTest(sender); using (mocks.Record()) { Expect.Call(sender.SendMail()).Returns(true);
} underTest.SomeMethod(); mocks.Verify(sender); }
&lt;/pre&gt;
&lt;p&gt;
And some code this is testing (obviously not test driven, but you get the idea):
&lt;/p&gt;
&lt;pre class="c-sharp" name="code"&gt;public void SomeMethod()
{
  if (!_sender.SendMail())
  {
    throw new Exception("OH NOS");
  }
}&lt;/pre&gt;
&lt;p&gt;
Notice that here we would need to stub and verify separately with Mockito like syntax.
This would look something like this:
&lt;/p&gt;
&lt;pre class="c-sharp" name="code"&gt;[Test]
public void SomeMethod_Always_CallsSendMail()
{
  IMailSender sender = mocks.DynamicMock&lt;imailsender&gt;
(); UnderTest underTest = new UnderTest(sender); Stub.That(() =&amp;gt; sender.SendMail()).Returns(true);
underTest.SomeMethod(); Verify.That(() =&amp;gt; sender.SendMail()).WasCalled(); }
&lt;/pre&gt;
&lt;p&gt;
This may violate DRY, but what if you designed your API differently? Maybe SendMail
should throw an exception on failure instead of returning a boolean? This would make
the return value unnecessary and remove the need for the Stub call. Clearly you can't
always do this, especially with unwrapped legacy or API code, but it's something to
think about.
&lt;/p&gt;
&lt;p&gt;
Also, I think you shouldn't be verifying more than one method generally to go along
with the one assert/test rule, so a single repeat would not be that horrendous. Heck,
you could even do:
&lt;/p&gt;
&lt;pre class="c-sharp" name="code"&gt;[Test]
public void SomeMethod_Always_CallsSendMail()
{
  IMailSender sender = mocks.DynamicMock&lt;imailsender&gt;
(); UnderTest underTest = new UnderTest(sender); Stub.That(var sendMail = () =&amp;gt;
sender.SendMail()).Returns(true); underTest.SomeMethod(); Verify.That(sendMail).WasCalled();
}
&lt;/pre&gt;
&lt;p&gt;
I think the syntax would lead to better, more concise tests. But maybe it would just
be too annoying? I wouldn't know until I tried it for a while I guess.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.eleutian.com/aggbug.ashx?id=36e031ad-2d2a-4d3a-b509-51bd7a507d1c" /&gt;</description>
      <comments>http://blog.eleutian.com/CommentView,guid,36e031ad-2d2a-4d3a-b509-51bd7a507d1c.aspx</comments>
      <category>development</category>
      <category>frameworks</category>
      <category>mocking</category>
    </item>
    <item>
      <trackback:ping>http://blog.eleutian.com/Trackback.aspx?guid=48e6b33d-7fa0-4a4d-a441-4b3d5e21bd24</trackback:ping>
      <pingback:server>http://blog.eleutian.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.eleutian.com/PermaLink,guid,48e6b33d-7fa0-4a4d-a441-4b3d5e21bd24.aspx</pingback:target>
      <dc:creator>Aaron</dc:creator>
      <wfw:comment>http://blog.eleutian.com/CommentView,guid,48e6b33d-7fa0-4a4d-a441-4b3d5e21bd24.aspx</wfw:comment>
      <wfw:commentRss>http://blog.eleutian.com/SyndicationService.asmx/GetEntryCommentsRss?guid=48e6b33d-7fa0-4a4d-a441-4b3d5e21bd24</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <em>(Note: I'm going to speak about .NET mock projects here for the most part, but
most of them have Java quasi-equivalents.) </em>
        </p>
        <p>
The original mocking frameworks like <a href="http://nmock.org/">NMock</a> required
you to setup expectations by passing strings for method names. This was fragile and
made refactoring more difficult. 
</p>
        <p>
A few mock frameworks now allow you to define expectations and mock results in a strongly
typed manner. <a href="http://www.ayende.com/projects/rhino-mocks.aspx">Rhino Mocks</a> and <a href="http://www.typemock.com/">TypeMock</a> use
a record/replay method to setup expectations. The record replay method is mostly necessary
because the same calls are made on the same objects under two different scenarios.
This leads to a few issues. 
</p>
        <p>
The first issue is confusion and barrier to entry. Many people have complained that
the Record/Replay method is not straight forward and the whole paradigm is confusing.
There are also complains about the naming, are you really recording and then replaying?
It's just kind of a strange thing. Of course most of us learn to live with it, understand
it, and accept it for what it is. Recently though, a few mock frameworks have popped
up that do away with this model.
</p>
        <p>
In the .NET world we have <a href="http://code.google.com/p/moq/">Moq</a>. Moq gets
rid of the need for record/replay because recordings have a very different syntax.
They use lambdas instead of actual calls to the mock object. This allows the framework
to know when you are recording an expectation and when you are fulfilling an expectation.
It adds a bit of noise in the form of "() =&gt;" but all in all it's not bad. Of course
this requires C# 3.0, but it's good to keep looking ahead. 
</p>
        <p>
In the Java world we have <a href="http://code.google.com/p/mockito/">Mockito</a>.
Mockito also does away with the record/replay model but it does it in a different
way. At first I wasn't a fan, but thinking about it more, I like it. Mockito has two
main apis, stub and verify. Stub is equivalent to SetupResult.For, and verify is equivalent
to Expect.Call with a verify. The interesting bit is that the stubbing happens before
the the class under test is invoked and the verifying (which includes describing the
method to be verified) happens after the class under test is invoked. This is best
shown with an example stolen from the Mockito site:
</p>
        <pre class="java" name="code">  
  //stubbing using built-in anyInt() argument matcher
  stub(mockedList.get(anyInt())).toReturn("element");
  
  //stubbing using hamcrest (let's say isValid() returns your own hamcrest matcher):
  stub(mockedList.contains(argThat(isValid()))).toReturn("element");
  
  //following prints "element"
  System.out.println(mockedList.get(999));
  
  //you can also verify using argument matcher
  verify(mockedList).get(anyInt());</pre>
        <p>
Obviously it would take a bit of imagination to arrive at a .NET equivalent, but you
get the idea. I like this because the normal test structure is Setup Stuff-&gt;Do
Stuff to Test-&gt;Verify Stuff did what it should have. The normal record/replay model
requires you to set up verifications before you actually Do Stuff (though you call
VerifyAll afterwards). This is a bit less natural. I feel syntax like this (yeah,
I like the new NUnit syntax) would be more intention revealing:
</p>
        <pre class="java" name="code">Assert.That(() =&gt; someMock.Foo(), Was.Called);</pre>
        <p>
Or:
</p>
        <pre class="java" name="code">Verify.That(() =&gt; someMock.Foo()).WasCalled();</pre>
        <p>
Then you would stub like this:
</p>
        <pre class="java" name="code">Stub.That(() =&gt; someMock.Bar()).Returns(3);</pre>
        <p>
          <strong>Note: No idea if this is feasible or makes sense or not, my lambda experience
is limited to light reading, but you get the idea. I'm sure the syntax could also
be prettier.</strong>
        </p>
        <p>
Rhino.Mocks is my current mock framework of choice. I'm used to it, I've lightly contributed
to it, and I've been working with it for a while now. Despite that, I do think that
there is definitely more to explore in the mocking arena especially with C# 3.0.
</p>
        <p>
There are lots of other fun things to talk about too... like <a href="http://www.typemock.com/">TypeMock</a>'s
magic, but that's another day still...
</p>
        <img width="0" height="0" src="http://blog.eleutian.com/aggbug.ashx?id=48e6b33d-7fa0-4a4d-a441-4b3d5e21bd24" />
      </body>
      <title>The Past, Present and Future (?) of Mocking</title>
      <guid isPermaLink="false">http://blog.eleutian.com/PermaLink,guid,48e6b33d-7fa0-4a4d-a441-4b3d5e21bd24.aspx</guid>
      <link>http://blog.eleutian.com/2008/04/03/ThePastPresentAndFutureOfMocking.aspx</link>
      <pubDate>Thu, 03 Apr 2008 04:13:18 GMT</pubDate>
      <description>&lt;p&gt;
&lt;em&gt;(Note: I'm going to speak about .NET mock projects here for the most part, but
most of them have Java quasi-equivalents.) &lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
The original mocking frameworks like &lt;a href="http://nmock.org/"&gt;NMock&lt;/a&gt; required
you to setup expectations by passing strings for method names. This was fragile and
made refactoring more difficult. 
&lt;/p&gt;
&lt;p&gt;
A few mock frameworks now allow you to define expectations and mock results in a strongly
typed manner. &lt;a href="http://www.ayende.com/projects/rhino-mocks.aspx"&gt;Rhino Mocks&lt;/a&gt; and &lt;a href="http://www.typemock.com/"&gt;TypeMock&lt;/a&gt; use
a record/replay method to setup expectations. The record replay method is mostly necessary
because the same calls are made on the same objects under two different scenarios.
This leads to a few issues. 
&lt;/p&gt;
&lt;p&gt;
The first issue is confusion and barrier to entry. Many people have complained that
the Record/Replay method is not straight forward and the whole paradigm is confusing.
There are also complains about the naming, are you really recording and then replaying?
It's just kind of a strange thing. Of course most of us learn to live with it, understand
it, and accept it for what it is. Recently though, a few mock frameworks have popped
up that do away with this model.
&lt;/p&gt;
&lt;p&gt;
In the .NET world we have &lt;a href="http://code.google.com/p/moq/"&gt;Moq&lt;/a&gt;. Moq gets
rid of the need for record/replay because recordings have a very different syntax.
They use lambdas instead of actual calls to the mock object. This allows the framework
to know when you are recording an expectation and when you are fulfilling an expectation.
It adds a bit of noise in the form of "() =&amp;gt;" but all in all it's not bad. Of course
this requires C# 3.0, but it's good to keep looking ahead. 
&lt;/p&gt;
&lt;p&gt;
In the Java world we have &lt;a href="http://code.google.com/p/mockito/"&gt;Mockito&lt;/a&gt;.
Mockito also does away with the record/replay model but it does it in a different
way. At first I wasn't a fan, but thinking about it more, I like it. Mockito has two
main apis, stub and verify. Stub is equivalent to SetupResult.For, and verify is equivalent
to Expect.Call with a verify. The interesting bit is that the stubbing happens before
the the class under test is invoked and the verifying (which includes describing the
method to be verified) happens after the class under test is invoked. This is best
shown with an example stolen from the Mockito site:
&lt;/p&gt;
&lt;pre class="java" name="code"&gt;  
  //stubbing using built-in anyInt() argument matcher
  stub(mockedList.get(anyInt())).toReturn("element");
  
  //stubbing using hamcrest (let's say isValid() returns your own hamcrest matcher):
  stub(mockedList.contains(argThat(isValid()))).toReturn("element");
  
  //following prints "element"
  System.out.println(mockedList.get(999));
  
  //you can also verify using argument matcher
  verify(mockedList).get(anyInt());&lt;/pre&gt;
&lt;p&gt;
Obviously it would take a bit of imagination to arrive at a .NET equivalent, but you
get the idea. I like this because the normal test structure is Setup Stuff-&amp;gt;Do
Stuff to Test-&amp;gt;Verify Stuff did what it should have. The normal record/replay model
requires you to set up verifications before you actually Do Stuff (though you call
VerifyAll afterwards). This is a bit less natural. I feel syntax like this (yeah,
I like the new NUnit syntax) would be more intention revealing:
&lt;/p&gt;
&lt;pre class="java" name="code"&gt;Assert.That(() =&amp;gt; someMock.Foo(), Was.Called);&lt;/pre&gt;
&lt;p&gt;
Or:
&lt;/p&gt;
&lt;pre class="java" name="code"&gt;Verify.That(() =&amp;gt; someMock.Foo()).WasCalled();&lt;/pre&gt;
&lt;p&gt;
Then you would stub like this:
&lt;/p&gt;
&lt;pre class="java" name="code"&gt;Stub.That(() =&amp;gt; someMock.Bar()).Returns(3);&lt;/pre&gt;
&lt;p&gt;
&lt;strong&gt;Note: No idea if this is feasible or makes sense or not, my lambda experience
is limited to light reading, but you get the idea. I'm sure the syntax could also
be prettier.&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Rhino.Mocks is my current mock framework of choice. I'm used to it, I've lightly contributed
to it, and I've been working with it for a while now. Despite that, I do think that
there is definitely more to explore in the mocking arena especially with C# 3.0.
&lt;/p&gt;
&lt;p&gt;
There are lots of other fun things to talk about too... like &lt;a href="http://www.typemock.com/"&gt;TypeMock&lt;/a&gt;'s
magic, but that's another day still...
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.eleutian.com/aggbug.ashx?id=48e6b33d-7fa0-4a4d-a441-4b3d5e21bd24" /&gt;</description>
      <comments>http://blog.eleutian.com/CommentView,guid,48e6b33d-7fa0-4a4d-a441-4b3d5e21bd24.aspx</comments>
      <category>development</category>
      <category>frameworks</category>
      <category>mocking</category>
    </item>
    <item>
      <trackback:ping>http://blog.eleutian.com/Trackback.aspx?guid=0986ad95-df80-4393-9706-6c7a91c74ee4</trackback:ping>
      <pingback:server>http://blog.eleutian.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.eleutian.com/PermaLink,guid,0986ad95-df80-4393-9706-6c7a91c74ee4.aspx</pingback:target>
      <dc:creator>Aaron</dc:creator>
      <wfw:comment>http://blog.eleutian.com/CommentView,guid,0986ad95-df80-4393-9706-6c7a91c74ee4.aspx</wfw:comment>
      <wfw:commentRss>http://blog.eleutian.com/SyndicationService.asmx/GetEntryCommentsRss?guid=0986ad95-df80-4393-9706-6c7a91c74ee4</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.clariusconsulting.net/blogs/kzu/archive/2007/12/18/LinqtoMockMoqisborn.aspx">Moq</a> has
been getting some press lately because it's the newest mock framework on the block.
I think it's certainly interesting and I'll have more to say on it later, but I wanted
to briefly complain about one aspect real quick.
</p>
        <p>
Moq touts that it has a more simplified API when compared to something like <a href="http://www.ayende.com/projects/rhino-mocks.aspx">Rhino.Mocks</a>.
The API has a single entry point which certainly aids discoverability, but I question
one of the design decisions. I remember seeing someone say that Rhino had too many
types of mocks and that that was confusing. Well, I don't think it has this many different
Mock Behaviors:
</p>
        <pre>  public enum MockBehavior
  {
    Strict, 
    Normal,
    Relaxed,
    Loose,
    Default = Normal,
  }
</pre>
        <p>
Why have this many? Does anyone know what they do just by looking at them? At least
they're documented, but the docs are quite a mouthful:
</p>
        <pre>  public enum MockBehavior
  {
    /// 
<summary>
/// Causes the mock to always throw /// an exception for invocations that don't have
a /// corresponding expectation. /// 
</summary>
Strict, /// 
<summary>
/// Matches the behavior of classes and interfaces /// in equivalent manual mocks:
abstract methods /// need to have an expectation (override), as well /// as all interface
members. Other members (virtual /// and non-virtual) can be called freely and will
end up /// invoking the implementation on the target type if available. /// 
</summary>
Normal, /// 
<summary>
/// Will only throw exceptions for abstract methods and /// interface members which
need to return a value and /// don't have a corresponding expectation. /// 
</summary>
Relaxed, /// 
<summary>
/// Will never throw exceptions, returning default /// values when necessary (null
for reference types /// or zero for value types). /// 
</summary>
Loose, /// 
<summary>
/// Default mock behavior, which equals 
<see cref="Normal" />
. /// 
</summary>
Default = Normal, } </pre>
        <p>
I'm of the opinion that you should only have one type of Mock, and that's what Rhino
calls Dynamic and Moq calls Loose. I described why <a href="http://blog.eleutian.com/2007/02/27/LooselycoupledMocks.aspx">here</a>.
If I wanted to simplify mocking, I'd start here.
</p>
        <img width="0" height="0" src="http://blog.eleutian.com/aggbug.ashx?id=0986ad95-df80-4393-9706-6c7a91c74ee4" />
      </body>
      <title>Moq's MockBehavior</title>
      <guid isPermaLink="false">http://blog.eleutian.com/PermaLink,guid,0986ad95-df80-4393-9706-6c7a91c74ee4.aspx</guid>
      <link>http://blog.eleutian.com/2008/03/26/MoqsMockBehavior.aspx</link>
      <pubDate>Wed, 26 Mar 2008 16:29:45 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://www.clariusconsulting.net/blogs/kzu/archive/2007/12/18/LinqtoMockMoqisborn.aspx"&gt;Moq&lt;/a&gt; has
been getting some press lately because it's the newest mock framework on the block.
I think it's certainly interesting and I'll have more to say on it later, but I wanted
to briefly complain about one aspect real quick.
&lt;/p&gt;
&lt;p&gt;
Moq touts that it has a more simplified API when compared to something like &lt;a href="http://www.ayende.com/projects/rhino-mocks.aspx"&gt;Rhino.Mocks&lt;/a&gt;.
The API has a single entry point which certainly aids discoverability, but I question
one of the design decisions. I remember seeing someone say that Rhino had too many
types of mocks and that that was confusing. Well, I don't think it has this many different
Mock Behaviors:
&lt;/p&gt;
&lt;pre&gt;  public enum MockBehavior
  {
    Strict, 
    Normal,
    Relaxed,
    Loose,
    Default = Normal,
  }
&lt;/pre&gt;
&lt;p&gt;
Why have this many? Does anyone know what they do just by looking at them? At least
they're documented, but the docs are quite a mouthful:
&lt;/p&gt;
&lt;pre&gt;  public enum MockBehavior
  {
    /// 
&lt;summary&gt;
/// Causes the mock to always throw /// an exception for invocations that don't have
a /// corresponding expectation. /// 
&lt;/summary&gt;
Strict, /// 
&lt;summary&gt;
/// Matches the behavior of classes and interfaces /// in equivalent manual mocks:
abstract methods /// need to have an expectation (override), as well /// as all interface
members. Other members (virtual /// and non-virtual) can be called freely and will
end up /// invoking the implementation on the target type if available. /// 
&lt;/summary&gt;
Normal, /// 
&lt;summary&gt;
/// Will only throw exceptions for abstract methods and /// interface members which
need to return a value and /// don't have a corresponding expectation. /// 
&lt;/summary&gt;
Relaxed, /// 
&lt;summary&gt;
/// Will never throw exceptions, returning default /// values when necessary (null
for reference types /// or zero for value types). /// 
&lt;/summary&gt;
Loose, /// 
&lt;summary&gt;
/// Default mock behavior, which equals 
&lt;see cref="Normal" /&gt;
. /// 
&lt;/summary&gt;
Default = Normal, } &lt;/pre&gt;
&lt;p&gt;
I'm of the opinion that you should only have one type of Mock, and that's what Rhino
calls Dynamic and Moq calls Loose. I described why &lt;a href="http://blog.eleutian.com/2007/02/27/LooselycoupledMocks.aspx"&gt;here&lt;/a&gt;.
If I wanted to simplify mocking, I'd start here.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.eleutian.com/aggbug.ashx?id=0986ad95-df80-4393-9706-6c7a91c74ee4" /&gt;</description>
      <comments>http://blog.eleutian.com/CommentView,guid,0986ad95-df80-4393-9706-6c7a91c74ee4.aspx</comments>
      <category>mocking</category>
      <category>frameworks</category>
    </item>
  </channel>
</rss>