<?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: Unit testing MonoRail controllers &#8211; Redirects</title>
	<atom:link href="http://lostechies.com/jimmybogard/2008/02/19/unit-testing-monorail-controllers-redirects/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/jimmybogard/2008/02/19/unit-testing-monorail-controllers-redirects/</link>
	<description>Strong opinions, weakly held</description>
	<lastBuildDate>Wed, 22 May 2013 13:39:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: Jimmy Bogard</title>
		<link>http://lostechies.com/jimmybogard/2008/02/19/unit-testing-monorail-controllers-redirects/#comment-196</link>
		<dc:creator>Jimmy Bogard</dc:creator>
		<pubDate>Thu, 21 Feb 2008 01:47:45 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2008/02/18/unit-testing-monorail-controllers-redirects.aspx#comment-196</guid>
		<description>@Victor

I&#039;ll look into the email comments.  It looks like for now all I have is comments RSS.

I think the Controller might be a special case of state/interaction testing.  Since it&#039;s a base class I don&#039;t own, I&#039;d almost consider it a different object.

I&#039;ve also run into this where we had a different team implement our base business objects.  Setting property values would do all sorts of things which we didn&#039;t know and didn&#039;t care about.  So we just made sure we did what we were supposed to do and let the underlying object do its work.

My benchmark here was that I had no way to make the connection between the operation &quot;Redirect&quot; and the resultant state &quot;Response.RedirectedTo&quot;.  Admittedly the connection between the two seems logical, but how do I know the connection exists?  I have to know the underlying base class does this.

The way we arrived at this solution was that we instantiated our controller, called &quot;Redirect&quot;, and saw we got exceptions.  PrepareController fixes these exceptions, but for us, that we got exceptions was enough for us to stop, subclass and redirect, and use the mocks to test the interaction between our derived class and the base class.

