I’ve been working on this for a few weeks now, half an hour at a time in the evenings and I can safely say it’s pretty hard to maintain a train of thought in thirty minute intervals. However a bare minimum implementation is complete and ready to discuss.
We start with an acceptance test:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature: Referrals Count | |
As an operational manager | |
I want to see counts of referrals | |
So I can plan capacity and monitor the number of patients in the system | |
Scenario: Simple Referral | |
Given the following referrals: | |
| Patient | Referral Date | | |
| Jane Smith | 2013–01–01 | | |
| Robert Jones | 2013–01–02 | | |
| Jenny Lee | 2013–01–03 | | |
When I load the referrals | |
Then the referral count should be 3 | |
And the referral count for 2013-01-01 should be 1 |
The first part of the feature describes the user story and the second part tells us that when we load three patient referrals then the total count should be 3 with 1 on the 1st January.
I’m using SpecFlow for acceptance tests since it is very easy to define tables and there are some useful binding utilities as we will see. After entering the test we can immediately compile the application and run the tests without writing anything else. The test will obviously fail since we haven’t written any code. In fact the acceptance test will stay broken for some time as we write code and unit tests. When it passes we know the feature is done.
So thinking about this functionally we effectively want to write a function that transforms an enumerable of source referral records into an enumerable of referral facts; then pipe this iterator into a SqlBulkCopy instance. Effectively this code needs to work:
referralrepository.BulkCopy(referrals.Select(x => mapper.Map(x)));
This is a Linq transform with a mapping function applied to each item in the source list. In the next few posts I’m going to break it into bite size chunks to implement.