<?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/"
	>

<channel>
	<title>Trevor Power &#187; TDD</title>
	<atom:link href="http://blog.trevorpower.com/index.php/tag/tdd/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.trevorpower.com</link>
	<description>Software development and other thoughts</description>
	<lastBuildDate>Fri, 20 Aug 2010 07:33:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Not mocking the HttpContext?</title>
		<link>http://blog.trevorpower.com/index.php/not-mocking-the-httpcontext/</link>
		<comments>http://blog.trevorpower.com/index.php/not-mocking-the-httpcontext/#comments</comments>
		<pubDate>Wed, 21 Jan 2009 20:42:00 +0000</pubDate>
		<dc:creator>trevorpower</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[ASP.Net MVC]]></category>
		<category><![CDATA[Mocking]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://trevorpower.com/blog/?p=28</guid>
		<description><![CDATA[Someone asked me a question recently about mocking, and I had to say I didn&#8217;t have much experience with it. I found this answer a bit odd myself as I&#8217;ve been doing a lot of TDD with an ASP.Net MVC application. I&#8217;d seen lots of people talking about mocking the HttpContext and wondered &#8220;Why haven&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.trevorpower.com%2Findex.php%2Fnot-mocking-the-httpcontext%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.trevorpower.com%2Findex.php%2Fnot-mocking-the-httpcontext%2F" height="61" width="51" /></a></div><p>Someone asked me a question recently about mocking, and I had to say I didn&#8217;t have much experience with it. I found this answer a bit odd myself as I&#8217;ve been doing a lot of TDD with an ASP.Net MVC application. I&#8217;d seen lots of people talking about mocking the HttpContext and wondered &#8220;Why haven&#8217;t<span class="Apple-style-span" style="font-weight: bold;"> <span class="Apple-style-span" style="font-weight: normal;">I</span></span> had to do this?&#8221;.
<div></div>
<div>The first time I started TDD, I was working on converting an existing ASP.Net application to ASP.Net MVC. Most of my controller actions checked the current security principle in the context, so I immediately ran into problems when trying to test these.</div>
<div></div>
<div>I didn&#8217;t know much about MVC or TDD so used what I did know. I knew about a powerful component of MVC called an action invoker, that could be overridden to handle some parameter stuff. I found that I could easily create an ActionInvoker that would populate parameters of a certain type (namely IPrincipal) using the following code:</div>
<pre name="code" class="c-sharp:nocontrols:nogutter" cols="80" rows="10">
public class ActionInvoker : ControllerActionInvoker
{
   protected override object GetParameterValue(System.Reflection.ParameterInfo parameterInfo)
   {
      if (parameterInfo.ParameterType == typeof(IPrincipal))
         return HttpContext.Current.User;

      return base.GetParameterValue(parameterInfo);
   }
}
</pre>
<p>
<div>And put the following into my controller constructors:</div>
<pre name="code" class="c-sharp:nocontrols:nogutter" cols="80" rows="10">
public MyController()
{
   ActionInvoker = new ActionInvokers.ActionInvoker();
}
</pre>
<div>This made it easy to test my controller actions. I just needed to mock a simple IPrincipal. I used a similar solution when my file upload controller needed access to HttpContext.Current.Request.Files.</div>
<div></div>
<div>At the moment my code only depends on a few simple objects that come from the HttpContext and not the context itself. Surely this is better, if not please comment. I&#8217;m going to change the above to conform with everyone else by mocking the HttpContext but the only reason I see for doing this, is that the above action invoker is not testable. Is this the only reason?</div>
<div></div>
<div>Before you point it out to me, I have recently moved most of my security code into AuthorizeAttributes. Now my unit tests for invalid calls (security wise) to controller actions all fail but that&#8217;s for a future post.</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.trevorpower.com/index.php/not-mocking-the-httpcontext/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>What&#039;s up with the Tadmap project?</title>
		<link>http://blog.trevorpower.com/index.php/whats-up-with-the-tadmap-project/</link>
		<comments>http://blog.trevorpower.com/index.php/whats-up-with-the-tadmap-project/#comments</comments>
		<pubDate>Sun, 11 Jan 2009 16:19:00 +0000</pubDate>
		<dc:creator>trevorpower</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tadmap]]></category>
		<category><![CDATA[ASP.Net MVC]]></category>
		<category><![CDATA[Image Hosting]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://trevorpower.com/blog/?p=25</guid>
		<description><![CDATA[If you&#8217;ve been following the Tadmap blog then you might be wondering why there haven&#8217;t been any updates since November. Well here&#8217;s why.
Before Christmas I decided to try out the new ASP.Net MVC framework, for no other reason than wanting to learn more about it. My initial impression was that it would be ideal for [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.trevorpower.com%2Findex.php%2Fwhats-up-with-the-tadmap-project%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.trevorpower.com%2Findex.php%2Fwhats-up-with-the-tadmap-project%2F" height="61" width="51" /></a></div><p>If you&#8217;ve been following the <a href="http://blog.tadmap.com/">Tadmap blog</a> then you might be wondering why there haven&#8217;t been any updates since November. Well here&#8217;s why.</p>
<p>Before Christmas I decided to try out the new ASP.Net MVC framework, for no other reason than wanting to learn more about it. My initial impression was that it would be ideal for <a href="http://tadmap.com/">Tadmap</a>, so I decided to go for it. The change over meant refactoring all the pages I already had into controller and views, and I got 90% there very quickley. As I had never used MVC before I started following Rob Conery&#8217;s <a href="http://blog.wekeroad.com/mvc-storefront/mvc-storefront-part-1/">MVC Storefront</a> series to make sure I was doing things right. This may or may not have been a mistake.</p>
<p>First, he was using a fancy new version of the Repository pattern which I liked the look of very much, this lead to even more refactoring and learning more about LINQ on the way.</p>
<p>I tried to ignore the Test Driven Development aspect of what Rob was doing, but eventually I downloaded <a href="http://www.nunit.org/index.php">Nunit</a> just to try my hands at writing an automated test. Straight away I was hooked on TDD. I tried limiting TDD to just new code but to make the new code testable meant refactoring the old code to reduce dependencies.</p>
<p>It&#8217;s taken a lot longer then I wanted but I am having a lot of fun doing it. My code is clean and loosely coupled and I have over a hundred unit tests and a bunch of integration tests that I can fire with one click. </p>
<p>Even though I have no boss and as yet no users, I have still run into the age old problem of doing it right versus getting it done. There is the ultimate balance to be made between making things perfect while achieving the goals and real world features that help our moral and motivation. It&#8217;s starting to bother me that I haven&#8217;t been able to add any new features in over a month.</p>
<p>So in the next few weeks I hope to get an, albeit imperfect, ASP.Net MVC version of the application up on the live server. I&#8217;ll then be in a position to iron out the last few post refactoring bugs or implement a cool new feature when I need the motivation to keep going.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.trevorpower.com/index.php/whats-up-with-the-tadmap-project/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>More blogging in 2009</title>
		<link>http://blog.trevorpower.com/index.php/more-blogging-in-2009/</link>
		<comments>http://blog.trevorpower.com/index.php/more-blogging-in-2009/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 20:46:00 +0000</pubDate>
		<dc:creator>trevorpower</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[ASP.Net MVC]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[Tadmap]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://trevorpower.com/blog/?p=24</guid>
		<description><![CDATA[It&#8217;s a new year, a time to start those good habits again. One thing I want to start doing this year is to write more blog posts. Four blog posts in November, that&#8217;s pretty good going for me but then nothing in December. The reason I hesitate when it comes to publishing stuff is that I&#8217;m [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.trevorpower.com%2Findex.php%2Fmore-blogging-in-2009%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.trevorpower.com%2Findex.php%2Fmore-blogging-in-2009%2F" height="61" width="51" /></a></div><div>It&#8217;s a new year, a time to start those good habits again. One thing I want to start doing this year is to write more blog posts. Four blog posts in November, that&#8217;s pretty good going for me but then nothing in December. The reason I hesitate when it comes to publishing stuff is that I&#8217;m not very good at writing. But that&#8217;s not going to change with out some practice.</div>
<div></div>
<div>The other reason not to publish something is the feeling that it&#8217;s not worth saying unless it&#8217;s going to contribute something that other people actually want. But as you can see from this post, I don&#8217;t care about that anymore.  I&#8217;m just going to say stuff and get things off my chest.</div>
<div></div>
<div>So what am I going to write about? I will try to keep it somewhat technical in nature. Professionally I work with ASP.Net 2.0 but on my <a href="http://tadmap.com/"><span class="blsp-spelling-error" id="SPELLING_ERROR_0">Tadmap</span></a> project I&#8217;m getting to work with some cool new stuff like <a href="http://msdn.microsoft.com/en-us/vcsharp/aa336809.aspx">C# 3.0</a>, <a href="http://www.asp.net/mvc/">ASP.net <span class="blsp-spelling-error" id="SPELLING_ERROR_1">MVC</span></a>, <a href="http://msdn.microsoft.com/en-us/vbasic/aa904594.aspx"><span class="blsp-spelling-error" id="SPELLING_ERROR_2">LINQ</span></a> and <a href="http://en.wikipedia.org/wiki/Test-driven_development">Test Driven Development</a>. All of which may be food for future blog posts.</div>
<div>
<div></div>
<div>As you can see on my blog page, I have added my twitter updates. I&#8217;ve had a twitter account for a while now but just started using it lately. This is just another way for me to practice writing. I think this whole twitter lark <span class="blsp-spelling-error" id="SPELLING_ERROR_3">mayb</span>e just a fad but I&#8217;ll give it go for while and see what happens.</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.trevorpower.com/index.php/more-blogging-in-2009/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
