I started down this path to create a genealogy project inspired by Ben Lovell’s ‘Incremental development with Monorail’ postings. So I’m now completing my first page based on his Part One.

I’m deviating somewhat from this first part in that I’m dividing my unit tests into two types of tests: unit and integration. In my Genealogist.Tests I have Controllers directory where I place the PersonController tests. The Integration directory is where I place the PersonControllerIntegration tests.

Wizard3

PersonControllerTest contains the first test, ShouldRenderAddPersonForm. This extends the BaseControllerTest class from the Castle.MonoRail.TestSupport assembly. I had trouble getting this to work and it turned out that I have an old version of the Castle.MonoRail.TestSupport assembly down in the GAC. Once I removed it then the test worked.

   1: using Castle.MonoRail.TestSupport;
   2: using Genealogist.Controllers.Persons;
   3: using NUnit.Framework;
   4:  
   5: namespace MRProjectTest.Controllers {
   6:     [TestFixture]
   7:     public class PersonControllerTest : BaseControllerTest {
   8:         private PersonsController personController;
   9:  
  10:         [SetUp]
  11:         public void SetUp() {
  12:             personController = new PersonsController();
  13:             PrepareController(personController,@”Persons”, “addPerson”);
  14:         }
  15:  
  16:         [Test]
  17:         public void ShouldRenderAddPersonForm() {
  18:             personController.Add();
  19:             Assert.IsNotNull(personController);
  20:             Assert.AreEqual(personController.SelectedViewName, @”Personsadd”, @”Expected view: PersonAdd wasn’t rendered”);
  21:         }
  22:  
  23:         [TearDown]
  24:         public void Teardown() {}
  25:     }
  26: }

PersonControllerIntegrationTest contains the first test, ShouldRenderAddPersonForm. This is the first time I have used WatiN. All it took was to add two references to my project: WatiN.Core and Interop.SHDocVw. I had a small issue here getting the test to work because I used http://localhost:16489/Persons/add.brail. Once I changed it to http://localhost:16489/Persons/add.castle the test worked.

   1: using NUnit.Framework;
   2: using Rhino.Mocks;
   3: using WatiN.Core;
   4:  
   5: namespace MRProjectTest.Integration {
   6:     [TestFixture]
   7:     public class PersonControllerIntegrationTests {
   8:         private MockRepository mock;
   9:  
  10:         [SetUp]
  11:         public void SetUp() {
  12:             mock = new MockRepository();
  13:         }
  14:  
  15:         [Test]
  16:         public void ShouldRenderAddForm() {
  17:             using (IE browser = new IE(“http://localhost:16489/Persons/add.castle”)) {
  18:                 Assert.IsTrue(browser.ContainsText(“Add Person”));
  19:             }
  20:         }
  21:  
  22:         [TearDown]
  23:         public void TearDown() {
  24:             mock.VerifyAll();
  25:         }
  26:     }
  27: }

Using TDD both of these test failed but with some small amount of code both of these succeed. The PersonsController code is:

   1: using Castle.MonoRail.Framework;
   2:  
   3: namespace Genealogist.Controllers.Persons {
   4:     public class PersonsController : Controller {
   5:         [Layout(“default”)]
   6:         public void Add() {
   7:             RenderView(“add”);
   8:         }
   9:     }
  10: }

The add.brail code is this:

   1: Add Person

Be sure to add the Person controller to the controllers.config file. I forgot to and it took me a couple of minutes to figure out why it wasn’t working.

   1: <?xml version=“1.0″ encoding=“utf-8″?>
   2: <configuration>
   3:     <components>
   4:         <component id=“home.controller” type=“Genealogist.Controllers.HomeController, Genealogist” />
   5:     <component id=“persons.controller” type=“Genealogist.Controllers.Persons.PersonsController, Genealogist” />
   6:     </components>
   7: </configuration>

When it is all said and done I got this:

Wizard2

While this doesn’t seem like much it is the beginnings of something that has taken me hours to understand. All of the Castle stack is in place and I’m using ExtJS to help with the rendering of the page using the Brail ViewEngine. This is good.