Test Driven Development with ASP.Net MVC (Part 2)

The series in full:

In Part 1, I talked about my view on TDD, and the particular flavour I use when doing TDD with MVC. In this post I am going to have a look at the feature we want to implement.

An event booking system

The functionality we are building is for an event booking system.  There is a database full of events, and people can use the web site to search for events and make a booking.

We are interested in implementing the search functionality. We may be fortunate to have analysts, testers and developers working together to craft the user stories with the product owner, but at this stage it doesn’t really matter how the user stories were created.  What matters is that there is a framework of ideas to build from.  They don’t have to be perfect, but it is difficult for the system to emerge without something to kick-start the ideas.

We have the following user story:

As a potential event attendee, I want to search for events, so that I can see all the available events that match my criteria

We also have some screen mock-ups to guide us.  A couple of the more relevant ones are shown below:

Event Search Screen mock-up 1

Event Search Screen mock-up 1

Event Search Screen mock-up 2

Event Search Screen mock-up 1

From the mock-ups, what behaviour do we want to cover? There are lots of potential scenarios, but lets focus on a few of the more straight forward ones for now:

• Search criteria options are pre populated
• Search for an event by region
• Search for an event by name
• No results returned from search
• Search criteria is ‘remembered’ when the results are shown

You will see that some of the scenarios overlap. For example, having no search results returned could well be part of searching for an event by name or region, however I find it better to cover the scenarios explicitly for the benefit of test separation in the case of both unit and acceptance testing.

From the scenario list we can now flesh out some examples to use:

Scenario 1 – Search criteria options are pre populated
GIVEN that I want to search for an event by region
WHEN I select to choose a region
THEN a list of possible regions is presented

Scenario 2 – Search for an event by region
GIVEN the following events exist

Event Code Event Name Region Description
CR/0001 Crochet for Beginners North A gentle introduction into the art of crochet
CR/0002 Intermediate Crochet North Taking your crochet to the next level
CH/3001 Cat Herding London A starter session for the uninitiated

WHEN I search for events in the “North” Region
THEN the search results present the following events

Event Code Event Name Region Description
CR/0001 Crochet for Beginners North A gentle introduction into the art of crochet
CR/0002 Intermediate Crochet North Taking your crochet to the next level

Scenario 3 – Search for an event by Name
GIVEN the following events exist

Event Code Event Name Region Description
CR/0001 Crochet for Beginners North A gentle introduction into the art of crochet
CR/0002 Intermediate Crochet North Taking your crochet to the next level
CH/3001 Cat Herding London A starter session for the uninitiated

WHEN I search for events with the name “Cat Herding”
THEN the search results present the following events

Event Code Event Name Region Description
CH/3001 Cat Herding London A starter session for the uninitiated

Scenario 4 – No Search results return from search
GIVEN the following events exist

Event Code Event Name Region Description
CR/0001 Crochet for Beginners North A gentle introduction into the art of crochet
CR/0002 Intermediate Crochet North Taking your crochet to the next level
CH/3001 Cat Herding London A starter session for the uninitiated

WHEN I search for events in the “South” Region
THEN I am informed that no search results have been returned

Scenario 5 – Search criteria is ‘remembered’ when the results are shown
GIVEN I have performed a search in the "North" region
WHEN the search results page is displayed
THEN the search criteria displays my choice of region

In Part 3 we will start implementing the application, guided by the behaviour defined in the scenarios.

The series in full:

Advertisements

7 Responses to Test Driven Development with ASP.Net MVC (Part 2)

  1. Pingback: Test Driven Development with ASP.Net MVC (Part 1) « James Heppinstall: On Development

  2. Pingback: Test Driven Development with ASP.Net MVC (Part 3) « James Heppinstall: On Development

  3. Pingback: Test Driven Development with ASP.Net MVC (Part 4) « James Heppinstall: On Development

  4. Pingback: Test Driven Development with ASP.Net MVC (Part 5) « James Heppinstall: On Development

  5. Pingback: Behavioural testing in .Net with SpecFlow and Selenium (Part 1) « James Heppinstall: On Development

  6. Nehru Barry says:

    Sometimes ago i seen the article about Test Driven Development.here i think you provide information in 5 stages.and nothing more interesting.

    • jheppinstall says:

      Hi Nehru,

      Thanks for your comment. I am not sure what you were expecting in a post about TDD with MVC. If you have any ideas to improve the series I would be interested to hear them.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: