<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>ASP.NET MVC</title><link>http://forums.asp.net/1146.aspx</link><description>Discussions regarding Model-View-Controller (MVC) support in ASP.NET.  &lt;a href="http://forums.asp.net/1215.aspx"&gt;T4MVC subforum&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: Mocking and testing for RedirectToAction</title><link>http://forums.asp.net/thread/2229600.aspx</link><pubDate>Thu, 13 Mar 2008 03:10:40 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2229600</guid><dc:creator>kbaley</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2229600.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2229600</wfw:commentRss><description>&lt;p&gt;Yes, you need to wrap the call in a lambda. I think Ayende talks about this on his blog.&lt;/p&gt;
&lt;p&gt;Also, you can&amp;#39;t test for List.aspx because there&amp;#39;s a good chance the URL won&amp;#39;t end in .aspx. But even if you test for something valid, I haven&amp;#39;t been able to get it to work. The SetFakeControllerContext creates a context with an empty RouteData which is where the null is coming into play. Somewhere in the bowels of the Route class, it&amp;#39;s referencing a property on the HttpContextBase.Request method that hasn&amp;#39;t been mocked (AppRelativeCurrentExecutionFilePath I think).&lt;/p&gt;
&lt;p&gt;Not sure what the way to do this now is. I don&amp;#39;t want to go back to a test-specific subclass just for the RedirectToAction method. At this point, I&amp;#39;m almost inclined to simply not test calls to RedirectToAction and add comments to add tests when it becomes possible.&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Mocking and testing for RedirectToAction</title><link>http://forums.asp.net/thread/2228226.aspx</link><pubDate>Wed, 12 Mar 2008 13:55:16 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2228226</guid><dc:creator>CVertex</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2228226.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2228226</wfw:commentRss><description>&lt;p&gt;Phil mentions the RedirectToAction testing problem on his blog.&lt;/p&gt;&lt;p&gt;Is there a friendly work around for now? Just so my tests pass?&lt;br /&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Mocking and testing for RedirectToAction</title><link>http://forums.asp.net/thread/2228209.aspx</link><pubDate>Wed, 12 Mar 2008 13:48:53 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2228209</guid><dc:creator>CVertex</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2228209.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2228209</wfw:commentRss><description>&lt;p&gt;I wasn&amp;#39;t on the same machine as I wrote the other code, but I quickly set up a similar situation and the same compiler error.&amp;nbsp;&lt;/p&gt;&lt;p&gt;Here are the compiler errors:&amp;nbsp;&lt;/p&gt;&lt;p&gt;Error&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; The best overloaded method match for &amp;#39;Rhino.Mocks.Expect.Call(Rhino.Mocks.Expect.Action)&amp;#39; has some invalid arguments&amp;nbsp;&amp;nbsp;&amp;nbsp; D:\Projects\MvcExperimentTests\Controllers\HomeControllerTest.cs&amp;nbsp;&amp;nbsp;&amp;nbsp; 59&amp;nbsp;&amp;nbsp;&amp;nbsp; 17&amp;nbsp;&amp;nbsp;&amp;nbsp; MvcExperimentTests&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Error&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp; Argument &amp;#39;1&amp;#39;: cannot convert from &amp;#39;void&amp;#39; to &amp;#39;Rhino.Mocks.Expect.Action&amp;#39;&amp;nbsp;&amp;nbsp;&amp;nbsp; D:\Projects\MvcExperimentTests\Controllers\HomeControllerTest.cs&amp;nbsp;&amp;nbsp;&amp;nbsp; 59&amp;nbsp;&amp;nbsp;&amp;nbsp; 29&amp;nbsp;&amp;nbsp;&amp;nbsp; MvcExperimentTests&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Should I wrap the rmc.Response.Redirect(null) call in a lambda?&lt;/p&gt;&lt;p&gt;or call Expect.Call&amp;lt;Action&amp;lt;string&amp;gt;&amp;gt;(rmc.Response.Redirect)?&lt;/p&gt;&lt;p&gt;In either case, Reponse.Redirect always gets passed null, and the Text.EndsWith(&amp;quot;List.aspx&amp;quot;) constraint never passes. Even Is.NotNull() fails.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Mocking and testing for RedirectToAction</title><link>http://forums.asp.net/thread/2227607.aspx</link><pubDate>Wed, 12 Mar 2008 09:35:13 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2227607</guid><dc:creator>tgmdbm</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2227607.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2227607</wfw:commentRss><description>&lt;p&gt;What was the compiler error?&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Mocking and testing for RedirectToAction</title><link>http://forums.asp.net/thread/2227422.aspx</link><pubDate>Wed, 12 Mar 2008 08:16:57 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2227422</guid><dc:creator>CVertex</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2227422.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2227422</wfw:commentRss><description>&lt;p&gt;Howdy,&lt;br /&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Thanks for your response.&lt;/p&gt;&lt;p&gt;I am using partial mocks. I&amp;#39;m using ScottHa&amp;#39;s code he presented on his blog.&lt;/p&gt;&lt;p&gt;I couldn&amp;#39;t get your code to compile unless I wrapped the rmc.Response.Redirect(null) in a lambda, i.e. () =&amp;gt; rmc.Response.redirect(null)&lt;/p&gt;&lt;p&gt;When I do that, the constraint always fails. Rhino Mocks says that null is indeed passed to the Response.Redirect method. There&amp;#39;s is little I can do to make this pass.&lt;/p&gt;&lt;p&gt;Phil mentioned on his blog that this was a bug. Just out of curiosity? Where is the bug here? Is it that RedirectToAction is NOT public (i.e. mockable)?&lt;/p&gt;&lt;p&gt;Excuse my ignorance, I&amp;#39;m still wrapping my head around Rhino mocks.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;br /&gt;Regards,&lt;/p&gt;&lt;p&gt;-CV&lt;br /&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Mocking and testing for RedirectToAction</title><link>http://forums.asp.net/thread/2221406.aspx</link><pubDate>Sun, 09 Mar 2008 15:22:33 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2221406</guid><dc:creator>tgmdbm</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2221406.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2221406</wfw:commentRss><description>&lt;p&gt;You&amp;nbsp; are obviously creating Partial Mocks. What that means is, if you don&amp;#39;t setup an expectation on the mocked object for a particular method, then it will defer to the mocked objects original implementation.&lt;/p&gt;


