I'm always a little intimidated when I post code examples. There are a lot of smart (and opinionated) people out there reading blogs. Fear won't get us anywhere though. That said, I'm posting this example and asking for criticism.
Here's the story. A school of music needs to schedule auditions for incoming students. The faculty need to be able to view the schedule for the next two upcoming terms, and some of staff needs to be able to edit the audition schedule.
The "schedule" is really a set of rooms set aside on certain dates for certain types of students. For example, room 1874 will be used for violins on September 21. Thus, a ScheduledRoom is a certain on a certain date, with rules about who can audition there. Right now, we're just concerned with retrieving the list of rooms for a given Term, which is a unique combination of year and semester.
We have a repository for handling audition schedules, and a service that talks to the repository. The service is in turn accessed by a desktop client, and a web client. I'm going to focus on just the repository here.
public class the_audition_schedule
private AuditionScheduleRepository _repository;
public void SetUp
_repository = new AuditionScheduleRepository();
public void can_retrieve_the_list_of_scheduled_rooms_for_a_given_term()
//setup data for test
Term fall2000 = a_term_for_Fall_2000();
Term spring2001 = a_term_for_Spring_2001();
//here's the actual code under test
IList<ScheduledRoom> rooms = _repository.GetRooms(fall2000);
//verify the results
The methods a_term_for_Fall_2000(), a_term_for_Spring_2001(), and schedule_a_room_for_() are helper methods that do nothing more than persist some test data. In my [Setup], I create a new instance of _repository, so that it's fresh for every test.
What am I really testing here? An important question, Joey Beninghove has a good post on the topic here.
I want to ensure that GetRooms() behaves the way I expect. I expect it to return 3 out of the 4 terms I have persisted. The actual implementation for GetRooms() builds an NHibernate.ICriteria and call its List<>() method.
Thoughts? Comments? More examples to come...
08-26-2007 11:07 PM