<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Developer Flotsam &#187; MVC</title>
	<atom:link href="http://jakkaj.wordpress.com/tag/mvc/feed/" rel="self" type="application/rss+xml" />
	<link>http://jakkaj.wordpress.com</link>
	<description>Developer Flotsam - random stuff floating around?</description>
	<lastBuildDate>Wed, 16 May 2012 19:49:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='jakkaj.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/c69967a9056213792a3a7b47a6f573af?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Developer Flotsam &#187; MVC</title>
		<link>http://jakkaj.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://jakkaj.wordpress.com/osd.xml" title="Developer Flotsam" />
	<atom:link rel='hub' href='http://jakkaj.wordpress.com/?pushpress=hub'/>
		<item>
		<title>ASP.NET MVC Test</title>
		<link>http://jakkaj.wordpress.com/2008/01/04/aspnet-mvc-test/</link>
		<comments>http://jakkaj.wordpress.com/2008/01/04/aspnet-mvc-test/#comments</comments>
		<pubDate>Fri, 04 Jan 2008 06:08:50 +0000</pubDate>
		<dc:creator>Jordan</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://jakkaj.wordpress.com/2008/01/04/aspnet-mvc-test/</guid>
		<description><![CDATA[UPDATE: This article is rather old now &#8211; MVC Preview 3 is out and I suggest looking at the new testing stuff in that http://weblogs.asp.net/scottgu/archive/2008/05/27/asp-net-mvc-preview-3-release.aspx I&#8217;ve been playing with MVC for a couple of days now as part of my professional development at Readify &#8211; and this afternoon it was time to attack a bit [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jakkaj.wordpress.com&#038;blog=1986956&#038;post=21&#038;subd=jakkaj&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>UPDATE: This article is rather old now &#8211; MVC Preview 3 is out and I suggest looking at the new testing stuff in that <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  <a title="The Gu on MVC Preview 3" href="http://weblogs.asp.net/scottgu/archive/2008/05/27/asp-net-mvc-preview-3-release.aspx" target="_self">http://weblogs.asp.net/scottgu/archive/2008/05/27/asp-net-mvc-preview-3-release.aspx</a></p>
<p>I&#8217;ve been playing with MVC for a couple of days now as part of my professional development at Readify &#8211; and this afternoon it was time to attack a bit of testing.</p>
<p>So I cracked open <a title=" ASP.NET MVC Framework (Part 1)" href="http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx" target="_blank">Scott&#8217;s post on MVC</a> and zoomed in on the unit testing code he posted.</p>
<p>Now, because ASP.NET MVC is quite new (its CTP, not beta, not anything, just a preview &#8211; so its *real new*) the dev community is still poking around trying out this and that and in the case of testing, not having a real smooth ride.</p>
<p>In Scott&#8217;s post he uses a class called TestViewEngine, which allows him to instantiate and test the views defined in the test web app project, running asserts etc on the output. But this class doesn&#8217;t exist in the MVC stuff yet &#8211; that I can see anyway (or my Googling).</p>
<p>So I set out on a Google fest to try to get this test code to run&#8230; and it turns out it was just a little more difficult than just creating a TestViewEngine class. The final result make use of the excellent Rhino mocking framework and my own TestViewEngine implementation.</p>
<p>I got the mocking code from here: <a title="Writing Unit Tests For Controller Actions" href="http://haacked.com/archive/2007/12/09/writing-unit-tests-for-controller-actions.aspx" target="_blank">http://haacked.com/archive/2007/12/09/writing-unit-tests-for-controller-actions.aspx</a> a great article on the initial state of MVC testing. I then combine this code with Scott&#8217;s and some of my own for the final result. You can download Rhino Mocks from here: <a title="Rhino Mocks download" href="http://www.ayende.com/projects/rhino-mocks/downloads.aspx" target="_blank">http://www.ayende.com/projects/rhino-mocks/downloads.aspx</a>.</p>
<p>There are also some great posts here <a title="ASP.NET MVC - Simplified Controller Tests" href="http://www.persistall.com/" target="_blank">http://www.persistall.com/</a> which may help you out a bit.</p>
<p>Basically the code is as on haacked for the most part:</p>
<p><pre class="brush: csharp;"> 
 [TestMethod]
        public void AllForUser()
        {

            RouteTable.Routes.Add(new Route
            {
                Url = &quot;Snippet/Detail/[id]&quot;,
                RouteHandler = typeof(MvcRouteHandler)
            });

            SnippetController controller = new SnippetController();

            MockRepository mocks = new MockRepository();
            IHttpContext httpContextMock = mocks.DynamicMock&lt;IHttpContext&gt;();
            IHttpRequest requestMock = mocks.DynamicMock&lt;IHttpRequest&gt;();
            IHttpResponse responseMock = mocks.DynamicMock&lt;IHttpResponse&gt;();
            SetupResult.For(httpContextMock.Request).Return(requestMock);
            SetupResult.For(httpContextMock.Response).Return(responseMock);
            SetupResult.For(requestMock.ApplicationPath).Return(&quot;/&quot;);

            responseMock.Redirect(&quot;/Snippet/Detail/1&quot;);

            RouteData routeData = new RouteData();
            routeData.Values.Add(&quot;Action&quot;, &quot;SnippetDetail&quot;);
            routeData.Values.Add(&quot;Controller&quot;, &quot;Snippet&quot;);

            ControllerContext contextMock = new
              ControllerContext(httpContextMock, routeData, controller);
            mocks.ReplayAll();

            controller.GetType().GetProperty(&quot;TempData&quot;).SetValue(controller, new TempDataDictionary(httpContextMock), null);

            controller.ControllerContext = contextMock;

            TestViewEngine tve = new TestViewEngine();

            controller.ViewFactory = tve;

            controller.SnippetDetail(1);

            Assert.AreEqual(typeof(Snippet), tve.View.ViewData.GetType(), &quot;Snippet object passed to view&quot;);
            Assert.AreEqual(1, tve.View.GetViewData&lt;Snippet&gt;().SnippetId, &quot;Correct Snippet ID Processed&quot;);
            Assert.AreEqual(&quot;SnippetDetail&quot;, tve.View.ViewName, &quot;Correct view rendered&quot;);
        }

    }
</pre></p>
<p>The only thing I had to add here was the following line:</p>
<p><pre class="brush: csharp;">&lt;/pre&gt;
&lt;pre&gt;controller.GetType().GetProperty(&quot;TempData&quot;).SetValue(controller, new TempDataDictionary(httpContextMock), null);
</pre></p>
<p>The problem was that the RenderView call in my ControllerAction was throwing a null argument exception because TempData on the object was null and is not allowed to be &#8211; thanks to a comment by Alexey on haacked for this!</p>
<p>Then I created my own little TestViewEngine class to keep in line with what Scott was doing in his post:</p>
<p><pre class="brush: csharp;"> 

 public class TestViewEngine : IViewFactory
    {

        TestView _view;

        #region IView Members

        #endregion

        #region IViewFactory Members

        public IView CreateView(ControllerContext controllerContext, string viewName, string masterName, object viewData)
        {
            _view = new TestView(controllerContext, viewName, masterName, viewData);
            return _view;
        }

        public TestView View
        {
            get
            {
                return _view;
            }
        }

        #endregion
    }

    public class TestView : IView, IViewDataContainer
    {
        ControllerContext _controllerContext;
        string _viewName;
        string _masterName;
        object _viewData;

        public TestView(ControllerContext controllerContext, string viewName, string masterName, object viewData)
        {
            _controllerContext = controllerContext;
            _viewName = viewName;
            _masterName = masterName;
            _viewData = viewData;
        }

        public T GetViewData&lt;T&gt;()
        {
            return (T)_viewData;
        }

        public string ViewName
        {
            get
            {
                return _viewName;
            }
        }

        #region IView Members

        public void RenderView(ViewContext viewContext)
        {
            //throw new NotImplementedException();
        }

        #endregion

        #region IViewDataContainer Members

        public object ViewData
        {
            get
            {
                return _viewData;
            }
        }

        #endregion
    }
</pre></p>
<p>With this code in place you should be able to correctly run the asserts as in Scott&#8217;s article.</p>
<p>From what I have read there are going to be a lot of additions in the coming versions that will assist with testing &#8211; hopefully this includes things to assist with mocking the View requests etc. For now at least we can run some testing code to get us through.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/jakkaj.wordpress.com/21/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/jakkaj.wordpress.com/21/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jakkaj.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jakkaj.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jakkaj.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jakkaj.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jakkaj.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jakkaj.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jakkaj.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jakkaj.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jakkaj.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jakkaj.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jakkaj.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jakkaj.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jakkaj.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jakkaj.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jakkaj.wordpress.com&#038;blog=1986956&#038;post=21&#038;subd=jakkaj&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jakkaj.wordpress.com/2008/01/04/aspnet-mvc-test/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/310d76b78db597d9c9d0066df9654e51?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Jordan</media:title>
		</media:content>
	</item>
		<item>
		<title>CodeJAK Designs</title>
		<link>http://jakkaj.wordpress.com/2008/01/03/codejak-designs/</link>
		<comments>http://jakkaj.wordpress.com/2008/01/03/codejak-designs/#comments</comments>
		<pubDate>Wed, 02 Jan 2008 22:33:18 +0000</pubDate>
		<dc:creator>Jordan</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[CodeJAK]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://jakkaj.wordpress.com/2008/01/03/codejak-designs/</guid>
		<description><![CDATA[As part of my MVC PD this week I&#8217;m creating a real website that does real things. This website is called CodeJAK and I hope to have it go live soon. Here is the initial design &#8220;CodeJAK design by Alex Knight&#8221; &#8211; its cool as! So here is the low-down: CodeJAK is a site that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jakkaj.wordpress.com&#038;blog=1986956&#038;post=19&#038;subd=jakkaj&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As part of my MVC PD this week I&#8217;m creating a real website that does real things.</p>
<p>This website is called CodeJAK and I hope to have it go live soon.</p>
<p>Here is the initial design &#8220;<a href="http://jakkaj.wordpress.com/2008/01/03/codejak-designs/codejak-design-by-alex-knight/" rel="attachment wp-att-20" title="CodeJAK design by Alex Knight">CodeJAK design by Alex Knight</a>&#8221; &#8211; its cool as!</p>
<p>So here is the low-down:</p>
<p>CodeJAK is a site that allows you to store code snippets &#8211; don&#8217;t let me lose you there, it&#8217;s got some cool features (okay, it *will* have some cool features).</p>
<p>First and foremost my plans for CodeJAK are to create a Visual Studio plugin that manages your snippets. All snippets you store in CodeJAK are stored on-line &#8211; so when you install CodeJAK on another machine and log in, all your snippets will be synched between your machines automatically.</p>
<p>The next  feature is that you can publish your snippets if you like, i.e. share them. Then others can search for published snippets (in VS, or on the accompanying website).</p>
<p>Other features include community features like tagging snippets, comments on snippets, RSS feeds (subs to a feed based on user or tags or some other search query) &#8211; you get the idea (don&#8217;t steal it! &#8211; if you think its good then leave a comment and help me out!)</p>
<p>P.S. If you have heard of this idea before (which I havn&#8217;t) then please let me know (let me down gently).</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/jakkaj.wordpress.com/19/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/jakkaj.wordpress.com/19/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jakkaj.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jakkaj.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jakkaj.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jakkaj.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jakkaj.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jakkaj.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jakkaj.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jakkaj.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jakkaj.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jakkaj.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jakkaj.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jakkaj.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jakkaj.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jakkaj.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jakkaj.wordpress.com&#038;blog=1986956&#038;post=19&#038;subd=jakkaj&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jakkaj.wordpress.com/2008/01/03/codejak-designs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/310d76b78db597d9c9d0066df9654e51?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Jordan</media:title>
		</media:content>
	</item>
	</channel>
</rss>
