<?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>Andrey Shchekin &#187; Mocking</title>
	<atom:link href="http://blog.ashmind.com/category/agile/mocking/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ashmind.com</link>
	<description></description>
	<lastBuildDate>Mon, 15 Mar 2010 18:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Mocking internal interfaces with Moq</title>
		<link>http://blog.ashmind.com/2008/05/09/mocking-internal-interfaces-with-moq/</link>
		<comments>http://blog.ashmind.com/2008/05/09/mocking-internal-interfaces-with-moq/#comments</comments>
		<pubDate>Fri, 09 May 2008 08:57:00 +0000</pubDate>
		<dc:creator>Andrey Shchekin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Mocking]]></category>
		<category><![CDATA[Moq]]></category>
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://blog.ashmind.com/index.php/2008/05/09/mocking-internal-interfaces-with-moq/</guid>
		<description><![CDATA[Is a same method you would use with NMock2, but with &#8220;DynamicProxyGenAssembly2&#8243; in InternalsVisibleTo. This strange name is a default dynamic assembly name used by Castle.DynamicProxy. Do not forget that the attribute should be added to the assembly with internal types, not to the tests assembly (obvious, but I got it wrong the first time). [...]]]></description>
			<content:encoded><![CDATA[<p>Is a <a href="http://blog.ashmind.com/index.php/2007/07/07/mocking-internal-interfaces-with-nmock2/">same method</a> you would use with NMock2, but with &#8220;DynamicProxyGenAssembly2&#8243; in InternalsVisibleTo.<br /> This strange name is a default dynamic assembly name used by Castle.DynamicProxy.</p>
<p>Do not forget that the attribute should be added to the assembly with internal types, not to the tests assembly (obvious, but I got it wrong the first time).</p>
<blockquote><p><strong>Update:</strong> <a href="http://groups.google.com/groups/profile?hl=en&#038;enc_user=MrWd7RcAAABFAu4WJ_yZyMt4VseX6ryvHqZiDvCVswhrZ6TQxKj0ww">yesthatmcgurk</a> has <a href="http://groups.google.com/group/moqdisc/browse_thread/thread/ebe69d235dfa69d9?hl=en">pointed me</a> to the fact that for strongly named assemblies you have to specify the public key as well. So the correct attribute for the strongly named assembly should be</p>
<pre class="csharpcode">[<span class="kwrd">assembly</span>:InternalsVisibleTo(<span class="str">"DynamicProxyGenAssembly2,
PublicKey=002400000480000094000000060200000024000052534
1310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b
3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d926665
4753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb
4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c486
1eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7"</span>)]
<span class="rem">// without line-breaks</span></pre>
</blockquote>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
]]></content:encoded>
			<wfw:commentRss>http://blog.ashmind.com/2008/05/09/mocking-internal-interfaces-with-moq/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>NMock 3.5</title>
		<link>http://blog.ashmind.com/2007/09/23/nmock-35/</link>
		<comments>http://blog.ashmind.com/2007/09/23/nmock-35/#comments</comments>
		<pubDate>Sun, 23 Sep 2007 09:09:14 +0000</pubDate>
		<dc:creator>Andrey Shchekin</dc:creator>
				<category><![CDATA[C# 3.0]]></category>
		<category><![CDATA[Fluent]]></category>
		<category><![CDATA[Mocking]]></category>
		<category><![CDATA[NMock2]]></category>

		<guid isPermaLink="false">http://blog.ashmind.com/index.php/2007/09/23/nmock-35/</guid>
		<description><![CDATA[One of the places where I am likely to actively use expression trees is testing/mocking. (I am not the first one to notice this — I saw some post on expression tree asserts, but I lost it). In my day-to-day development I am using NMock2. Ayende&#8216;s Rhino Mocks may be more convenient, but I do [...]]]></description>
			<content:encoded><![CDATA[<p>One of the places where I am likely to actively use expression trees is testing/mocking.<br />
(I am not the first one to notice this — I saw some post on expression tree asserts, but I lost it).</p>
<p>In my day-to-day development I am using <a href="http://nmock.org">NMock2</a>.<br /> <a href="http://www.ayende.com/Blog/">Ayende</a>&#8216;s <a href="http://www.ayende.com/projects/rhino-mocks.aspx">Rhino Mocks</a> may be more convenient, but I do not like the syntax.<br /> I just can&#8217;t read &#8220;expect call return&#8221; — my mind wants &#8220;expect call returns&#8221;.<br /> Also, event support in Rhinos is really cryptic.<br /> (I understand that it may be the only stringless way to express it).</p>
<p>So working on C# 3.0 project, I&#8217;ve looked into a stringless experience with NMock2.<br /> What I wanted was to pass a method call expression, to change this:
<pre class="csharpcode">
<span class="cls">Expect</span>.Once.On(fs)
    .Method(<span class="str">"GetDescendantDirectories"</span>)
    .With(RootPath)
    .Will(<span class="cls">Return</span>.Value(directories));</pre>
<p>into this
<pre class="csharpcode">
<span class="cls">Expect</span>.Once
    .That(() =&gt; fs.GetDescendantDirectories(RootPath))
    .Will(<span class="cls">Return</span>.Value(directories));</pre>
</p>
<p>Fortunately, it was quite easy to do with extension methods.<br />
I have spent more time figuring better fluent syntax than actually writing it.</p>
<p>But the case where expression trees really shine, I think, is in the possibility to do this:</p>
<pre class="csharpcode">
<span class="cls">Expect</span>.Exactly(directory.Files.Count)
    .That(() =&gt; access.IsPublicFile(<em><span class="cls">Any</span>.String</em>))
    .Will(<span class="cls">Return</span>.Value(<span class="kwrd">true</span>));</pre>
<p>I can analyze expression tree and find out that Any.String is not &#8220;a string&#8221;, but &#8220;any string&#8221;.<br />
It is also easy to imagine Any.String.Matching(&#8220;^whatever&#8221;) and so on.<br />
I have <strong>not</strong> tried to implement it, but I feel that it would be simple as well.
</p>
<p>Also, while writing the post, I just got an idea — in the world of extenson methods we can do</p>
<pre class="csharpcode">
<span class="cls">Expect</span>.Exactly(directory.Files.Count)
    .That(() =&gt; access.IsPublicFile(<span class="cls">Any</span>.String))
    .Will<em>.Return(<span class="kwrd">true</span>)</em>;</pre>
<p>without sacrificing extensibility.<br />
&#8220;Will&#8221; can also be chained if more than one action is needed (however, a delegate would be better for this).</p>
<p>It would be nice to actually add this to NMock2 (as 3.5 branch), but they are using CVS, not SVN.<br />
Also, am I the only one who thinks that SourceForge is slow and has hardly usable (bloated) design?</p>
<p>So if you want the code, you can ask me in comments, but it is primitive indeed.</p>
<style type="text/css">
.codewrap pre { width: 1%; }
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .cls { color: #2b91af; }
.csharpcode em { font-weight: normal; font-style: normal; text-decoration: underline; }
</style>
]]></content:encoded>
			<wfw:commentRss>http://blog.ashmind.com/2007/09/23/nmock-35/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Mocking internal interfaces with NMock2</title>
		<link>http://blog.ashmind.com/2007/07/07/mocking-internal-interfaces-with-nmock2/</link>
		<comments>http://blog.ashmind.com/2007/07/07/mocking-internal-interfaces-with-nmock2/#comments</comments>
		<pubDate>Sat, 07 Jul 2007 19:05:21 +0000</pubDate>
		<dc:creator>Andrey Shchekin</dc:creator>
				<category><![CDATA[Mocking]]></category>
		<category><![CDATA[NMock2]]></category>
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://blog.ashmind.com/index.php/2007/07/07/mocking-internal-interfaces-with-nmock2/</guid>
		<description><![CDATA[Yesterday I stumbled into a question of how to mock an internal interface. The interface is visible in the test assembly due to InternalVisibleTo attribute, but Mockery was unable to create a mock of it. The very first idea was additional InternalVisibleTo, but I had to find out what assembly name to use. Since dynamic [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I stumbled into a question of how to mock an internal interface.</p>
<p>The interface is visible in the test assembly due to InternalVisibleTo attribute, but Mockery was unable to create a mock of it.<br />
The very first idea was additional InternalVisibleTo, but I had to find out what assembly name to use.</p>
<p>Since dynamic mocks are actual classes created on-demand for the specified interface, they do not belong to NMock2 assembly.<br />
But they have their own dynamic assembly with consistent name &#8212; in case of NMock2 it is &#8220;Mocks&#8221; (I got it from Reflector).<br />
So I used InternalVisibleTo(&#8220;Mocks&#8221;) and it actually worked.</p>
<p>I am not sure if it would work with strong names, but, fortunately, I do not need to strong name this project.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ashmind.com/2007/07/07/mocking-internal-interfaces-with-nmock2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

