Well as you can see I’m not highly imaginative when it comes to blog post titles but I thought I’d continue with the Stranger in a Strange Land theme. If you’ve read my last blog posting on the subject you’ll know I’m busy learning about XAF and XPO for my new role at Developer Express and if you are following along, by now you should have read the documentation and watched the videos that I pointed to in that post.
So, what now? Well I don’t know about you, but I find the easiest way to learn about a programming tool or framework is to write a small application using it, so that’s what I’m going to start to do in this post. Specifically, I’m going to start to build an application to manage a hypothetical dental surgery.
The development of every application has to start somewhere and with XAF based applications that usually (but not always) means starting by working out the hierarchy of objects in your solution domain, so our hierarchy is going to look like this:-

For those of you who don’t speak UML, I’ll talk you through the diagram. A dental Surgery has one or more people associated with it, each Person is either an Employee or a Patient, of those who are employees, they are either a Dentist, a Receptionist or a Hygienist. Patients have one or more appointments with a Dentist or a Hygienist.
Having decided on our hierarchy of objects, let’s go ahead and build it in Visual Studio. Create a new solution and add a class library project and create the hierarchy of objects by carrying out the steps shown in this video, remembering to add the one-to-many relationship between Surgery and People as per the documentation here. Don’t worry if you mess it up, we’ll fix it as we go. When you have finished your project will look something like this:-

Having done that, let’s test our application. Add a new unit test to the solution (I’ll be using the built in VS tests but you can use your favourite unit testing suite) and write a test to create a new Surgery and a Dentist to work in that Surgery. In your test initialiser you need to write the following code to tell XPO where to put the database (we’ll be using the default Access implementation for the moment) and to build the schema if it does not already exist:-
[ClassInitialize()]
public static void MyClassInitialize(TestContext testContext)
{
//GS - Create a sensible location for the database
string path = @"C:\databases\XPODemo\XPOLayer.mdb";
//GS - If it exists, delete the database before the tests begin
if (File.Exists(path))
{
File.Delete(path);
}
//GS - Set the default session to null
XpoDefault.Session = null;
//GS - Explicitly set the default data layer
XpoDefault.DataLayer =
XpoDefault.GetDataLayer(
AccessConnectionProvider.GetConnectionString(path),
AutoCreateOption.DatabaseAndSchema);
}
Then add the following test to add a new Surgery object:-
[TestMethod]
public void AddSurgeryAndDentist()
{
using (var uow = new UnitOfWork())
{
//GS - Create a new Surgery
var surgery = new Surgery(uow);
surgery.Name = "Test Name";
surgery.Address1 = "27, Haggis Street";
surgery.Address2 = "Dundee";
surgery.Address3 = "Scotland";
surgery.Address4 = "UK";
surgery.Postcode = "DD7 7YG";
//GS - Create a Dentist to work at the Surgery
var dentist = new Dentist(uow);
dentist.FirstName = "Gary";
dentist.LastName = "Short";
dentist.Address1 = "Address1";
dentist.Address2 = "Address2";
dentist.Address3 = "Address3";
dentist.Address4 = "Address4";
dentist.Postcode = "DD3 8JK";
dentist.Email = "email@domain.com";
dentist.Hours = 37;
dentist.PayNumber = "RA 23445";
dentist.Salary = 42000.00f;
//GS - State that the Dentist works at the Surgery
surgery.People.Add(dentist);
//GS - Persit the object
uow.CommitChanges();
}
using (var uow = new UnitOfWork())
{
//GS - Test that the Surgery object was persisted
var Criteria = new BinaryOperator("Name", "Test Name");
var surgery = uow.FindObject<Surgery>(Criteria);
Assert.IsNotNull(surgery);
}
}
Well, I think that will do us for this post. In this post we devised a hierarchy of solution domain objects, then we implemented those objects using XPO as the persistence mechanism and finally we wrote tests to validate that we could persist our objects properly. In the next post, we’ll extend our solution to add different behaviours to our objects; we’ll also extend our test project to validate that behaviour. Hope to see you next time!