Incremental development with Monorail: Part Two
So in part one we had finished up at a failing test. Lets recap what this was:
And our failing test:
Our add view assumes that a Save action exists on our PostController. In attempting to make the test above pass, we will introduce this new action. However, this will be driven out from the PostController’s test fixture like so:
We’re faced with a bunch of unimplemented types and members shown in red thanks to Resharper’s error highlighting. As you can see from the test we’ve introduced the AddPostRequestDto and the three properties it exposes. Secondly we’ve introduced the Save action to the PostController that accepts our AddPostRequestDto. Our test then simply asserts that the correct response was set and that the postcreated view is displayed.
Our first step is the implementation of the AddPostRequestDto. Thankfully Resharper will perform this for us:
We’ve added this new type to the Core project under a new Messages namespace and folder for organisation.
Lets now go ahead and implement the new Save action on the PostController:
As you can no doubt see, we’ve done only the simplest thing possible to pass the test. Lets run our tests and see the results:
Well our controller fixtures pass nicely. I’ve got a sneaky suspicion that our acceptance test might fail however:
The expected confirmation was not displayed! We can assume this is as we’ve yet to create the postcreated view and spat back the responseMessage from this. Lets go ahead and create the view now:
If I run the test again, in the very short time the browser is visible I can see that we’re failing with an exception occurring during the Monorail binding. To fix this we need to derive the PostController from Monorail’s SmartDispatcherController and add the DataBind attribute to the Save action’s only parameter:
So lets go ahead and run our whole test suite:
Sweet! How functional our application is at this stage is still pretty debatable but we’re getting there
Our next task is to actually step down a layer and introduce a service to handle our persistence. I’ve checked in the latest changes. Stay tuned for the next post.
The google code hosted project: http://code.google.com/p/mr-blogengine/