<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>marthijn. &#187; NUnit</title>
	<atom:link href="http://www.marthijnvandenheuvel.com/tag/nunit/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.marthijnvandenheuvel.com</link>
	<description></description>
	<lastBuildDate>Fri, 30 Dec 2011 13:03:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Using NUnit in Visual Studio 2010</title>
		<link>http://www.marthijnvandenheuvel.com/2010/06/09/using-nunit-in-visual-studio-2010/</link>
		<comments>http://www.marthijnvandenheuvel.com/2010/06/09/using-nunit-in-visual-studio-2010/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 12:13:10 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[NUnit]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=196</guid>
		<description><![CDATA[How to use NUnit in Visual Studio 2010.]]></description>
			<content:encoded><![CDATA[<p>Like in older versions of <a href="http://www.microsoft.com/visualstudio" target="_blank">Visual Studio</a> it is possible to use <a href="http://www.nunit.org" target="_blank">NUnit</a> as an external tool in the new 2010 version. By creating a toolbar as well it is very easy to run your test suite. The usual way to add an external command is by clicking the menu Tools -&gt; External Tools. However, by default this menu item is not visible. To enable this menu item go to Tools -&gt; Settings -&gt; Expert Settings.</p>
<p><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010.png" rel="lightbox[196]"><img class="aligncenter size-full wp-image-197" title="Visual Studio 2010" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010.png" alt="Visual Studio 2010" width="214" height="32" /></a></p>
<p><span id="more-196"></span></p>
<p>The first step is download and install the latest version of NUnit since older versions are not compatible with .NET 4. NUnit version 2.5.5 can be downloaded <a href="http://www.nunit.org/?p=download" target="_blank">here</a>.</p>
<p>Now go to Tools -&gt; External Tools:</p>
<p><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_exttools.png" rel="lightbox[196]"><img class="aligncenter size-full wp-image-198" title="Visual Studio 2010 External Tools" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_exttools.png" alt="Visual Studio 2010 External Tools" width="493" height="481" /></a></p>
<p>I think this screen shot explains itself very well. Now its possible to add this external command to a tool bar. To do so go to View -&gt; Toolbars -&gt; Customize:</p>
<p><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_customize.png" rel="lightbox[196]"><img class="aligncenter size-full wp-image-200" title="Visual Studio 2010 Customize Toolbars" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_customize.png" alt="Visual Studio 2010 Customize Toolbars" width="465" height="509" /></a></p>
<p>Press the New button and enter a name. Now open the Commands tab and add the external command (usually External Command 1 when you don&#8217;t have any other external commands) to the toolbar:</p>
<p style="text-align: center;"><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_customize2.png" rel="lightbox[196]"><img class="aligncenter size-full wp-image-202" title="Visual Studio 2010 Commands" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_customize2.png" alt="Visual Studio 2010 Toolbars" width="801" height="529" /></a></p>
<p style="text-align: left;">When clicking the NUnit button in the new toolbar the NUnit GUI starts and loads your test suite.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2010/06/09/using-nunit-in-visual-studio-2010/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Using Rhino Mocks to mock a void function</title>
		<link>http://www.marthijnvandenheuvel.com/2010/03/15/using-rhino-mocks-to-mock-a-void-function/</link>
		<comments>http://www.marthijnvandenheuvel.com/2010/03/15/using-rhino-mocks-to-mock-a-void-function/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 23:01:57 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[NUnit]]></category>
		<category><![CDATA[Rhino Mocks]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=95</guid>
		<description><![CDATA[Using NUnit and Rhino Mocks to create an expectation for a void function.]]></description>
			<content:encoded><![CDATA[<p>In some of my web applications I use <a href="http://www.ayende.com/projects/rhino-mocks.aspx" target="_blank">Rhino Mocks</a> to create mock objects. Usually the code has a record section where the expected calls are recorded, and a playback section where the testing is done. In the following code snippet the DoSomething() function calls a void function which is defined in the interface of _myMock. The problem is this void function is not expected and the <a href="http://www.nunit.org/index.php" target="_blank">NUnit</a> test run will fail:</p>
<pre>Rhino.Mocks.Exceptions.ExpectationViolationException : IMyInterface.MyVoidFunction; Expected #0, Actual #1.</pre>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>_mock<span style="color: #008000;">.</span><span style="color: #0000FF;">Record</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  Expect<span style="color: #008000;">.</span><span style="color: #0000FF;">Call</span><span style="color: #008000;">&#40;</span>_myMock<span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;a&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Return</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;b&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008080; font-style: italic;">/* insert expectation for void function here */</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>_mock<span style="color: #008000;">.</span><span style="color: #0000FF;">Playback</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">// DoSomething calls the mocked object's GetValue function, which returns 'b' when the parameter is 'a'</span>
  <span style="color: #008080; font-style: italic;">// DoSomething also calls a void function which is located in the interface of the mocked object, so this</span>
  <span style="color: #008080; font-style: italic;">// void function must be mocked too, else the test run will fail</span>
  Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqual</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;b&quot;</span>, _myObject<span style="color: #008000;">.</span><span style="color: #0000FF;">DoSomething</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;a&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p><span id="more-95"></span></p>
<p>When trying to create an expectation for this void function Visual Studio will give a syntax error:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect<span style="color: #008000;">.</span><span style="color: #0000FF;">Call</span><span style="color: #008000;">&#40;</span>_myMock<span style="color: #008000;">.</span><span style="color: #0000FF;">MyVoidFunction</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Argument '1': cannot convert from 'void' to 'Rhino.Mocks.Expect.Action'</span></pre></div></div>

<p>On the internet I found two solutions to fix this problem. The <a href="http://ayende.com/Blog/archive/2007/10/17/Rhino-Mocks-Void-methods-using-Expect.Call.aspx" target="_blank">first solution</a> uses a delegate:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect<span style="color: #008000;">.</span><span style="color: #0000FF;">Call</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">delegate</span><span style="color: #008000;">&#123;</span> _myMock<span style="color: #008000;">.</span><span style="color: #0000FF;">MyVoidFunction</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>The <a href="http://stackoverflow.com/questions/359831/rhinomock-test-mock-interface-void-functions" target="_blank">second solution</a> uses a <a href="http://msdn.microsoft.com/en-us/library/bb397687.aspx" target="_blank">lambda</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect<span style="color: #008000;">.</span><span style="color: #0000FF;">Call</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span> _myMock<span style="color: #008000;">.</span><span style="color: #0000FF;">MyVoidFunction</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Now the test will succeed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2010/03/15/using-rhino-mocks-to-mock-a-void-function/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

