Building the www.brightonsausageco.com website - 29/10/2012

This is a follow up to the 1st in this series: http://iwayneo.blogspot.co.uk/2012/10/building-www.html

And the second http://iwayneo.blogspot.co.uk/2012/10/building-www_16.html

And the third: http://iwayneo.blogspot.co.uk/2012/10/building-www_26.html

Monday morning, 6:00am!! I left the site on Friday with a passing step which basically meant that the add category form wouldn't b0rk on submission. I know there's some blank spots to fill here (persistence) but I don't have a failing step yet so I'm being ignorant to all these things - I'll tackle them when the tests require me to.

From the feature file I can see that we are failing on the following step: "Then I should see "category1" show up in the list of existing categories" because when we click the Save button we get a 404 POSTing to /admin/categories/add. This was a simple coding error with inconsistent action names: the GET action was called CategoriesAdd and the POST was called Categories - so the routing wouldn't work POSTing to that URL - I need to get the routing tests to be more detailed.

The good thing about allowing my development to be guided by small steps in a feature file is that I can easilly gain continuity and remain focused during disparate, micro sprints: TBD (Train Based Development!). To get this step passing I just need to add a redirect in the POST action so that we're headed back to the main category page where we can add the list of existing categories. Before I can add the redirect to the action I need to make sure I have a failing test:

Here is what the action now looks like in order to make that test pass:

We're still not out of the woods however - we still have a failing step and in fact - I think the woods just got darker! The reason we're still failing is because we aren't showing a list of existing categories. Existing categories is the first mention of real persistence - we hinted at the fact that we were storing the categories somewhere when we submitted the form but there was not concrete spec suggesting that was the case. Now we have the requirement to pluck categories out of somewhere. This means a decision on what storage mechanism must be made. Because I don't want the unecessary complication of RDBMS plus ORM I have already opted out of SQL. This leaves me with the 3 good doc based storage engines that I would choose from:

  • RavenDb
  • Mongo
  • Riak

And without much adoooo I can tell you that I have opted for MongoDb on the bases that it is free and has a large community. [installs mongo + NuGet for driver in both MVC and Behaviors projects]. So I'm happy with the idea that I'm going to be fetching a set of Categories from MongoDb. To do this I need to pass in a repository to the Admin controller which I can use to talk to the DB. This means going back to the first test and making the AdminController instantiation work with an IRepository:

And the code for the AdminController now looks like:

That gives us the ability but we're not doing so let's sort that. To display the categories we need to be able to get all of them from the repository. Let's go and add the IRepository.GetAll() method then.

Comments