<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Setup expectation with successive function calls using Moq</title>
	<atom:link href="http://www.timvw.be/setup-expectation-with-successive-function-calls-using-moq/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.timvw.be/setup-expectation-with-successive-function-calls-using-moq/</link>
	<description>The journey of a thousand miles begins with one step.</description>
	<lastBuildDate>Fri, 02 Jul 2010 13:49:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Paul</title>
		<link>http://www.timvw.be/setup-expectation-with-successive-function-calls-using-moq/comment-page-1/#comment-64783</link>
		<dc:creator>Paul</dc:creator>
		<pubDate>Mon, 31 Aug 2009 19:57:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.timvw.be/?p=864#comment-64783</guid>
		<description>Uggh.  Forgot that HTML and Generics aren&#039;t friends.  Try this...

    public static class MoqExtensions
    {
        public static IReturnsResult&lt;TMock&gt;ReturnsInOrder&lt;TMock, TResult&gt;(this ISetup&lt;TMock, TResult setup, params TResult[] values) where TMock : class
        {
            var valueQueue = new Queue&lt;TResult&gt;(values);
            return setup.Returns(valueQueue.Dequeue);
        }
    }</description>
		<content:encoded><![CDATA[<p>Uggh.  Forgot that HTML and Generics aren&#8217;t friends.  Try this&#8230;</p>
<p>    public static class MoqExtensions<br />
    {<br />
        public static IReturnsResult&lt;TMock&gt;ReturnsInOrder&lt;TMock, TResult&gt;(this ISetup&lt;TMock, TResult setup, params TResult[] values) where TMock : class<br />
        {<br />
            var valueQueue = new Queue&lt;TResult&gt;(values);<br />
            return setup.Returns(valueQueue.Dequeue);<br />
        }<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul</title>
		<link>http://www.timvw.be/setup-expectation-with-successive-function-calls-using-moq/comment-page-1/#comment-64782</link>
		<dc:creator>Paul</dc:creator>
		<pubDate>Mon, 31 Aug 2009 19:54:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.timvw.be/?p=864#comment-64782</guid>
		<description>I found this worked, to replace the Funcs with values.  Great starting point though, thanks for that; could not think for the life of me where to start with this problem.

    public static class MoqExtensions
    {
        public static IReturnsResult ReturnsInOrder(this ISetup setup, params TResult[] values) where TMock : class
        {
            var valueQueue = new Queue(values);
            return setup.Returns(valueQueue.Dequeue);
        }
    }</description>
		<content:encoded><![CDATA[<p>I found this worked, to replace the Funcs with values.  Great starting point though, thanks for that; could not think for the life of me where to start with this problem.</p>
<p>    public static class MoqExtensions<br />
    {<br />
        public static IReturnsResult ReturnsInOrder(this ISetup setup, params TResult[] values) where TMock : class<br />
        {<br />
            var valueQueue = new Queue(values);<br />
            return setup.Returns(valueQueue.Dequeue);<br />
        }<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason</title>
		<link>http://www.timvw.be/setup-expectation-with-successive-function-calls-using-moq/comment-page-1/#comment-64163</link>
		<dc:creator>Jason</dc:creator>
		<pubDate>Wed, 29 Jul 2009 21:10:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.timvw.be/?p=864#comment-64163</guid>
		<description>Thank you for this code example. It is helping me mock an IDataReader with successive Read() calls.</description>
		<content:encoded><![CDATA[<p>Thank you for this code example. It is helping me mock an IDataReader with successive Read() calls.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Hamilton</title>
		<link>http://www.timvw.be/setup-expectation-with-successive-function-calls-using-moq/comment-page-1/#comment-57330</link>
		<dc:creator>Matt Hamilton</dc:creator>
		<pubDate>Tue, 17 Mar 2009 00:20:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.timvw.be/?p=864#comment-57330</guid>
		<description>&gt; I ran into the problem of setting “ordered” results while playing with callbacks.. That is why i choose for functions instead of values.

Fair enough. I took your code and &quot;ported&quot; it back to Moq 2.x, and while I was at it I added an overload which simply took an array of TResult, so it&#039;s possible to have both! Pretty handy!</description>
		<content:encoded><![CDATA[<p>&gt; I ran into the problem of setting “ordered” results while playing with callbacks.. That is why i choose for functions instead of values.</p>
<p>Fair enough. I took your code and &#8220;ported&#8221; it back to Moq 2.x, and while I was at it I added an overload which simply took an array of TResult, so it&#8217;s possible to have both! Pretty handy!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: timvw</title>
		<link>http://www.timvw.be/setup-expectation-with-successive-function-calls-using-moq/comment-page-1/#comment-57315</link>
		<dc:creator>timvw</dc:creator>
		<pubDate>Mon, 16 Mar 2009 06:32:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.timvw.be/?p=864#comment-57315</guid>
		<description>@Matt:

&lt;blockquote&gt;Is there any reason why your “ReturnsInOrder” method couldn’t take an array of TResult rather than Func?&lt;/blockquote&gt;

I ran into the problem of setting &quot;ordered&quot; results while playing with callbacks.. That is why i choose for functions instead of values.

&lt;blockquote&gt;You could simply pass the valueFunctions array into the constructor of your Queue, rather than ‘foreaching’ over it and Enqueueing every item individually.&lt;/blockquote&gt;

You are absolutely right. While i was writing the method i looked for a constructed that accepted an IEnumerable but didn&#039;t find see it. Now that i&#039;m more awake, i could easily spot it ;) Thanks for the feedback.</description>
		<content:encoded><![CDATA[<p>@Matt:</p>
<blockquote><p>Is there any reason why your “ReturnsInOrder” method couldn’t take an array of TResult rather than Func?</p></blockquote>
<p>I ran into the problem of setting &#8220;ordered&#8221; results while playing with callbacks.. That is why i choose for functions instead of values.</p>
<blockquote><p>You could simply pass the valueFunctions array into the constructor of your Queue, rather than ‘foreaching’ over it and Enqueueing every item individually.</p></blockquote>
<p>You are absolutely right. While i was writing the method i looked for a constructed that accepted an IEnumerable but didn&#8217;t find see it. Now that i&#8217;m more awake, i could easily spot it <img src='http://www.timvw.be/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Thanks for the feedback.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Hamilton</title>
		<link>http://www.timvw.be/setup-expectation-with-successive-function-calls-using-moq/comment-page-1/#comment-57294</link>
		<dc:creator>Matt Hamilton</dc:creator>
		<pubDate>Sun, 15 Mar 2009 21:54:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.timvw.be/?p=864#comment-57294</guid>
		<description>One small thing: You could simply pass the valueFunctions array into the constructor of your Queue, rather than &#039;foreaching&#039; over it and Enqueueing every item individually. Cuts one line out of the method and potentially speeds it up slightly.</description>
		<content:encoded><![CDATA[<p>One small thing: You could simply pass the valueFunctions array into the constructor of your Queue, rather than &#8216;foreaching&#8217; over it and Enqueueing every item individually. Cuts one line out of the method and potentially speeds it up slightly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Hamilton</title>
		<link>http://www.timvw.be/setup-expectation-with-successive-function-calls-using-moq/comment-page-1/#comment-57290</link>
		<dc:creator>Matt Hamilton</dc:creator>
		<pubDate>Sun, 15 Mar 2009 21:34:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.timvw.be/?p=864#comment-57290</guid>
		<description>That&#039;s inspired, Tim!

Is there any reason why your &quot;ReturnsInOrder&quot; method couldn&#039;t take an array of TResult rather than Func? Have you only done that for the added flexibility of lazy evaluation?

Thanks for the ping!</description>
		<content:encoded><![CDATA[<p>That&#8217;s inspired, Tim!</p>
<p>Is there any reason why your &#8220;ReturnsInOrder&#8221; method couldn&#8217;t take an array of TResult rather than Func? Have you only done that for the added flexibility of lazy evaluation?</p>
<p>Thanks for the ping!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
