Quick Tip: Asserting response redirects in a MonoRail controller test


Reading this post by Sean reminded me of when I first started using the trunk’s BaseControllerTest.  One nifty little property on the base test controller’s mock Response object is RedirectedTo.  So you can do something like this:

   1: // some call on the controller that should do the redirect
<pre style="border-style: none;margin: 0em;padding: 0px;overflow: visible;font-size: 8pt;width: 100%;color: black;line-height: 12pt;font-family: consolas,'Courier New',courier,monospace;background-color: #f4f4f4"><span style="color: #606060">   2:</span> Assert.AreEqual(<span style="color: #006080">"/productSearch/performSearch.rails"</span>, Response.RedirectedTo);</pre>

In previous MonoRail projects, I used the very nice base class from the guys at Eleutian and it worked great.  But I’ve been using the trunk’s BaseControllerTest exclusively on my current project since it started a few months ago and it rocks as well.  Nice to have it “out of the box” now.

← Refactoring towards a DRY, fluent interface
The importance of tools to a software craftsman →