<?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>Tea-Driven Development &#187; generics</title>
	<atom:link href="http://blog.mattwynne.net/tag/generics/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mattwynne.net</link>
	<description>Matt Wynne taking it one tea at a time</description>
	<lastBuildDate>Tue, 10 Jan 2012 20:07:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Generics and NMock</title>
		<link>http://blog.mattwynne.net/2007/10/17/generics-and-nmock/</link>
		<comments>http://blog.mattwynne.net/2007/10/17/generics-and-nmock/#comments</comments>
		<pubDate>Wed, 17 Oct 2007 16:36:53 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[generics]]></category>
		<category><![CDATA[nmock]]></category>
		<category><![CDATA[nmock generics c#]]></category>

		<guid isPermaLink="false">http://blog.mattwynne.net/2007/10/17/generics-and-nmock/</guid>
		<description><![CDATA[Maybe NMock supports this, but I can&#8217;t see how. [Update 20/10/2007 - of course it does! See the comments for Aybars and Rob's solution.] Let&#8217;s say I have a dependency of my SUT (system under test). That dependency looks like: public interface IDatabase { void Get&#60;TTypeToFetch&#62; (); } Now in my test, I want to [...]]]></description>
			<content:encoded><![CDATA[<p>Maybe NMock supports this, but I can&#8217;t see how.</p>

<p><em>[Update 20/10/2007 - of course it does! See the comments for Aybars and Rob's solution.]</em></p>

<p>Let&#8217;s say I have a dependency of my SUT (system under test). That dependency looks like:
<pre>
public interface IDatabase
{
  void Get&lt;TTypeToFetch&gt; ();
}</pre>
Now in my test,  I want to expect that the SUT will try to fetch a Widget.</p>

<p>NMock gives me something which looks like it could help &#8211; a matcher. So I can code something like this:
<pre>
Mockery mockery = new Mockery();
IDatabase db = mockery.NewMock&lt;IDatabase&gt;();
Expect
  .Once
  .On(db)
  .Method(new GenericMethodMatcher(Widget));</pre>
So I code up a little GenericMethodMatcher which casts the object passed to it as a MethodInfo and takes a look at the result of a call to GetGenericArguments() to see if it fins a Widget. So far, so exceedingly <a href="http://www.urbandictionary.com/define.php?term=proper+bo">proper bo.</a></p>

<p>Unfortunately, the MethodInfo which NMock passes to the matcher is &#8216;open&#8217;, meaning that it still contains just the templated definitions of the types that <em>could</em> be passed to it at run-time. What I need in this instance, is a &#8216;closed&#8217; MethodInfo object.</p>

<p>I guess this is hard for NMock to do, since it only works with the interface and not a concrete class. I have no idea what&#8217;s going on under the hood&#8230;  Maybe it it possible but I&#8217;m just too stupid&#8230; I wonder how <a href="http://www.ayende.com/projects/rhino-mocks.aspx">other mocking frameworks</a> handle this scenario.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mattwynne.net/2007/10/17/generics-and-nmock/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

