<?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:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Tim Ross - .NET Developer</title>
	<atom:link href="http://timross.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://timross.wordpress.com</link>
	<description>Software development using the .NET framework</description>
	<lastBuildDate>Wed, 09 Sep 2009 07:00:13 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='timross.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/4b946a7f8e6be8cff70990a4ff79b8ac?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Tim Ross - .NET Developer</title>
		<link>http://timross.wordpress.com</link>
	</image>
			<item>
		<title>Success, But At What Price?</title>
		<link>http://timross.wordpress.com/2009/09/08/success-but-at-what-price/</link>
		<comments>http://timross.wordpress.com/2009/09/08/success-but-at-what-price/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 22:52:08 +0000</pubDate>
		<dc:creator>timross</dc:creator>
				<category><![CDATA[Software Practices]]></category>

		<guid isPermaLink="false">http://timross.wordpress.com/?p=263</guid>
		<description><![CDATA[A friend asked me recently, “do all these good organisational and development practices really make that much of a difference to the successful outcome of a project?”. We all know following good practices improves the lives of those involved, but do they really help to achieve a business success? After all, some extremely-late, over-budget, bloated, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timross.wordpress.com&blog=2219574&post=263&subd=timross&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>A friend asked me recently, “do all these good organisational and development practices really make that much of a difference to the successful outcome of a project?”. We all know following good practices improves the lives of those involved, but do they really help to achieve a business success? After all, some extremely-late, over-budget, bloated, misguided and poor-quality software development projects do go on to make the business a lot of money, therefore can be deemed to be successful. But at what price? Projects like this often leave a path of destruction behind them. The stress, political battles, low morale, fear, late nights, strained relationships, blood, sweat and tears of the people who worked hard under pressure, following poor organisational and development practices. That’s the difference. Good practices not only help to achieve a successful business outcome, they also help to build a good working environment. There is a human factor to the successful outcome of a project. Let’s not forget that.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timross.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timross.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timross.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timross.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timross.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timross.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timross.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timross.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timross.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timross.wordpress.com/263/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timross.wordpress.com&blog=2219574&post=263&subd=timross&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://timross.wordpress.com/2009/09/08/success-but-at-what-price/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">timross</media:title>
		</media:content>
	</item>
		<item>
		<title>Internal And External Collaborators</title>
		<link>http://timross.wordpress.com/2009/09/02/internal-and-external-collaborators/</link>
		<comments>http://timross.wordpress.com/2009/09/02/internal-and-external-collaborators/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 08:28:40 +0000</pubDate>
		<dc:creator>timross</dc:creator>
				<category><![CDATA[Behaviour Driven Development]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software Practices]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://timross.wordpress.com/?p=242</guid>
		<description><![CDATA[The Single Responsibility Principal (SRP) states that every object should have a single responsibility, and that all its services should be aligned with that responsibility. By separating object responsibilities we are able to achieve a clear Separation of Concerns. Objects need to collaborate with each other in order to perform a behaviour. I find I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timross.wordpress.com&blog=2219574&post=242&subd=timross&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The <a href="http://en.wikipedia.org/wiki/Single_responsibility_principle" target="_blank">Single Responsibility Principal</a> (SRP) states that every object should have a single responsibility, and that all its services should be aligned with that responsibility. By separating object responsibilities we are able to achieve a clear <a href="http://en.wikipedia.org/wiki/Separation_of_concerns" target="_blank">Separation of Concerns</a>. Objects need to collaborate with each other in order to perform a behaviour. I find I use two distinct styles of collaboration with other objects which I have called <strong>internal and external collaborators</strong>.</p>
<p>The principals of object collaboration are nothing new, but I have found that defining these roles has helped me to better understand how to design and test the behaviour of objects.</p>
<h3>External Collaborators</h3>
<p>External collaborators are objects that provide a service or resource to an object but are not directly controlled by the object. They are passed to an object by <a href="http://martinfowler.com/articles/injection.html#FormsOfDependencyInjection" target="_blank">dependency injection</a> or through a <a href="http://martinfowler.com/articles/injection.html#UsingAServiceLocator" target="_blank">service locator</a>. An object makes calls to its external collaborators to perform actions or retrieve data. When testing an object, any external collaborators are <a href="http://xunitpatterns.com/Test%20Stub.html" target="_blank">stubbed-out</a>. We can then write tests that perform an action, then determine if the right calls were made to the external object.</p>
<p>Examples of external collaborator objects include: services, repositories, presenters, framework classes, email senders, loggers and file system wrappers.</p>
<p>We are interested in testing how we interact with the external collaborator and not how it affects the behaviour of our object. For example, if we are testing a controller that retrieves a list of customers from a repository, we want to know that we have asked the repository for a list of customers, but we are not concerned that the repository returns the correct customers (this is a test for the repository itself). Of course, we might need some particular customer objects returned by the stub for the purpose of testing the behaviour of the controller. These customer objects then become internal collaborators, which we’ll come to next.</p>
<p>External collaborators can be registered with an <a href="http://martinfowler.com/articles/injection.html#InversionOfControl" target="_blank">IoC container</a> to manage the creation and lifecycle of the object, and to provide an instance to dependent objects.</p>
<h3>Internal Collaborators</h3>
<p>Internal collaborators have a smaller scope than external collaborators. They are used in the context of the local object to provide functions or hold state. An object and its internal collaborators work together closely and should be treated as a single unit of behaviour.</p>
<p>Examples of internal collaborators include: DTOs, domain entities, view-models, utilities, system types and extension methods.</p>
<p>When testing an object with internal collaborators, we are interested in the effect on behaviour, not the interaction with the object. Therefore we shouldn’t stub-out internal collaborators. We don’t care how we interact with them, just that the correct behaviour occurs.</p>
<p>These objects are not affected by external influences, such as a database, email server, or file system. They are also not volatile or susceptible to environmental changes, such as a web request context. Therefore, they should not require any special context setup before testing.</p>
<p>We don’t get passed an instance of a internal collaborator through dependency injection, instead they may be passed to us by an external collaborator (e.g. a repository returning an entity), or we create an instance within our own object when we need it (such as a DTO).</p>
<p>By understanding the roles and responsibilities of collaboration between objects, our design becomes clearer and tests are more focused and easier to maintain.</p>
<p><a href="http://timross.files.wordpress.com/2009/09/object_collaborators.png"><img title="object_collaborators" style="display:inline;border-width:0;" height="383" alt="object_collaborators" src="http://timross.files.wordpress.com/2009/09/object_collaborators_thumb.png?w=504&#038;h=383" width="504" border="0" /></a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timross.wordpress.com/242/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timross.wordpress.com/242/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timross.wordpress.com/242/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timross.wordpress.com/242/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timross.wordpress.com/242/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timross.wordpress.com/242/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timross.wordpress.com/242/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timross.wordpress.com/242/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timross.wordpress.com/242/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timross.wordpress.com/242/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timross.wordpress.com&blog=2219574&post=242&subd=timross&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://timross.wordpress.com/2009/09/02/internal-and-external-collaborators/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">timross</media:title>
		</media:content>

		<media:content url="http://timross.files.wordpress.com/2009/09/object_collaborators_thumb.png" medium="image">
			<media:title type="html">object_collaborators</media:title>
		</media:content>
	</item>
		<item>
		<title>Continuous Testing In .NET</title>
		<link>http://timross.wordpress.com/2009/08/04/continuous-testing-in-net/</link>
		<comments>http://timross.wordpress.com/2009/08/04/continuous-testing-in-net/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 11:46:21 +0000</pubDate>
		<dc:creator>timross</dc:creator>
				<category><![CDATA[Testing]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://timross.wordpress.com/?p=230</guid>
		<description><![CDATA[The Test-Driven Development cycle of red-green-refactor gets you into a rhythm of writing a failing test, making it pass and then refactoring. It is important that we get feedback early if something is broken so we can keep this rhythm going. Stopping to run tests and wait for the result can impact this rhythm and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timross.wordpress.com&blog=2219574&post=230&subd=timross&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The Test-Driven Development cycle of <a href="http://jamesshore.com/Blog/Red-Green-Refactor.html" target="_blank">red-green-refactor</a> gets you into a rhythm of writing a failing test, making it pass and then refactoring. It is important that we get feedback early if something is broken so we can keep this rhythm going. Stopping to run tests and wait for the result can impact this rhythm and distract our focus on the next step. </p>
<p>The concept of continuous testing came from <a href="http://pag.csail.mit.edu/pubs/David-Saff.html" target="_blank">research</a> carried out by the <a href="http://groups.csail.mit.edu/pag/" target="_blank">Program Analysis Group</a> at MIT. They found that continuously running tests increased developer productivity and reduced waste. You can find more information about continuous testing in <a href="http://blog.objectmentor.com/articles/2007/09/20/continuous-testing-explained" target="_blank">this blog post</a> by Ben Rady.</p>
<h3>Tools For Continuous Testing</h3>
<p>There are a number of tools available that support continuous testing. Ruby has <a href="http://www.nateclark.com/articles/2008/09/17/_autotest_-is-now-_autospec_-how-to-set-up-autospec-for-rspec-and-rails-with-zentest" target="_blank">AutoSpec</a>, a command-line continuous testing tool. Java has <a href="http://www.infinitest.org/" target="_blank">Infinitest</a>, a plug-in for Ecplise and IntelliJ. In .NET, <a href="http://averyblog.com/" target="_blank">James Avery</a> has been working on <a href="http://code.google.com/p/autotestnet/" target="_blank">AutoTest.NET</a> and I was involved in a project to write a Visual Studio add-in called <a href="http://quicktest.codeplex.com/" target="_blank">QuickTest</a>. The main problem I have found with using these tools for .NET development is the complexity of real-world project structures. Whenever I’d try to use QuickTest on real projects, I found I was dealing with very different project structures, test configurations and naming conventions. It was really difficult to factor all these configuration scenarios into a tool that is designed to &quot;discover&quot; which unit tests to continuously run.</p>
<p>That gave me the idea for <a href="http://code.google.com/p/autobuildtool/" target="_blank">AutoBuild</a>.</p>
<h3>Introducing AutoBuild</h3>
<p>AutoBuild is a continuous testing tool for .NET that runs a <a href="http://nant.sourceforge.net/" target="_blank">NAnt</a> script whenever a file is saved. You simply tell AutoBuild to watch a particular folder and give it a simple NAnt script to run whenever a file changes. The advantage of this approach is that all the complexity in customising a continuous testing tool for your project is contained within the NAnt script. The NAnt script is likely to be a small subset of an actual build script. For example, you might not want tests that hit the database to be run on every save, so you could add a &quot;DatabaseTest&quot; attribute to your test and configure the NAnt script to ignore all tests with that attribute. </p>
<p>If you aren&#8217;t familiar with NAnt, don&#8217;t worry. A default build file is provided and you only need to modify the solution path and unit test assembly path properties. </p>
<p>Currently, the test failure output in AutoBuild only supports the <a href="http://nant.sourceforge.net/release/latest/help/tasks/nunit2.html" target="_blank">NUnit task</a>. I plan to add support for other unit test frameworks in the near future. I am also interested in adding support for <a href="http://rake.rubyforge.org/" target="_blank">Rake</a> build scripts.</p>
<h3>Using AutoBuild</h3>
<p>You can find the source code for AutoBuild here:    <br /><a href="http://code.google.com/p/autobuildtool/" target="_blank">http://code.google.com/p/autobuildtool/</a></p>
<p>To get started, get the source and run the default.build.cmd file. This will run the build and create an <strong>output</strong> folder that contains the AutoBuild assemblies, along with a sample build script and command file. You can copy these to your own project and customise the build file for your solution.</p>
<p>To run the &quot;<a href="http://en.wikipedia.org/wiki/Eating_one's_own_dog_food" target="_blank">dog food</a>&quot; sample, simply run the autobuild.cmd file in the <strong>root</strong> AutoBuild folder (not the one in the output folder). This will open AutoBuild and start watching the source directory. Then open the AutoBuild solution and modify any .cs file. This should kick-off the build and run the tests. Mess around with the code to watch the build fail. Note that this autobuild.build script is configured to only run tests <strong>not</strong> marked with &quot;integration&quot;.</p>
<p>AutoBuild will produce an output with build errors and failing tests in red and successful builds and test runs in green. You can change the output colours by modifying the log4net settings in the AutoBuild.Console.exe.config file. You can also switch on debug output by changing the log level to debug.</p>
<p><a href="http://timross.files.wordpress.com/2009/08/autobuild.png"><img title="autobuild" style="display:inline;border-width:0;" height="289" alt="autobuild" src="http://timross.files.wordpress.com/2009/08/autobuild_thumb.png?w=504&#038;h=289" width="504" border="0" /></a> </p>
<p>AutoBuild is ideally suited to a dual-monitor set up, with Visual Studio in one monitor and AutoBuild in the other. This allows you to focus on writing code and check the status of the build at a glance. I would like to integrate the console into Visual Studio for cases when you only have one monitor (e.g. working on a laptop). This might involve writing a Visual Studio add-in that allows you to load the console into the IDE.</p>
</p>
<p>Please submit any issues to the <a href="http://code.google.com/p/autobuildtool/" target="_blank">project on Google Code</a>. If you have any comments or suggestions, then please feel free to <a href="http://www.timross.info/contact/" target="_blank">contact me</a>.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timross.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timross.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timross.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timross.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timross.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timross.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timross.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timross.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timross.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timross.wordpress.com/230/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timross.wordpress.com&blog=2219574&post=230&subd=timross&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://timross.wordpress.com/2009/08/04/continuous-testing-in-net/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">timross</media:title>
		</media:content>

		<media:content url="http://timross.files.wordpress.com/2009/08/autobuild_thumb.png" medium="image">
			<media:title type="html">autobuild</media:title>
		</media:content>
	</item>
		<item>
		<title>Services Are Not Objects</title>
		<link>http://timross.wordpress.com/2009/06/06/services-are-not-objects/</link>
		<comments>http://timross.wordpress.com/2009/06/06/services-are-not-objects/#comments</comments>
		<pubDate>Sat, 06 Jun 2009 15:26:57 +0000</pubDate>
		<dc:creator>timross</dc:creator>
				<category><![CDATA[SOA]]></category>
		<category><![CDATA[Software Practices]]></category>

		<guid isPermaLink="false">http://timross.wordpress.com/?p=216</guid>
		<description><![CDATA[Many .NET applications I see that have a so-called Service-Oriented Architecture (SOA) use a technology such as Windows Communication Foundation (WCF) to treat services as if they were local objects. You call methods on the remote object in the same way as you would call a local object, only rather than executing locally, the request [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timross.wordpress.com&blog=2219574&post=216&subd=timross&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Many .NET applications I see that have a so-called <a href="http://en.wikipedia.org/wiki/Service-oriented_architecture" target="_blank">Service-Oriented Architecture</a> (SOA) use a technology such as <a href="http://msdn.microsoft.com/en-us/netframework/aa663324.aspx" target="_blank">Windows Communication Foundation</a> (WCF) to treat services as if they were local objects. You call methods on the remote object in the same way as you would call a local object, only rather than executing locally, the request is sent to a remote service for processing which <em>may</em> then return a response. This is known as a <a href="http://en.wikipedia.org/wiki/Remote_procedure_call" target="_blank">Remote Procedure Call</a>, or RPC. Often these calls can cause the application to hang while waiting for a response. The usual way to handle this is to call the service method asynchronously, providing a method to call when a response comes back. This allows your application to continue processing after the request is made.</p>
<p>Sounds simple enough, but I have found these direct request-response calls can lead to a fragile and unreliable application that is tightly-coupled to the services it calls. If for some reason a service is not available, your application may stop functioning. Sure, you can build in error-handling, but it then becomes the responsibility of your application to manage the dependency on the service.</p>
<p>Recently, <a href="http://thesleepydev.co.uk/" target="_blank">Jennifer Smith</a> and I were discussing the unreliable nature of these architectures on Twitter, when <a href="http://www.udidahan.com/" target="_blank">Udi Dahan</a>, SOA specialist and creator of <a href="http://www.nservicebus.com/" target="_blank">NServiceBus</a>, pointed us to a <a href="http://www.udidahan.com/2009/05/25/a-queue-isnt-an-implementation-detail/" target="_blank">recent blog post</a> of his that explains why we shouldn’t call services as if they were real objects. Udi suggests that there is a better way to handle calls to services and that is to use a <a href="http://en.wikipedia.org/wiki/Message_queue" target="_blank">message queue</a>. He also makes the point that we need to <strong>stop treating services as local objects</strong> and use messaging as in integral part of the application architecture:</p>
<blockquote><p>A queue isn’t an implementation detail. It’s the primary architectural abstraction of a distributed system.</p>
</blockquote>
<p>So, if you’re developing a distributed application, use a <a href="http://msdn.microsoft.com/en-us/library/ms978583.aspx" target="_blank">message bus</a> to communicate between applications. The message bus is responsible for transporting messages between applications. When you use a message bus, the application that sends a message is no longer coupled to the receiver.</p>
<p>I am currently converting a fragile request-response service-based application to use messaging with the <a href="http://www.nservicebus.com/" target="_blank">NServiceBus</a> message bus. I hope to significantly improve the performance and robustness of the application by making messaging a first-class citizen in the architecture, and not just an abstraction.</p>
<p>For more information on messaging and NServiceBus, check out:</p>
<ul>
<li><a href="http://www.nservicebus.com/Overview.aspx" target="_blank">An overview of NServiceBus</a> </li>
<li><a href="http://www.udidahan.com/category/nservicebus/" target="_blank">Udi Dahan’s blog</a> </li>
</ul>
<p>This book also contains excellent information on designing and developing messaging solutions:</p>
<ul>
<li><a href="http://www.amazon.com/Enterprise-Integration-Patterns-Designing-Addison-Wesley/dp/0321200683" target="_blank">Enterprise Integration Patterns</a> </li>
</ul>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timross.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timross.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timross.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timross.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timross.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timross.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timross.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timross.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timross.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timross.wordpress.com/216/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timross.wordpress.com&blog=2219574&post=216&subd=timross&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://timross.wordpress.com/2009/06/06/services-are-not-objects/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">timross</media:title>
		</media:content>
	</item>
		<item>
		<title>Features and Specs</title>
		<link>http://timross.wordpress.com/2009/05/19/features-and-specs/</link>
		<comments>http://timross.wordpress.com/2009/05/19/features-and-specs/#comments</comments>
		<pubDate>Tue, 19 May 2009 13:17:46 +0000</pubDate>
		<dc:creator>timross</dc:creator>
				<category><![CDATA[Behaviour Driven Development]]></category>
		<category><![CDATA[BDD]]></category>

		<guid isPermaLink="false">http://timross.wordpress.com/?p=205</guid>
		<description><![CDATA[I’m going to take a short diversion from my series on BDD with ASP.NET MVC to talk about the difference between Features and Specs in Behaviour-Driven Development.
I am currently reading the beta version of The RSpec Book. This is an excellent book that covers doing BDD in Ruby using RSpec and Cucumber. From reading this [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timross.wordpress.com&blog=2219574&post=205&subd=timross&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I’m going to take a short diversion from my series on <a href="http://timross.wordpress.com/2009/05/06/using-behaviour-driven-development-with-asp-net-mvc-part-2/">BDD with ASP.NET MVC</a> to talk about the difference between Features and Specs in Behaviour-Driven Development.</p>
<p>I am currently reading the beta version of <a href="http://www.pragprog.com/titles/achbd/the-rspec-book" target="_blank">The RSpec Book</a>. This is an excellent book that covers doing BDD in Ruby using <a href="http://rspec.info/" target="_blank">RSpec</a> and <a href="http://cukes.info/" target="_blank">Cucumber</a>. From reading this book, I have come to realise there is a distinct difference between higher-level user acceptance criteria (features) and and lower-level context-specifications (specs).</p>
<h3>Features</h3>
<p>Features are the things that the customer is likely to be most concerned with. They are high-level behaviours that are derived from the acceptance criteria of a <a href="http://dannorth.net/whats-in-a-story" target="_blank">user story</a>. They are purely concerned with how the user interacts with the application and don’t provide any details of implementation.</p>
<p>Features can be used to facilitate communication with the customer on what business objectives the application should achieve.</p>
<p>A feature consists of a user story and one or more example scenarios, which serve as our acceptance criteria. An example of a feature would be:</p>
<p><font face="monospace">Story: Account Holder withdraws cash </font></p>
<p><font face="monospace">&#160; As an Account Holder&#160; <br />&#160; I want to withdraw cash from an ATM       <br />&#160; So that I can get money when the bank is closed </font></p>
<p><font face="monospace">&#160; Scenario 1: Account has sufficient funds&#160; <br />&#160;&#160;&#160; Given the account balance is $100       <br />&#160;&#160;&#160; And the card is valid       <br />&#160;&#160;&#160; And the machine contains enough money       <br />&#160;&#160;&#160; When the Account Holder requests $20       <br />&#160;&#160;&#160; Then the ATM should dispense $20       <br />&#160;&#160;&#160; And the account balance should be $80       <br />&#160;&#160;&#160; And the card should be returned</font></p>
<p>Features can be turned into automated acceptance criteria. In Ruby, we can use Cucumber to parse a plain-text file and run each scenario against the application. These are usually slow-running, end-to-end integration tests. In .NET we would use a BDD framework such as <a href="http://nbehave.org/" target="_blank">NBehave</a>, or a standard unit-testing framework to implement the features as automated acceptance criteria.</p>
<p>Recently, I have been using Cucumber for automating the acceptance criteria for a .NET application, using <a href="http://wtr.rubyforge.org/" target="_blank">Waitr</a> to drive the browser. With <a href="http://www.ironruby.net/" target="_blank">IronRuby</a>, we will be able to access our .NET objects directly from Cucumber. As of this post date, IronRuby does not work with Cucumber, but a fix should be out very soon.</p>
<h3>Specs</h3>
<p>When we have defined a new feature, we must create the objects required to implement it. To do this we need to “drop-down” to the object-level and use a <a href="http://codebetter.com/blogs/jean-paul_boodhoo/archive/2007/11/29/getting-started-with-bdd-style-context-specification-base-na.aspx" target="_blank">context-specification</a> style to define how these objects should behave.</p>
<p>Specs are implemented as fast-running, unit-level tests with stubbed dependencies. In Ruby, RSpec is used to define the specs. In .NET we would use a standard unit-testing tool, such as <a href="http://www.nunit.org/" target="_blank">NUnit</a>.</p>
<p>A spec consists of an action on an object, within a certain context, and the observations made from that action. An example of a spec would be:</p>
<p><font face="monospace">When ATM requests withdrawal and account has sufficient funds      <br />&#160; Should check account balance       <br />&#160; Should send “Please wait” message to screen       <br />&#160; Should begin transaction       <br />&#160; Should withdraw funds from account       <br />&#160; Should dispense cash       <br />&#160; Should end transaction       <br />&#160; Should return card       <br />&#160; Should send “please take your card” message to screen</font></p>
<p>These steps describe the interaction between our object and its dependencies. They do not necessarily reflect the user’s observations (e.g the user doesn’t observe a transaction taking place).</p>
<p>We are not as concerned about testing the state of an object as we are about defining how it interacts with other objects. For instance, using the Model-View-Controller pattern, if we’re specifying a controller, we want to make sure an action sends a certain “message” to the view, rather than testing how it affects the state of the view. By specifying interaction over state, we are better able to define the roles and responsibilities of our objects.</p>
<p>I will try to incorporate some of this into the <a href="http://code.google.com/p/playlist-share/" target="_blank">PlaylistShare</a> sample application to demonstrate the distinction between Features and Specs.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timross.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timross.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timross.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timross.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timross.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timross.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timross.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timross.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timross.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timross.wordpress.com/205/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timross.wordpress.com&blog=2219574&post=205&subd=timross&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://timross.wordpress.com/2009/05/19/features-and-specs/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">timross</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Behaviour-Driven Development with ASP.NET MVC – Part 2</title>
		<link>http://timross.wordpress.com/2009/05/06/using-behaviour-driven-development-with-asp-net-mvc-part-2/</link>
		<comments>http://timross.wordpress.com/2009/05/06/using-behaviour-driven-development-with-asp-net-mvc-part-2/#comments</comments>
		<pubDate>Wed, 06 May 2009 16:58:00 +0000</pubDate>
		<dc:creator>timross</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Behaviour Driven Development]]></category>
		<category><![CDATA[BDD]]></category>

		<guid isPermaLink="false">http://timross.wordpress.com/?p=180</guid>
		<description><![CDATA[In part one, I introduced the PlaylistShare project, created some initial user stories, defined the acceptance criteria and created a template for writing executable specifications. In this part, I am going to write some executable specs for viewing playlists and implement the behaviour to make them pass. You can download the source code at the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timross.wordpress.com&blog=2219574&post=180&subd=timross&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In <a href="http://timross.wordpress.com/2009/05/04/using-behaviour-driven-development-with-aspnet-mvc-part-1/" target="_blank">part one</a>, I introduced the <a href="http://code.google.com/p/playlist-share/" target="_blank">PlaylistShare project</a>, created some initial user stories, defined the acceptance criteria and created a template for writing executable specifications. In this part, I am going to write some executable specs for viewing playlists and implement the behaviour to make them pass. You can download the source code at the end of this post.</p>
<p>There a couple of approaches you can take when writing specs for an ASP.NET MVC user interface. Either you can run them directly against the UI from inside a browser, using a tool such as <a href="http://watin.sourceforge.net/" target="_blank">WaitiN</a>. Or, you can drop in just below the UI and run the specs against the controllers. I prefer running them against the controllers as they run much faster and are not susceptible to changes to the HTML elements. However, you may find some aspects are better specified using a UI testing tool, such as behaviour that relies heavily on client-side scripting, which the controllers know nothing about.</p>
<p>I will be starting with the executable specification template I created in <a href="http://timross.wordpress.com/2009/05/04/using-behaviour-driven-development-with-aspnet-mvc-part-1/" target="_blank">part one</a>:</p>
</p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, &#39;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">namespace</span> view_playlist_specs</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">{</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">namespace</span> scenario_of</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">abstract</span> <span style="color:#0000ff;">class</span> listener_views_playlists : Specification&lt;PlaylistController&gt;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> PlaylistController create_subject()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">                <span style="color:#008000;">// Create the system under test</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">                <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">new</span> PlaylistController();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">&#160;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">void</span> given_a_list_of_playlists()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">                <span style="color:#008000;">// Establish a list of playlists</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">        }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">&#160;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">namespace</span> viewing_a_list_of_playlists</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">    {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        [TestFixture]</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> when_the_listener_views_the_playlists </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            : scenario_of.listener_views_playlists</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">        {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> setup_scenario()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">                <span style="color:#008000;">// Arrange</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">                given_a_list_of_playlists();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">&#160;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> execute_scenario()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">                <span style="color:#008000;">// Act</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">&#160;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            [Test]</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> should_display_a_list_of_playlists()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">                <span style="color:#008000;">// Assert</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">&#160;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            [Test]</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> playlists_should_be_ordered_by_date_submitted_from_newest_to_oldest()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">                <span style="color:#008000;">// Assert</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">    }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">}</pre>
</p></div>
</div>
<p>The first scenario we are going to implement is:</p>
<p><strong>Story: Listener views playlists</strong></p>
<p>As a playlist listener, I can view a list of playlists that have been submitted, so that I can find a playlist I might enjoy.</p>
<p><em>Scenario 1:</em> Viewing a list of playlists </p>
<p>Given a list of playlists </p>
<p>When the listener views the playlists </p>
<p>Then should display a list of playlists </p>
<p>&#160; And playlists should be ordered by date submitted from newest to oldest</p>
<p>First, lets create a new ASP.NET MVC application and add a <strong>PlaylistController</strong> to give us a <em>subject</em> to work with.</p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, &#39;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">[HandleError]</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> PlaylistController : Controller</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">{</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">public</span> ActionResult Index()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">    {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">return</span> View();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">    }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">}</pre>
</p></div>
</div>
<p>Now that we have a controller, let’s specify the first outcome of the scenario.</p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, &#39;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">[Test]</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> should_display_a_list_of_playlists()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">{</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    the_view_model.should_be_equivalent_to(playlists);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">}</pre>
</p></div>
</div>
<p>The outcome states that a list of playlists should be viewed on the page.</p>
<p><strong>the_view_model</strong> is a property on the spec base class that wraps calls to <strong>ProductsController.ViewData.Model</strong>. This makes the code slightly more readable. We can use <strong>ViewData.Model</strong> on the controller to pass data back to the view. In this case we want to pass back a list of <strong>Playlist</strong> objects.</p>
<p>You will notice I have used a method called <strong>should_be_equivalent_to</strong> to verify that <strong>the_view_model</strong> contains the same elements as <strong>playlists</strong>. This is an extension method defined in a <strong>SpecificationExtensions</strong> class I have added to the project. This class contains some helpful extension methods that wrap-up calls to NUnit assertions. This enables us to assert conditions directly on the objects, producing slightly more readable outcomes. Again, this is a personal preference and you can use ordinary <strong>Assert</strong> calls if you wish.</p>
</p>
<p>Running this spec should result in a failure, as we are not yet returning any playlists from the <strong>Index()</strong> controller method. We need to provide the controller with our list of playlists. To do this, we need to somehow pass a list of <strong>Playlist</strong> objects to the controller. The best way to do this is to use <a href="http://martinfowler.com/articles/injection.html" target="_blank">Dependency Injection</a> and <a href="http://en.wikipedia.org/wiki/Mock_object" target="_blank">Mocking</a> to pass a <a href="http://www.martinfowler.com/eaaCatalog/repository.html" target="_blank">Repository</a> containing our <strong>Playlist</strong> objects into the controller. Woah! Sounds complicated. But, it’s actually quite simple…</p>
<p>Let’s modify the <strong>PlaylistController</strong> to take an <strong>IPlaylistRepository</strong> and initialise a field in the constructor.</p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, &#39;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">[HandleError]</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> PlaylistController : Controller</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">{</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">readonly</span> IPlaylistRepository _playlistRepository;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">&#160;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">public</span> PlaylistController(IPlaylistRepository playlistRepository)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">    {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        _playlistRepository = playlistRepository;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">    }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">&#160;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">public</span> ActionResult Index()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">return</span> View();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">}</pre>
</p></div>
</div>
<p>Now we need to pass an instance of this repository when we create the <strong>PlaylistController</strong> in our specs. To do this I am going to generate a <em>stub</em> using <a href="http://ayende.com/projects/rhino-mocks.aspx" target="_blank">RhinoMocks</a>. This creates a runtime implementation of the <strong>IPlaylistRespository</strong> that we can pass into the controller.</p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, &#39;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> setup_scenario()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">{</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">    playlist_repository = MockRepository.GenerateStub&lt;IPlaylistRepository&gt;();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">}</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">&#160;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> PlaylistController create_subject()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">{</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">new</span> PlaylistController(playlist_repository);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">}</pre>
</p></div>
</div>
<p>The <strong>setup_scenario</strong> method gets called right before <strong>create_subject</strong><em>,</em> so we can use this to create any dependencies before the <strong>PlaylistController</strong> gets instantiated. Any scenarios can create additional context by overriding the <strong>setup_scenario</strong> method.</p>
<p>Now we need to add a <strong>GetAll()</strong> method to <strong>IPlaylistRepository</strong> that allows the <strong>PlaylistController</strong> to retrieve a list of <strong>Playlist</strong> objects.</p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, &#39;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">public</span> ActionResult Index()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">{</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">    var playlists = _playlistRepository.GetAll();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">return</span> View(playlists);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">}</pre>
</p></div>
</div>
<p>Back in our specs, we can now tell the stubbed <strong>playlist_repository</strong> to return some <strong>Playlist</strong> objects whenever the <strong>GetAll()</strong> method is called.</p>
</p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, &#39;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">void</span> given_a_list_of_playlists()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">{</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">    playlists = <span style="color:#0000ff;">new</span> List&lt;Playlist&gt;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">                    {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">                        <span style="color:#0000ff;">new</span> Playlist(),</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">                        <span style="color:#0000ff;">new</span> Playlist(),</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">                        <span style="color:#0000ff;">new</span> Playlist()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">                    };</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">    playlist_repository.Stub(r =&gt; r.GetAll()).Return(playlists.ToArray());</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">}</pre>
</p></div>
</div>
<p>Our spec should now be passing! We have now confirmed the controller is passing a list of playlists to the view to display on the page.</p>
<p>So, let’s write an assertion for our next outcome: “playlists should be ordered by date submitted from newest to oldest”. Here we verify that the <strong>Playlist</strong> objects sent to the view are ordered by date-submitted in a descending order.</p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, &#39;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">[Test]</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> playlists_should_be_ordered_by_date_submitted_from_newest_to_oldest()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">{</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    the_view_model.should_be_ordered_by_descending(p =&gt; p.DateSubmitted);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">}</pre>
</p></div>
</div>
<p>For this to compile we need to add a <strong>DateSubmitted</strong> property to the <strong>Playlist</strong> object. </p>
<p>I have created a helper method called <strong>should_be_ordered_by_descending</strong> that will verify that the playlists are ordered correctly. It’s really useful to create extension methods for complicated assertions to better explain what is being verified.</p>
<p>We can now make this spec pass by using <a href="http://en.wikipedia.org/wiki/Language_Integrated_Query" target="_blank">LINQ</a> to order the list of <strong>Playlist</strong> objects in the controller action before they are returned to the view.</p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, &#39;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">public</span> ActionResult Index()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">{</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">    var playlists = _playlistRepository.GetAll();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">return</span> View(playlists.OrderByDescending(p =&gt; p.DateSubmitted));</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">}</pre>
</p></div>
</div>
<p>Here is the output from the <a href="http://www.jetbrains.com/resharper/" target="_blank">Resharper</a> test runner:</p>
<p><a href="http://timross.files.wordpress.com/2009/05/testrunresharper1small.png"><img title="test-run-resharper-1-small" style="display:inline;border-width:0;" height="221" alt="test-run-resharper-1-small" src="http://timross.files.wordpress.com/2009/05/testrunresharper1small_thumb.png?w=504&#038;h=221" width="504" border="0" /></a> </p>
<p>Using these naming conventions means that if a spec fails, it’s easy to identify what behaviour is causing the problem. You also get clear, concise, executable documentation that describes how your application behaves.</p>
<p>You might have noticed that I have been implementing the playlist controller without even running the web site. By implementing the controller first, we can focus on the core behaviour of the application without being concerned about how it is presented. In the next part, we will create the view that displays the playlists on the page.</p>
</p>
<p><a href="http://playlist-share.googlecode.com/files/playlist-share-part-2.zip"><strong>Download the source code for Part 2</strong></a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timross.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timross.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timross.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timross.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timross.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timross.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timross.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timross.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timross.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timross.wordpress.com/180/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timross.wordpress.com&blog=2219574&post=180&subd=timross&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://timross.wordpress.com/2009/05/06/using-behaviour-driven-development-with-asp-net-mvc-part-2/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">timross</media:title>
		</media:content>

		<media:content url="http://timross.files.wordpress.com/2009/05/testrunresharper1small_thumb.png" medium="image">
			<media:title type="html">test-run-resharper-1-small</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Behaviour-Driven Development with ASP.NET MVC &#8211; Part 1</title>
		<link>http://timross.wordpress.com/2009/05/04/using-behaviour-driven-development-with-aspnet-mvc-part-1/</link>
		<comments>http://timross.wordpress.com/2009/05/04/using-behaviour-driven-development-with-aspnet-mvc-part-1/#comments</comments>
		<pubDate>Mon, 04 May 2009 21:35:22 +0000</pubDate>
		<dc:creator>timross</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Behaviour Driven Development]]></category>
		<category><![CDATA[BDD]]></category>

		<guid isPermaLink="false">http://timross.wordpress.com/?p=161</guid>
		<description><![CDATA[Introduction
Welcome to the first post in a series where I hope to demonstrate creating an ASP.NET MVC application using Behaviour-Driven Development (BDD).
I agonised over how to introduce this blog post. In the end, I figured it would be best just to get straight into it! There are plenty of excellent articles that introduce the concepts [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timross.wordpress.com&blog=2219574&post=161&subd=timross&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h3>Introduction</h3>
<p>Welcome to the first post in a series where I hope to demonstrate creating an <a href="http://www.asp.net/mvc/" target="_blank">ASP.NET MVC</a> application using <a href="http://en.wikipedia.org/wiki/Behavior_Driven_Development" target="_blank">Behaviour-Driven Development</a> (BDD).</p>
<p>I agonised over how to introduce this blog post. In the end, I figured it would be best just to get straight into it! There are plenty of excellent articles that introduce the concepts behind both <a href="http://dannorth.net/introducing-bdd" target="_blank">BDD</a> and <a href="http://weblogs.asp.net/scottgu/archive/2007/10/14/asp-net-mvc-framework.aspx" target="_blank">ASP.NET MVC</a>, so I won&#8217;t bother repeating it here. I will explain core concepts along the way and provide links to further information. If you feel that I haven&#8217;t explained something properly, or have missed something, then please post a comment and I&#8217;ll try to elaborate further.</p>
<p>Right, let&#8217;s get started. The application I am going to build is a playlist sharing web site aptly called <em>PlaylistShare</em> (slightly unimaginative, but if you have a better name, let me know! <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> . Music streaming services like <a href="http://www.spotify.com/" target="_blank">Spotify</a> are becoming increasingly popular and a <a href="http://www.spotify.com/blog/archives/2009/01/16/sharing-is-good-share-your-spotify-playlists/" target="_blank">number of sites</a> have sprung up that allow you to share playlists with other people. I don&#8217;t intend this example to be anything unique or new, but I thought it would be an interesting subject and not yet-another-storefront example. </p>
<p>I will provide a link to download the source code at the end of each post. I have also created a <a href="http://code.google.com/p/playlist-share/" target="_blank">Google Code project</a> to host the source code.</p>
<h3>It All Starts With a Story</h3>
<p>BDD is an <a href="http://en.wikipedia.org/wiki/Outside-in_software_development" target="_blank">outside-in</a> development process. We start by identifying goals and motivations, then drill down to the features that will achieve those goals. So, I&#8217;ve come up with a few <a href="http://dannorth.net/whats-in-a-story" target="_blank">user stories</a> to get us started.</p>
<p><strong>Story: Listener views playlists</strong></p>
<p>As a playlist listener, I can view a list of playlists that have been submitted, so that I can find a playlist I might enjoy.</p>
<p><strong>Story: Listener views playlist details</strong></p>
<p>As a playlist listener, I can view the playlist details, so that I can get more information about the playlist.</p>
<p><strong>Story: Contributor submits a playlist</strong></p>
<p>As a playlist contributor, I can submit a playlist, so that others can listen to it.</p>
<p>There are a lot of other features I can add, but as a “business”, these are my top priorities and will allow me to get something functional delivered first.</p>
<h3>Defining Acceptance Criteria</h3>
<p>In order to determine what behaviour to implement, we need to create a list of acceptance criteria for each story. The acceptance criteria allows us to define when a story is “done”.</p>
<p><em>Note: this is a very important stage. It allows all members of the team to share a common understanding of what the system is meant to do. It is tempting to jump straight to writing the executable specifications, but this stage needs to be carefully considered and have input from the customer and testers.</em></p>
<p>We will define the acceptance criteria as example <em>scenarios</em> using a <a href="http://dannorth.net/whats-in-a-story" target="_blank">given/when/then</a> vocabulary.</p>
<p><strong>Story: Listener views playlists</strong></p>
<p><em>Scenario 1:</em> Viewing a list of playlists     <br />Given a list of playlists     <br />When the listener views the playlists     <br />Then should display a list of playlists     <br />&#160; And playlists should be ordered by date submitted from newest to oldest</p>
<p><strong>Story: Listener views playlist details</strong></p>
<p><em>Scenario 1:</em> Viewing playlist details     <br />Given a playlist     <br />When the listener views the playlist details     <br />Then should display the playlist details     <br />&#160; And should display a link to listen to the playlist</p>
<p><strong>Story: Contributor submits a playlist</strong></p>
<p><em>Scenario 1:</em> Submitting a playlist     <br />Given a playlist     <br />When the contributor submits the playlist     <br />Then should submit the playlist     <br />&#160; And should display a message confirming the submission was successful</p>
<p><em>Scenario 2:</em> Submitting a playlist without a name     <br />Given a playlist without a name     <br />When the contributor submits the playlist     <br />Then should display a message saying the name is required     <br />&#160; And should not submit the playlist</p>
<p>Now that we have defined some acceptance criteria, we can create the executable specifications used to drive the implementation (a fancy way of saying, “write some tests!”). As we go forward we will probably identify other features we would like. We will make a note of these then add them to our next “iteration”.</p>
<h3>Writing Executable Specifications</h3>
<p>In BDD, tests are called specifications. This is mainly to get away from the notion that we are “testing”. Rather, we are defining behaviours that will drive the development process. We will still end up with a full suite of automated tests, but this is merely a very handy side-effect, not the goal, of BDD.</p>
<p>There are a number of BDD frameworks available for .NET, the most well-known of these being <a href="http://nbehave.org/" target="_blank">NBehave</a>. However, these frameworks can be difficult to get started with and can distract us from the main purpose of BDD, which is to effectively describe the application behavior. This is not because these frameworks are bad, but is more to do with the constraints of the C# language. BDD frameworks are much more effective in languages like Ruby, where the syntax makes it very easy to write readable specifications using frameworks such as <a href="http://rspec.info/" target="_blank">RSpec</a> and <a href="http://cukes.info/" target="_blank">Cucumber</a>. For this example, I am going to stick with using <a href="http://www.nunit.org/index.php" target="_blank">NUnit</a> and structure the test classes and member names to enable us to write BDD specifications. It will be a glorious day when when <a href="http://weblogs.asp.net/astopford/archive/2009/04/14/bdd-with-rspec-cucumber-ironruby.aspx" target="_blank">eventually</a> see RSpec and Cucumber working on <a href="http://www.ironruby.net/" target="_blank">IronRuby</a> and integrated seamlessly with our .NET applications. Until then, this is my current preference for writing BDD-style specifications in real-world applications.</p>
<p>I use a common <em>Specification</em> base-class to provide a framework for writing the specifications. This simple class contains the NUnit setup/teardown methods, handles exceptions and coordinates the various stages of executing a scenario.</p>
<p>These are a few conventions I use when writing BDD-style specifications:</p>
<ul>
<li><strong>Specification names are lowercase with underscores.</strong> This_is_to_make_the_specifications_more_readable. It is a personal preference, but I find PascalCaseNamingBecomesHardToReadForLongSentences (see what I did there&#8230; heh). </li>
<li><strong>One test-fixture per <em>scenario.</em></strong> Each test fixture represents a scenario of the story. </li>
<li><strong>Each test-fixture is wrapped in a namespace that describes the <em>scenario.</em></strong> This allows us to easily navigate the scenarios and prevents naming conflicts with other actions. This becomes important when we have the same action in different scenarios. </li>
<li><strong>Each test-fixture name defines the <em>action.</em></strong> An action is the “when” part of a scenario. It is the event that <em>causes</em> the behaviour. </li>
<li><strong>Each test-fixture derives from a base class that describes the <em>story.</em></strong> By inheriting from a base class, we can provide common set up data that is shared across all scenarios in the story. It also provides us with a handy reference back to the original story. </li>
<li><strong>The <em>context</em> is set before executing the <em>action</em>.</strong> The context is the “given” part of a scenario. The context sets the state of the system-under-test and its dependencies before the action is invoked. Wrapping setup code in helper-methods makes it easy to see what context we are creating and to reuse common setup steps. </li>
<li><strong>One test per <em>outcome.</em></strong> An outcome is the result of an action, the “then” part of a scenario. We may have many outcomes from an action, but we should only be testing for one thing per outcome. So try to only make <strong>one assertion per test method</strong>. Test for other outcomes in separate test methods. </li>
</ul>
<p>The outline for the first scenario looks like this:</p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, &#39;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">namespace</span> view_playlist_specs</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">{</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">namespace</span> scenario_of</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">abstract</span> <span style="color:#0000ff;">class</span> listener_views_playlists : Specification&lt;PlaylistController&gt;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> PlaylistController create_subject()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">                <span style="color:#008000;">// Create the system under test</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">                <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">new</span> PlaylistController();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">&#160;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">void</span> given_a_list_of_playlists()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">                <span style="color:#008000;">// Establish a list of playlists</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">        }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">&#160;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">namespace</span> viewing_a_list_of_playlists</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">    {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        [TestFixture]</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> when_the_listener_views_the_playlists </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            : scenario_of.listener_views_playlists</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">        {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> setup_scenario()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">                <span style="color:#008000;">// Arrange</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">                given_a_list_of_playlists();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">&#160;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> execute_scenario()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">                <span style="color:#008000;">// Act</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">&#160;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            [Test]</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> should_display_a_list_of_playlists()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">                <span style="color:#008000;">// Assert</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">&#160;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            [Test]</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> playlists_should_be_ordered_by_date_submitted_from_newest_to_oldest()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">                <span style="color:#008000;">// Assert</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">            }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;">    }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">}</pre>
</p></div>
</div>
<p><a href="http://playlist-share.googlecode.com/files/playlist-share-part-1.zip" target="_blank">Download the source code containing the outline for the first scenario</a>.</p>
<p>I hope this has been a helpful way to get started. I will explain a lot more about writing specifications in upcoming posts. Please feel free to post any questions or comments. In the next part of this series, I will begin implementing a playlist controller and passing the scenarios.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timross.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timross.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timross.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timross.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timross.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timross.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timross.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timross.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timross.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timross.wordpress.com/161/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timross.wordpress.com&blog=2219574&post=161&subd=timross&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://timross.wordpress.com/2009/05/04/using-behaviour-driven-development-with-aspnet-mvc-part-1/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">timross</media:title>
		</media:content>
	</item>
		<item>
		<title>Becoming a Polyglot Programmer</title>
		<link>http://timross.wordpress.com/2009/04/23/becoming-a-polyglot-programmer/</link>
		<comments>http://timross.wordpress.com/2009/04/23/becoming-a-polyglot-programmer/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 08:49:19 +0000</pubDate>
		<dc:creator>timross</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://timross.wordpress.com/?p=157</guid>
		<description><![CDATA[We .NET developers have always had the security blanket of a general purpose language like C# or VB.NET that we’ve been able to use for pretty much anything we need. However, it is becoming increasingly important for a developer to know several languages covering different paradigms and to have the ability to choose the best [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timross.wordpress.com&blog=2219574&post=157&subd=timross&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>We .NET developers have always had the security blanket of a general purpose language like C# or VB.NET that we’ve been able to use for pretty much anything we need. However, it is becoming increasingly important for a developer to know several languages covering different paradigms and to have the ability to choose the best language for the problem at hand.</p>
<p><a href="http://www.pragprog.com/the-pragmatic-programmer" target="_blank">The Pragmatic Programmer</a> recommends learning a new language every year. I’m currently taking that to the extreme and have several languages on the go.</p>
<h3>C</h3>
<p>I never learned C. I went straight from a basic understanding of Java to ASP/VBScript (ah, those were so not the days). So now I’m playing catch-up, learning about exciting things like pointers and memory allocation – all things that I have heard about many times, but never fully understood.</p>
<p>I’m current reading <a href="http://www.amazon.com/Programming-Language-Prentice-Hall-Software/dp/0131103628" target="_blank">The C Programming Language</a>, which is a very concise (only 274 pages) and superbly written book. If you know C#, then most of what’s covered will not be new. In fact, C is nowhere near as intimidating as I thought it would be, and it’s really made me appreciate the things I took for granted in modern C-based languages.</p>
<h3>Haskell</h3>
<p>Functional languages are hitting the mainstream, big time. I learned basic functional language principals using <a href="http://haskell.org/" target="_blank">Haskell</a> at Uni over 10 years ago. Back then it was pretty much an academic language that complemented a mathematics paper I was doing. These days, functional languages offer a promising solution to concurrency problems with software running on multi-core processors. Haskell is a purely functional language, which means you cannot sneak in a for-each loop when the going gets tough. It’s a great way to learn how to solve a problem in a functional manner, using a functional mindset.</p>
<p>It’s easy to get started with Haskell. I’m currently making my way through this excellent tutorial: <a href="http://learnyouahaskell.com/" target="_blank">Learn You a Haskell for Great Good</a>.</p>
<h3>Javascript</h3>
<p>I already know Javascript. Or at least I thought I did. Javascript has made a big comeback recently with the increasing popularity of client-side web programming for creating rich websites. The emergence of excellent frameworks like JQuery take the pain out of cross-browser support and DOM manipulation, which has always been the bane of Javascript development. On the surface, Javascript looks like a weak language with some bad features. But strip away the bad parts and there’s a really neat, powerful and dynamic language that runs pretty much anywhere!</p>
<p>With web applications becoming increasingly reliant on rich-client capabilities, it is important for any web developer to have a solid understanding of Javascript. If you are already familiar with Javascript, I would recommend the book <a href="http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742" target="_blank">Javascript: The Good Parts</a> to take you to the next level.</p>
<h3>Ruby</h3>
<p>I <a href="http://timross.wordpress.com/2008/12/08/adventures-in-ruby/" target="_blank">previously posted</a> on my adventures in Ruby and mentioned some good resources for getting started. <a href="http://www.ruby-lang.org/" target="_blank">Ruby</a> is a very powerful, dynamic and portable language that can be used for many tasks big or small. From building full-scale web applications using Rails, to writing build scripts using <a href="http://rake.rubyforge.org/" target="_blank">Rake</a>. Many .NET developers are replacing the XML-heavy NAnt build files with Rake scripts, which allow much greater flexibility by using the expressiveness of Ruby to coordinate the build tasks. The potent combination of <a href="http://rspec.info/" target="_blank">RSpec</a> and <a href="http://cukes.info/" target="_blank">Cucumber</a> for writing BDD specs make good use of Ruby’s dynamic and readable syntax. With the release of <a href="http://www.ironruby.net/" target="_blank">IronRuby</a> on the horizon, .NET developers will be able to get the benefits of this great language running natively on the .NET Framework via the Dynamic Language Runtime.</p>
<h3>F#</h3>
<p><a href="http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/" target="_blank">F#</a> is a multi-paradigm language for the .NET framework and encompasses both functional and imperative elements. I’ve barely scratched the surface of F#, but it looks very promising indeed. The more we require functional elements in our day-to-day programming, the more important it is to have a language that fully supports functional programming. C# 3.0 has some great functional features, such as LINQ and lambda expressions, but F# looks to offer much more powerful set of functional features.</p>
<h3>Conclusion</h3>
<p>So, I have a lot of learn! I don’t expect to become an expert in all these languages at once. But I think having a basic understanding of each has already helped me to improve my general programming skills and to approach problems in different ways.</p>
<p>If you are interested in learning a new language, I would recommend you know at least one dynamic and one functional language. If you’re feeling particularly up for a challenge, try <a href="http://en.wikipedia.org/wiki/Lisp_programming_language" target="_blank">LISP</a> <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timross.wordpress.com/157/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timross.wordpress.com/157/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timross.wordpress.com/157/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timross.wordpress.com/157/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timross.wordpress.com/157/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timross.wordpress.com/157/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timross.wordpress.com/157/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timross.wordpress.com/157/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timross.wordpress.com/157/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timross.wordpress.com/157/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timross.wordpress.com&blog=2219574&post=157&subd=timross&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://timross.wordpress.com/2009/04/23/becoming-a-polyglot-programmer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">timross</media:title>
		</media:content>
	</item>
		<item>
		<title>Software Craftsmanship 2009</title>
		<link>http://timross.wordpress.com/2009/02/27/software-craftsmanship-2009/</link>
		<comments>http://timross.wordpress.com/2009/02/27/software-craftsmanship-2009/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 14:56:06 +0000</pubDate>
		<dc:creator>timross</dc:creator>
				<category><![CDATA[Events]]></category>

		<guid isPermaLink="false">http://timross.wordpress.com/2009/02/27/software-craftsmanship-2009/</guid>
		<description><![CDATA[Yesterday I attended the Software Craftsmanship 2009 conference held at the BBC media centre in London. Overall, it was a great day with some really interesting sessions covering a wide variety of topics. It was especially interesting to share ideas and experiences with developers from different backgrounds using different languages and platforms.
The first session I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timross.wordpress.com&blog=2219574&post=152&subd=timross&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Yesterday I attended the <a href="http://parlezuml.com/softwarecraftsmanship/" target="_blank">Software Craftsmanship 2009</a> conference held at the BBC media centre in London. Overall, it was a great day with some really interesting sessions covering a wide variety of topics. It was especially interesting to share ideas and experiences with developers from different backgrounds using different languages and platforms.</p>
<p>The first session I attended was <a href="http://parlezuml.com/softwarecraftsmanship/sessions/pitfalls_in_test_authoring.htm" target="_blank">Pitfalls in Test Authoring</a> with Dave Cleal and John Daniels from Syntropy. This session was an open discussion on identifying test anti-patterns. Some really good points were raised and the discussion was very open and frank. There was some debate on whether unit tests should ever hit the database and what the scope of a unit test should be. This discussion later led to an open spaces talk on functional (integration) testing versus unit testing.</p>
<p>The next session I attended was <a href="http://gojko.net/" target="_blank">Gojko Adzic’s</a> talk on <a href="http://parlezuml.com/softwarecraftsmanship/sessions/specification_workshops.htm" target="_blank">Specification Workshops</a>. Gojko gave an excellent presentation on running workshops for the whole team to discuss the requirements for an iteration. One point that stood out for me was that the workshop should focus on what the software needs to do and not how to do it.</p>
<p>Over lunch I had a good chat to some java developers on why we should minimize code comments and the use of <a href="http://puttingtheteaintoteam.blogspot.com/2008/10/is-that-pojo-or-nojo.html" target="_blank">NOJOs</a> (&quot;Non Object-oriented Java Object&quot;, or DTOs to us .NET developers).&#160; I also had a chance to catch up with some ex-BBC colleagues who were attending the conference.</p>
<p>After lunch I went to a session on <a href="http://parlezuml.com/softwarecraftsmanship/sessions/responsibility_driven_design_with_mock_objects.htm" target="_blank">Responsibility-Driven Design with Mock Objects</a> by Willem van den Ende and Marc Evers. This was a live pair-programming session developing a text-based adventure game using RSpec and Ruby. The tests were focused on object collaboration rather than state. It was really interesting to see the use of mock objects in Ruby. I also found the focus on pure mocking for testing object collaboration to be very different from using mock objects to simply replace dependencies.</p>
<p>The next session was <a href="http://parlezuml.com/softwarecraftsmanship/sessions/empirical_experiences_of_refactoring.htm" target="_blank">Empirical Experiences of Refactoring in Open Source</a> by Steve Counsell from Brunel University. Steve presented his findings on the use of refactoring in open-source software. His findings were interesting but I was left a bit confused by what the results of the study meant for software teams. I would be interested to learn more about the conclusions of the study.</p>
<p>The final session I attended was on <a href="http://parlezuml.com/softwarecraftsmanship/sessions/test_driven_development_of_asynchronous_systems.htm" target="_blank">Test-driven Development of Asynchronous Systems</a> by Nat Pryce. Nat gave a good talk on his experiences with end-to-end testing of asynchronous systems.</p>
<p>We finished the day with a tour of the BBC Television Centre and a few beers in the bar upstairs. A few of us got to see Jonathan Ross recording his Friday night show and apparently U2 were guests. Unfortunately we didn’t bump into Bono, but we did get to have a photo with a <a href="http://en.wikipedia.org/wiki/TARDIS" target="_blank">TARDIS</a>.</p>
<p>All in all it was a great day and I would like to thank <a href="http://parlezuml.com/blog/" target="_blank">Jason Gorman</a> for organising this excellent event.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timross.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timross.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timross.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timross.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timross.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timross.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timross.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timross.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timross.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timross.wordpress.com/152/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timross.wordpress.com&blog=2219574&post=152&subd=timross&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://timross.wordpress.com/2009/02/27/software-craftsmanship-2009/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">timross</media:title>
		</media:content>
	</item>
		<item>
		<title>Focus On Quality Improves Delivery</title>
		<link>http://timross.wordpress.com/2009/02/03/focus-on-quality/</link>
		<comments>http://timross.wordpress.com/2009/02/03/focus-on-quality/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 22:22:00 +0000</pubDate>
		<dc:creator>timross</dc:creator>
				<category><![CDATA[Software Practices]]></category>

		<guid isPermaLink="false">http://timross.wordpress.com/2009/02/03/focus-on-quality/</guid>
		<description><![CDATA[Ron Jeffries explains why software quality and speed of delivery are not mutually exclusive. If you want to continually deliver working software quickly, then you need to maintain high quality: 
http://xprogramming.com/blog/2009/02/01/quality-speed-tradeoff-youre-kidding-yourself/
Uncle Bob has also posted his thoughts:
http://blog.objectmentor.com/articles/2009/02/03/speed-kills
I often find there is a lot of focus on delivering software quickly, but not so much on maintaining [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timross.wordpress.com&blog=2219574&post=143&subd=timross&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Ron Jeffries explains why software quality and speed of delivery are not mutually exclusive. If you want to continually deliver working software quickly, then you need to maintain high quality: </p>
<p><a href="http://xprogramming.com/blog/2009/02/01/quality-speed-tradeoff-youre-kidding-yourself/" target="_blank">http://xprogramming.com/blog/2009/02/01/quality-speed-tradeoff-youre-kidding-yourself/</a></p>
<p>Uncle Bob has also posted his thoughts:</p>
<p><a href="http://blog.objectmentor.com/articles/2009/02/03/speed-kills" target="_blank">http://blog.objectmentor.com/articles/2009/02/03/speed-kills</a></p>
<p>I often find there is a lot of focus on delivering software quickly, but not so much on maintaining quality. I think this is because it is generally considered that maintaining high quality means greater expense and later delivery. However, the higher the quality of code, the better able we are to deliver working software quickly and repeatedly. My belief is that the quality leaver should never be touched, or you risk taking on crushing debt.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timross.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timross.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timross.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timross.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timross.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timross.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timross.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timross.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timross.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timross.wordpress.com/143/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timross.wordpress.com&blog=2219574&post=143&subd=timross&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://timross.wordpress.com/2009/02/03/focus-on-quality/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">timross</media:title>
		</media:content>
	</item>
	</channel>
</rss>