I wouldn&#039;t go as far as to recommend people against PrepareController, but it&#039;s just my personal preference to treat base classes I don&#039;t own as an black-box dependency WRT methods.</description>
		<content:encoded><![CDATA[<p>@Victor</p>
<p>I&#8217;ll look into the email comments.  It looks like for now all I have is comments RSS.</p>
<p>I think the Controller might be a special case of state/interaction testing.  Since it&#8217;s a base class I don&#8217;t own, I&#8217;d almost consider it a different object.</p>
<p>I&#8217;ve also run into this where we had a different team implement our base business objects.  Setting property values would do all sorts of things which we didn&#8217;t know and didn&#8217;t care about.  So we just made sure we did what we were supposed to do and let the underlying object do its work.</p>
<p>My benchmark here was that I had no way to make the connection between the operation &#8220;Redirect&#8221; and the resultant state &#8220;Response.RedirectedTo&#8221;.  Admittedly the connection between the two seems logical, but how do I know the connection exists?  I have to know the underlying base class does this.</p>
<p>The way we arrived at this solution was that we instantiated our controller, called &#8220;Redirect&#8221;, and saw we got exceptions.  PrepareController fixes these exceptions, but for us, that we got exceptions was enough for us to stop, subclass and redirect, and use the mocks to test the interaction between our derived class and the base class.</p>
<p>I wouldn&#8217;t go as far as to recommend people against PrepareController, but it&#8217;s just my personal preference to treat base classes I don&#8217;t own as an black-box dependency WRT methods.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By:  Victor Kornov</title>
		<link>http://lostechies.com/jimmybogard/2008/02/19/unit-testing-monorail-controllers-redirects/#comment-195</link>
		<dc:creator> Victor Kornov</dc:creator>
		<pubDate>Wed, 20 Feb 2008 22:29:19 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2008/02/18/unit-testing-monorail-controllers-redirects.aspx#comment-195</guid>
		<description>Yep, I see you point about &quot;did I call Redirect&quot; and its a valid one.  But consider that when you use BaseControllerTest all services and context are already mocked with hand-made classes from Castle.Monorail.TestSupport. So, it&#039;s actually MockResponse.RedirectedTo. It exposes that for your testing. Note, It&#039;s not &quot;inner workings&quot; of your controller, but a public state meant just for that - testing. It&#039;s a bit &quot;raw&quot; out of the box though, as you may need your own convenience helper methods. From my POV it&#039;s good enough, so I fall back to state-based testing here.

As an aside, it&#039;s not good to test &quot;inner details&quot; but OK to test public state. And interaction testing is meant for that, object interactions, i.e. there are mo than one object, e.g. your controller. Currently, you test how you interact with yourself :)

P.S. Could you please look into enabling e-mailing responses for comments? It&#039;s just not convenient to go here once in a while to check discussion.</description>
		<content:encoded><![CDATA[<p>Yep, I see you point about &#8220;did I call Redirect&#8221; and its a valid one.  But consider that when you use BaseControllerTest all services and context are already mocked with hand-made classes from Castle.Monorail.TestSupport. So, it&#8217;s actually MockResponse.RedirectedTo. It exposes that for your testing. Note, It&#8217;s not &#8220;inner workings&#8221; of your controller, but a public state meant just for that &#8211; testing. It&#8217;s a bit &#8220;raw&#8221; out of the box though, as you may need your own convenience helper methods. From my POV it&#8217;s good enough, so I fall back to state-based testing here.</p>
<p>As an aside, it&#8217;s not good to test &#8220;inner details&#8221; but OK to test public state. And interaction testing is meant for that, object interactions, i.e. there are mo than one object, e.g. your controller. Currently, you test how you interact with yourself <img src='http://lostechies.com/jimmybogard/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>P.S. Could you please look into enabling e-mailing responses for comments? It&#8217;s just not convenient to go here once in a while to check discussion.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jimmy Bogard</title>
		<link>http://lostechies.com/jimmybogard/2008/02/19/unit-testing-monorail-controllers-redirects/#comment-194</link>
		<dc:creator>Jimmy Bogard</dc:creator>
		<pubDate>Wed, 20 Feb 2008 17:53:17 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2008/02/18/unit-testing-monorail-controllers-redirects.aspx#comment-194</guid>
		<description>@Victor

Yes, it is just a matter of personal taste, but I only really apply this to base classes I don&#039;t control.  I don&#039;t control SmartDispatcherController, and I don&#039;t want to know how its operations change its state.  All I care in my test is that &quot;Redirect&quot; is called.  That is also a method I don&#039;t own, so I don&#039;t want to test what it does.

What the Redirect method does is not important.  That it is being called is important.  I only care about the interaction, not the final state that MonoRail sets up for me.

In the end, if I cared what &quot;Response.RedirectedTo&quot; was, I would look at that.  But I don&#039;t in these tests.  All I care about is &quot;did I call Redirect with XXX controller and YYY action&quot;.</description>
		<content:encoded><![CDATA[<p>@Victor</p>
<p>Yes, it is just a matter of personal taste, but I only really apply this to base classes I don&#8217;t control.  I don&#8217;t control SmartDispatcherController, and I don&#8217;t want to know how its operations change its state.  All I care in my test is that &#8220;Redirect&#8221; is called.  That is also a method I don&#8217;t own, so I don&#8217;t want to test what it does.</p>
<p>What the Redirect method does is not important.  That it is being called is important.  I only care about the interaction, not the final state that MonoRail sets up for me.</p>
<p>In the end, if I cared what &#8220;Response.RedirectedTo&#8221; was, I would look at that.  But I don&#8217;t in these tests.  All I care about is &#8220;did I call Redirect with XXX controller and YYY action&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Victor Kornov</title>
		<link>http://lostechies.com/jimmybogard/2008/02/19/unit-testing-monorail-controllers-redirects/#comment-193</link>
		<dc:creator>Victor Kornov</dc:creator>
		<pubDate>Wed, 20 Feb 2008 14:23:49 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2008/02/18/unit-testing-monorail-controllers-redirects.aspx#comment-193</guid>
		<description>Sorry, but I don&#039;t get you mean by &quot;MonoRail implementation details&quot; here. Is that a Response.RedirectedTo prop with a simple string representing url for redirect?

Personally, I feel like you are complicating the test by making it interaction based as opposed to simpler state based. Don&#039;t you try to abstract too much away? 

You just need a couple of helper methods, like Sean shows, if any. If they were on a Response would it hide &quot;implementation details&quot; enough?</description>
		<content:encoded><![CDATA[<p>Sorry, but I don&#8217;t get you mean by &#8220;MonoRail implementation details&#8221; here. Is that a Response.RedirectedTo prop with a simple string representing url for redirect?</p>
<p>Personally, I feel like you are complicating the test by making it interaction based as opposed to simpler state based. Don&#8217;t you try to abstract too much away? </p>
<p>You just need a couple of helper methods, like Sean shows, if any. If they were on a Response would it hide &#8220;implementation details&#8221; enough?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jimmy Bogard</title>
		<link>http://lostechies.com/jimmybogard/2008/02/19/unit-testing-monorail-controllers-redirects/#comment-192</link>
		<dc:creator>Jimmy Bogard</dc:creator>
		<pubDate>Tue, 19 Feb 2008 17:22:08 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2008/02/18/unit-testing-monorail-controllers-redirects.aspx#comment-192</guid>
		<description>@Sean

Maybe I&#039;m being paranoid, but it feels weird for MonoRail implementation details to leak into my tests.  I find it more comforting to just do a partial mock of one method instead of getting a bunch of scaffolding up for a controller.

I run into this often when I test a derived class where I don&#039;t own the base class.  I tend to treat the base class as a black box.</description>
		<content:encoded><![CDATA[<p>@Sean</p>
<p>Maybe I&#8217;m being paranoid, but it feels weird for MonoRail implementation details to leak into my tests.  I find it more comforting to just do a partial mock of one method instead of getting a bunch of scaffolding up for a controller.</p>
<p>I run into this often when I test a derived class where I don&#8217;t own the base class.  I tend to treat the base class as a black box.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean Chambers</title>
		<link>http://lostechies.com/jimmybogard/2008/02/19/unit-testing-monorail-controllers-redirects/#comment-191</link>
		<dc:creator>Sean Chambers</dc:creator>
		<pubDate>Tue, 19 Feb 2008 13:09:54 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2008/02/18/unit-testing-monorail-controllers-redirects.aspx#comment-191</guid>
		<description>I use a &quot;ControllerTestBase&quot; class in all my controller tests where I have utility methods for assertions in controllers. Here is the method I use for asserting redirects:

        protected void AssertRedirectedTo(string controller, string action, string queryStringParameters)
        {
            Assert.AreEqual(Response.RedirectedTo, string.Format(@&quot;/{0}/{1}.rails{2}&quot;, controller, action, queryStringParameters), &quot;RedirectedTo was not equal&quot;);
        }

There may be an easier way to do this, but this has worked for me thus far.</description>
		<content:encoded><![CDATA[<p>I use a &#8220;ControllerTestBase&#8221; class in all my controller tests where I have utility methods for assertions in controllers. Here is the method I use for asserting redirects:</p>
<p>        protected void AssertRedirectedTo(string controller, string action, string queryStringParameters)<br />
        {<br />
            Assert.AreEqual(Response.RedirectedTo, string.Format(@&#8221;/{0}/{1}.rails{2}&#8221;, controller, action, queryStringParameters), &#8220;RedirectedTo was not equal&#8221;);<br />
        }</p>
<p>There may be an easier way to do this, but this has worked for me thus far.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
