<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Declan Whelan &#187; Software Development</title>
	<atom:link href="http://dpwhelan.com/blog/category/software-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://dpwhelan.com/blog</link>
	<description>Delivering better software</description>
	<lastBuildDate>Sat, 07 Aug 2010 16:36:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Moq Sequences</title>
		<link>http://dpwhelan.com/blog/software-development/moq-sequences/</link>
		<comments>http://dpwhelan.com/blog/software-development/moq-sequences/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 15:15:17 +0000</pubDate>
		<dc:creator>dwhelan</dc:creator>
				<category><![CDATA[Agile Testing]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://dpwhelan.com/blog/?p=134</guid>
		<description><![CDATA[I have recently started to use Moq for mocking and I really like it. The fluent interface and Lambda support makes it very easy and natural to use. However, I quickly ran into a situation where I wanted to ensure that methods on a mock object were called in a particular order. I have provided [...]]]></description>
			<content:encoded><![CDATA[<p>I have recently started to use Moq for mocking and I really like it. The fluent interface and Lambda support makes it very easy and natural to use.</p>
<p>However, I quickly ran into a situation where I wanted to ensure that methods on a mock object were called in a particular order. I have provided a simpler example below where I want to check that <em>BlogPresenter.Show()</em> shows blogs in reverse chronological order:</p>
<pre class="brush:csharp highlight: [17, 18]">
public class Post
{
    public DateTime DateTime { get; set; }
}

public class BlogPresenter
{
    private readonly BlogView view;

    public BlogPresenter(BlogView view)
    {
        this.view = view;
    }

    public void Show(IEnumerable posts)
    {
        foreach (var post in posts.OrderByDescending(post =&gt; post.DateTime))
            view.ShowPost(post);
    }
}

public interface BlogView
{
    void ShowPost(Post post);
}
</pre>
<p>To check this I used a callback to increment a counter like this:</p>
<pre class="brush:csharp highlight: [10, 13]">[Test]
public void Should_show_each_post_once_with_most_recent_first()
{
    var olderPost = new Post { DateTime = new DateTime(2010, 1, 1) };
    var newerPost = new Post { DateTime = new DateTime(2010, 1, 2) };
    var posts = new List { newerPost, olderPost };

    var mockView = new Mock();

    var viewOrder = 0;

    mockView.Setup(v =&gt; v.ShowPost(newerPost)).Callback(() =&gt; Assert.That(viewOrder++, Is.EqualTo(0)));
    mockView.Setup(v =&gt; v.ShowPost(olderPost)).Callback(() =&gt; Assert.That(viewOrder++, Is.EqualTo(1)));

    new BlogPresenter(mockView.Object).Show(posts);

    mockView.Verify(v =&gt; v.ShowPost(newerPost), Times.Once());
    mockView.Verify(v =&gt; v.ShowPost(olderPost), Times.Once());
}
</pre>
<p>This works code but is not very intentional. I wanted to express the intent the there is a required ordering of method calls. After searching around I found a nice code snippet from <a href="http://maxg3prog.blogspot.com/2010/04/very-simple-sequencer-for-moq.html" target="_blank">Max Guernsey, III</a> that was promising. I thought I would push a little further to see if I could get something like this:</p>
<pre class="brush:csharp">[Test]
public void Should_show_each_post_with_most_recent_first_using_sequences()
{
    var olderPost = new Post { DateTime = new DateTime(2010, 1, 1) };
    var newerPost = new Post { DateTime = new DateTime(2010, 1, 2) };
    var posts = new List { newerPost, olderPost };

    var mockView = new Mock();

    using (Sequence.Create())
    {
        mockView.Setup(v =&gt; v.ShowPost(newerPost)).InSequence();
        mockView.Setup(v =&gt; v.ShowPost(olderPost)).InSequence();

        new BlogPresenter(mockView.Object).Show(posts);
    }
}
</pre>
<p>So, I created Moq.Sequences and you download <em>Moq.Sequences.dll</em> from <a href="http://github.com/dwhelan/Moq-Sequences/downloads" target="_blank">github</a>. Simply, add <em>Moq.Sequences.dll</em> as a reference in your .Net project and add a <em>using Moq.Sequences;</em> in your test class. Moq.Sequences supports the following:</p>
<ul>
<li>checks order of method calls, property gets and property sets</li>
<li>allows you to specify the number of times a call is made before the next one is expected</li>
<li>allows intermixing of sequenced and non-sequenced expectations</li>
<li>thread safe &#8211; each thread can have its own sequence</li>
</ul>
<h3>Sequences</h3>
<p>Sequences are added using the Sequence static class and extension methods. You create a sequence by calling:</p>
<pre class="brush:csharp highlight:[1]">
using (Sequence.Create())
{
    ...
}
</pre>
<p>Sequences that do not fully complete are detected when the sequence is disposed. So, all the setups and mock calls should be done within the lifetime of the sequence.</p>
<h3>Steps</h3>
<p>Within a sequence you set the expectations for ordering via an extension method <em>InSequence<()</em>. I call these steps. For example, </p>
<pre class="brush:csharp highlight:[3,4]">
using (Sequence.Create())
{
    mock.Setup(_ => _.Method1()).InSequence();
    mock.Setup(_ => _.Method2()).InSequence();
    ...
}
</pre>
<p>This sets an expectation that <em>Method1()</em> will be called once followed by a single call to <em>Method2</em>. You can set more sophisticated expectations by using a <em>Times</em> parameter:</p>
<pre class="brush:csharp">
using (Sequence.Create())
{
    mock.Setup(_ => _.Method1()).InSequence(Times.AtMostOnce());
    mock.Setup(_ => _.Method2()).InSequence(Times.Between(1, 10, Range.Inclusive));
    ...
}
</pre>
<p>Steps can be created for method calls, property gets and property sets:</p>
<pre class="brush:csharp highlight[5]">
using (Sequence.Create())
{
    mock.Setup(_ => _.Method1()).InSequence(); // method call
    mock.SetupGet(_ => _.Property1).InSequence().Returns(0);  // property get
    mock.SetupSet(_ => _.Property2 = 0).InSequence(); // property set
    ...
}
</pre>
<p>Also, sequenced steps can be intermingled with non-sequenced expectations.</p>
<h3>Loops</h3>
<p>Loops are used when you want to check that as group of method calls are called in order several times. An example of this could be some resources which you expect to be opened, operated on and then closed, one after the other.</p>
<p>Loops are created via <em>Sequence.Loop()</em>:</p>
<pre class="brush:csharp highlight[5]">
using (Sequence.Create())
{
    mock.Setup(_ => _.Method1()).InSequence();

    using (Sequence.Loop())
    {
        mock.Setup(_ => _.Method2()).InSequence();
        mock.Setup(_ => _.Method3()).InSequence();
    }
    ...
}
</pre>
<p>The above checks that <em>Method1</em> is called by any number of calls to <em>Method2</em> followed immediately by a call to <em>Method3</em>. You can constrain the number of times the loop can be executed by adding a <em>Times</em> parameter such as the following example where the combination of <em>Method2</em> and <em>Method3</em> should be called exactly twice:</p>
<pre class="brush:csharp highlight[5]">
using (Sequence.Create())
{
    mock.Setup(_ => _.Method1()).InSequence();

    using (Sequence.Loop(Times.Exactly(2)))
    {
        mock.Setup(_ => _.Method2()).InSequence();
        mock.Setup(_ => _.Method3()).InSequence();
    }
    ...
}
</pre>
<h3>Wrap-Up</h3>
<p>Moq.Sequences provides a simple, intentional way of checking that things are are done in a specific order. Feel free to check it out at <a href="http://github.com/dwhelan/Moq-Sequences/" target="_blank">github</a>. I welcome any feedback!</p>
]]></content:encoded>
			<wfw:commentRss>http://dpwhelan.com/blog/software-development/moq-sequences/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PostRank &#8211; A .NET API for AideRSS PostRank</title>
		<link>http://dpwhelan.com/blog/software-development/postrank-a-net-api-for-aiderss-postrank/</link>
		<comments>http://dpwhelan.com/blog/software-development/postrank-a-net-api-for-aiderss-postrank/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 22:02:01 +0000</pubDate>
		<dc:creator>dwhelan</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[AideRSS]]></category>
		<category><![CDATA[PostRank]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[Simple Design]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://dpwhelan.com/blog/?p=26</guid>
		<description><![CDATA[AideRSS provides a service that ranks online content such as RSS feeds, blog posts and so on. I have always been impressed with AideRSS and wanted to educate myself with writing REST interface logic, ASP.Net and Web 2.0 in general. AideRSS also provides a PostRank API to their service so I decided to write a [...]]]></description>
			<content:encoded><![CDATA[<p><a title="AideRSS" href="http://www.aiderss.com/">AideRSS</a> provides a service that ranks online content such as RSS feeds, blog posts and so on. I have always been impressed with AideRSS and wanted to educate myself with writing REST interface logic, ASP.Net and Web 2.0 in general. AideRSS also provides a <a title="PostRank" href="http://www.postrank.com/home.html">PostRank API</a> to their service so I decided to write a .NET client wrapper for this API to make it easier to use. You can download the API including source and binaries from here:</p>
<p><a href="http://dpwhelan.com/blog/wp-content/uploads/2008/09/postrank-10.zip"><img class="alignnone size-medium wp-image-33" title="download" src="http://dpwhelan.com/blog/wp-content/uploads/2008/09/download.jpg" alt="Download" width="42" height="38" />postrank-10.zip</a></p>
<h3>Why Did I Write This?</h3>
<p>My goal with the API beyond learning some new stuff was to leverage <a title="TDD - Wikipedia" href="http://en.wikipedia.org/wiki/Test-driven_development">TDD</a> and allow emergent design to surface an underlying domain model. I wanted to avoid a simple static functional wrapper for the API and instead provide a design that would allow more powerful usages of the PostRank API. I wanted TDD to help evolve a reasonable domain model which would include classes to represent feeds, posts and so on. To do this I systematically applied the XP rules of simplicity:</p>
<ol>
<li>Testable &#8211; has a test</li>
<li>Communicative &#8211; classes and methods are intent revealing</li>
<li>Factored &#8211; no duplication of logic or structure</li>
<li>Minimal &#8211; minimum number of classes and methods</li>
</ol>
<p>While I am not an expert on RSS or the PostRank API I am quite happy with the resulting API. The classes that emerged make sense, at least to me! There is also a safety net of 105 unit tests that I can use for future refactoring and enhancements.</p>
<h3>What Does it Do?</h3>
<p>The API provides full access to the underlying PostRank API. Besides creating unit tests for the code I also included a demo command line application and a demo ASP.Net project.</p>
<p>The demo command line program takes a single command line argument which is the RSS feed you are interested in and defaults to Ilya Grigorik&#8217;s blog:</p>
<p><a href="http://dpwhelan.com/blog/wp-content/uploads/2008/09/postrank-command-line-output1.jpg"><img class="alignnone size-full wp-image-28" title="PostRank Command Line Output" src="http://dpwhelan.com/blog/wp-content/uploads/2008/09/postrank-command-line-output1.jpg" alt="PostRank Command Line Output" width="500" height="331" /></a></p>
<p>The ASP.Net project provides an interactive UI allowing you to enter an RSS feed and see AideRSS PostRank features such as top posts in a given time period. The screen shots below show some of the features of the API:</p>
<p><a href="http://dpwhelan.com/blog/wp-content/uploads/2008/09/top-posts-of-the-year.jpg"><img class="alignnone size-thumbnail wp-image-29" title="Top Posts of the Year" src="http://dpwhelan.com/blog/wp-content/uploads/2008/09/top-posts-of-the-year-150x150.jpg" alt="Top Posts of the Year" width="150" height="150" /> </a><a href="http://dpwhelan.com/blog/wp-content/uploads/2008/09/top-posts-of-the-month.jpg"><img class="alignnone size-thumbnail wp-image-30" title="Top Posts of the Month" src="http://dpwhelan.com/blog/wp-content/uploads/2008/09/top-posts-of-the-month-150x150.jpg" alt="Top Posts of the Month" width="150" height="150" /> </a><a href="http://dpwhelan.com/blog/wp-content/uploads/2008/09/great-posts.jpg"><img class="alignnone size-thumbnail wp-image-31" title="Great Posts" src="http://dpwhelan.com/blog/wp-content/uploads/2008/09/great-posts-150x150.jpg" alt="Great Posts" width="150" height="150" /></a></p>
<p>Note that there is an alternate .NET API written by William Spaetzel that you can get from <a href="http://spaetzel.com/postranksharp">http://spaetzel.com/postranksharp</a>.</p>
<p>I welcome any feedback you may have on this API.</p>
]]></content:encoded>
			<wfw:commentRss>http://dpwhelan.com/blog/software-development/postrank-a-net-api-for-aiderss-postrank/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Taking Stock of Your Software Inventory</title>
		<link>http://dpwhelan.com/blog/agile/taking-stock-of-your-software-inventory/</link>
		<comments>http://dpwhelan.com/blog/agile/taking-stock-of-your-software-inventory/#comments</comments>
		<pubDate>Mon, 26 May 2008 03:27:08 +0000</pubDate>
		<dc:creator>dwhelan</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Agile Testing]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://dpwhelan.com/blog/?p=9</guid>
		<description><![CDATA[Do you have inventory piling up between your development team and QA? This inventory of unconfirmed functionality limits your team&#8217;s agility on a few fronts: your software is not always potentially shippable deferred ROI delayed feedback from QA One of the main goals of your agile team is to build potentially shippable releases every iteration. [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-size: x-small;">Do you have inventory piling up between your development team and QA?</span></p>
<div></div>
<p><span style="font-size: x-small;"></p>
<p align="left"><img src="http://dpwhelan.com/blog/wp-content/uploads/2008/05/inventory.jpg" alt="" width="396" height="309" /></p>
<p align="left">This inventory of unconfirmed functionality limits your team&#8217;s agility on a few fronts:</p>
<div></div>
<p><span style="font-size: x-small;"></p>
<ul>
<li>
<div>your software is not always potentially shippable</div>
</li>
<li>deferred ROI</li>
<li>delayed feedback from QA</li>
</ul>
<p align="left">One of the main goals of your agile team is to build potentially shippable releases every iteration. When QA testing is done after development releases your team can no longer achieve this goal.</p>
<p align="left">This deferred testing also creates an inventory of unconfirmed features that need to be managed. And just like any manufacturing system, inventory is wasteful and costs your company time and money. Every day that your software is not shipped decreases the ROI.</p>
<p align="left">The longer your software remains untested the more costly any corrective action becomes. The cost arises from many factors including the ramp-up time for the developers, context-switching time, overhead with issue tracking and so on.</p>
<p align="left">Finally, feedback from good testers is invaluable. They think differently from developers and tend to have a more outward-looking customer perspective. If you get this feedback earlier in the process you will see a reduction in defects and less rework.</p>
<p align="left">If you find your team in this situation here are a few things you could might consider doing:</p>
<table border="0">
<tbody>
<tr>
<td>
<p style="text-align: center;"><strong><span style="font-size: small;">Track Metrics</span></strong></p>
<p style="text-align: center;"><img src="http://dpwhelan.com/blog/wp-content/uploads/2008/05/defects.jpg" alt="" width="280" height="185" /></p>
</td>
<td><span style="font-size: small;">Select metrics such as defect counts or time to close that you feel best highlights the obstacles your team faces. Chart these metrics in big visible charts<br/></br>Consider translating technical metrics into bottom-line financial data. For example, you could use daily expected revenue of the product to calculate the revenue loss due to each day of delay.</span></td>
</tr>
<tr>
<td>
<p style="text-align: center;"><strong><span style="font-size: small;">Get Developers and Testers Working Together</span></strong></p>
<p style="text-align: center;"><img src="http://dpwhelan.com/blog/wp-content/uploads/2008/05/pair-programming.jpg" alt="" width="225" height="173" /></p>
<p style="text-align: center;">
</td>
<td><span style="font-size: small;">There has been much talk about getting quality assurance infused throughout the product cycle. Agile teams are tailor-made for this transition. </span><span style="font-size: small;">Get a tester on your team and allow her to contribute throughout the iteration</bt>Aside from traditional testing, the tester can bullet-proof the story tests, suggest testing tasks, pair with developers on testing and so on</br></br>This inter-personal contact will do more to promote quality within your team than any formal QA process ever will.</td>
</tr>
<tr>
<td>
<p style="text-align: center;"><strong><span style="font-size: small;">Stagger Iteration Testing</span></strong></p>
<p style="text-align: center;"><img src="http://dpwhelan.com/blog/wp-content/uploads/2008/05/staggered-testing1.jpg" alt="Staggered testing" /></p>
<p style="text-align: center;">
</td>
<td><span style="font-size: small;">If you must maintain a separate system test phase, consider having the QA team test the previous iterations release. This way, the QA team has a stable release for testing and feedback is delayed at most one iteration</br></br>Over time, you may be able to move additional QA activities into the development iteration.</td>
</tr>
</tbody>
</table>
<p></span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://dpwhelan.com/blog/agile/taking-stock-of-your-software-inventory/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