&lt;pre class="coloredcode"&gt;        [Test]&lt;br /&gt;        [RollBack]&lt;br /&gt;        &lt;span class="kwd"&gt;public void&lt;/span&gt; CreateNormally()&lt;br /&gt;        {&lt;br /&gt;            var rmc = Controller();&lt;br /&gt;&lt;br /&gt;            &lt;span class="kwd"&gt;using&lt;/span&gt; ( mocks.Record() ) {&lt;br /&gt;                mocks.SetFakeControllerContext( rmc );&lt;br /&gt;                Expect.Call( rmc.Response.Redirect( &lt;span class="kwd"&gt;null&lt;/span&gt; ) )&lt;br /&gt;                    .Constraints( Text.EndsWith( &lt;span class="st"&gt;&amp;quot;List.aspx&amp;quot;&lt;/span&gt; ) );&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            &lt;span class="kwd"&gt;using&lt;/span&gt; ( mocks.Playback() ) {&lt;br /&gt;                rmc.Create( &lt;span class="st"&gt;&amp;quot;Sample Message&amp;quot; &lt;/span&gt;);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;b&gt;Expect.Call&lt;/b&gt; will setup the expectation on the Response mock object, and the call to &lt;b&gt;Contraints&lt;/b&gt; will ignore the null argument and test that it ends with &amp;quot;List.aspx&amp;quot;. You could use Text.Contains( &amp;quot;List&amp;quot; ) but that would break if &amp;quot;list&amp;quot; apeared anywhere else in the Url. You could of course implement your own AbstractContraint.&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Hope this helps&amp;nbsp;&lt;/p&gt;</description></item><item><title>Mocking and testing for RedirectToAction</title><link>http://forums.asp.net/thread/2221316.aspx</link><pubDate>Sun, 09 Mar 2008 13:18:18 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2221316</guid><dc:creator>CVertex</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2221316.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2221316</wfw:commentRss><description>&lt;p&gt;Howdy,&lt;/p&gt;&lt;p&gt;I just upgraded my little playground web app to Preview 2. I wrote alot of code using the first preview, so it&amp;#39;s taken me an hour or two to completely upgrade.&lt;/p&gt;&lt;p&gt;However, my controller tests fail :( Reliably, it&amp;#39;s the controller tests that are asserting that RedirectToAction was called.&lt;/p&gt;&lt;p&gt;Cos preview 2 supports controller mocking, I ditched the sub-class testing patterny thing and opted for the mocking.&lt;/p&gt;&lt;p&gt;Here&amp;#39;s one of my controller actions that uses RedirectToAction:&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class="coloredcode"&gt;&lt;b id="1"&gt;1    &lt;/b&gt;&lt;span class="kwd"&gt;public void&lt;/span&gt; Create(&lt;span class="kwd"&gt;string&lt;/span&gt; Message) {
&lt;b id="2"&gt;2    &lt;/b&gt;
&lt;b id="3"&gt;3    &lt;/b&gt;            &lt;span class="kwd"&gt;if&lt;/span&gt; (String.IsNullOrEmpty(Message)) {
&lt;b id="4"&gt;4    &lt;/b&gt;                &lt;span class="kwd"&gt;throw new&lt;/span&gt; ArgumentException(&lt;span class="st"&gt;&amp;quot;Message cannot be null or empty&amp;quot;&lt;/span&gt;);
&lt;b id="5"&gt;5    &lt;/b&gt;            }
&lt;b id="6"&gt;6    &lt;/b&gt;
&lt;b id="7"&gt;7    &lt;/b&gt;            var rm = &lt;span class="kwd"&gt;new&lt;/span&gt; ReminderMessage();
&lt;b id="8"&gt;8    &lt;/b&gt;            rm.Message = Message;
&lt;b id="9"&gt;9    &lt;/b&gt;
&lt;b id="10"&gt;10   &lt;/b&gt;            
&lt;b id="11"&gt;11   &lt;/b&gt;
&lt;b id="12"&gt;12   &lt;/b&gt;            db.ReminderMessages.InsertOnSubmit(rm);
&lt;b id="13"&gt;13   &lt;/b&gt;            db.SubmitChanges();
&lt;b id="14"&gt;14   &lt;/b&gt;
&lt;b id="15"&gt;15   &lt;/b&gt;            RedirectToAction(&lt;span class="st"&gt;&amp;quot;List&amp;quot;&lt;/span&gt; );
&lt;b id="16"&gt;16   &lt;/b&gt;        }
&lt;/pre&gt;&lt;pre class="coloredcode"&gt;For the ReminderMessagesController&lt;/pre&gt;&lt;pre class="coloredcode"&gt;My error unit tests run fine, cos they&amp;#39;re exception expecting.&lt;/pre&gt;&lt;pre class="coloredcode"&gt;But, my normal operation unit test fails,&lt;/pre&gt;&lt;pre class="coloredcode"&gt;&amp;nbsp;&amp;nbsp;&lt;pre class="coloredcode"&gt;[Test]
        [RollBack]
        &lt;span class="kwd"&gt;public void&lt;/span&gt; CreateNormally()
        {
            var rmc = Controller();
            &lt;span class="kwd"&gt;using&lt;/span&gt; (mocks.Record()) {
                mocks.SetFakeControllerContext(rmc);
            }
            &lt;span class="kwd"&gt;using&lt;/span&gt; (mocks.Playback()) {
                rmc.Create(&lt;span class="st"&gt;&amp;quot;Sample Message&amp;quot;&lt;/span&gt;);
            }
        }&lt;/pre&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="coloredcode"&gt;&amp;nbsp;with the MbUnit test execution exception:&lt;/pre&gt;&lt;table cellpadding="1" cellspacing="1"&gt;&lt;tr class="failureEven"&gt;&lt;td&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;ReminderMessagesControllerTests.SetUp.UpdateMessage&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;table id="EDAGAABABAAAAA" class="expandCollapse"&gt;&lt;tr class="failure-exception"&gt;&lt;td&gt;&lt;div&gt;&lt;table cellpadding="1" cellspacing="1"&gt;&lt;tr class="exceptionType"&gt;&lt;td&gt;&lt;strong&gt;Type:&lt;/strong&gt;System.NotImplementedException&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Message:&lt;/strong&gt;The method or operation is not implemented.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Source:&lt;/strong&gt;System.Web.Abstractions&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;TargetSite:Void Redirect(System.String)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;HelpLink:null&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;StackTrace:&lt;/strong&gt;&lt;br /&gt;&lt;pre class="stackTrace"&gt;   at System.Web.HttpResponseBase.Redirect(String url)&lt;br /&gt;   at HttpResponseBaseProxy2ad1c711cecc4e6da524bc5c50bdce13.Redirect_callback_20(String url)&lt;br /&gt;   at HttpResponseBaseProxy2ad1c711cecc4e6da524bc5c50bdce13.InvocationRedirect_32.InvokeMethodOnTarget()&lt;br /&gt;   at Castle.DynamicProxy.AbstractInvocation.Proceed()&lt;br /&gt;   at Rhino.Mocks.Impl.ReplayPartialMockState.DoMethodCall(IInvocation invocation, MethodInfo method, Object[] args)&lt;br /&gt;   at Rhino.Mocks.Impl.ReplayMockState.MethodCall(IInvocation invocation, MethodInfo method, Object[] args)&lt;br /&gt;   at Rhino.Mocks.MockRepository.MethodCall(IInvocation invocation, Object proxy, MethodInfo method, Object[] args)&lt;br /&gt;   at Rhino.Mocks.Impl.RhinoInterceptor.Intercept(IInvocation invocation)&lt;br /&gt;   at Castle.DynamicProxy.AbstractInvocation.Proceed()&lt;br /&gt;   at HttpResponseBaseProxy2ad1c711cecc4e6da524bc5c50bdce13.Redirect(String url)&lt;br /&gt;   at System.Web.Mvc.Controller.RedirectToAction(RouteValueDictionary values)&lt;br /&gt;   at System.Web.Mvc.Controller.RedirectToAction(String actionName)&lt;br /&gt;   at CN.Web.Controllers.ReminderMessagesController.Update(Int32 id) in C:\Projects\CharlesNicholas\CN.Web\Controllers\ReminderMessagesController.cs:line 78&lt;br /&gt;   at CN.Web.Test.ReminderMessagesControllerTests.UpdateMessage() in C:\Projects\CharlesNicholas\CN.Web.Test\ReminderMessagesControllerTests.cs:line 141&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&amp;nbsp;&lt;br /&gt;&lt;p&gt;Woh. that&amp;#39;s a deep stack trace. I&amp;#39;m not exactly sure what&amp;#39;s going on here, but I bet it has something to do with redirects trying to call a 301 on some part of System.Web that wasn&amp;#39;t mocked.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Okay, so how do I mock RedirectToAction when it isn&amp;#39;t public? I thought all of these actionable methods were going to be public to avoid the subclass testing patterny thingo - which involved alot of duplicated code.&lt;/p&gt;&lt;p&gt;Does someone know what I&amp;#39;m doing wrong? &lt;/p&gt;&lt;p&gt;Thanks,&lt;br /&gt;-CV &lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item></channel></rss>