June 2006 Entries

Test Driven Development Discussion

 

Last night I had the opportunity to go to dinner with the Visual C# Team, C# MVP's and Regional Directors. I had an interesting discussion with Bill Wagner on the merits of having development teams following the test driven development methodology. It was a hearty discussion where I attempted to play the devil advocate in support of full compliance of the TDD approach.

I also had the chance to chat with Jeffrey Palermo about some of the idiosyncrasies related to the configuration file within StructureMap and the immediate value ReSharper provides to development teams.

Dirty SOAP

 

I just came from Scott Hanselman and Patrick Cauldwell's session on dynamically endpoints without ASMX. Their session was great and I had the opportunity to talk with Scott for a little bit afterwards. Scott's company uses dynamic endpoints to allow their customers to easily integrate with their financial software by providing WS-I compliant web services to support integration with disparate client software. Using a dynamic adapter, they are well suited to evolve with the eminent release of WCF. Three days into TechEd and the only things missing are power strips in the session rooms (shouldn't this be an obvious requirement for a technical conference?) and sleep. Sleeping is so overrated.

Notification Policy

 

How does your application support notification policies? Do you have failover mechanisms to support the policy? Our plane was scheduled to leave at 4 o'clock Saturday to fly out to TechEd. When I arrived at the airport at 2:30 I was notified that our plane had been cancelled and rescheduled to an earlier time that had already left by this time. The airline confirmed that they had in fact notified us via a phone message that was left at the main number of our office - which somehow never made it to us, they were free and clear as far as they were concerned. How convenient. It was rather obvious that we were not notified, why would we show up for a flight that didn't exist? Through quite a bit of finagling we were able to get our tickets transferred to another airline and made it to Boston. We were conveniently given the royal treatment going through every security station in the airports along the way since we switched airlines so late. Ah, aren't notification policies excellent and foolproof?

Rhino Mocks To The Rescue

 

A recent discussion on the Test Driven Development group brought in question the lacking ability of NMock for mocking classes. NMock will currently only mock an interface. The problem arose when the author wanted to mock a class that takes parameters in its constructor. His solution is to add an Initialize method to the interface and then every other method checks to confirm the object was initialized. While that is very mechanical and error prone - it does work, however there is another solution. Rhino Mocks allows you to create a PartialMock of a class with parameterized constructor arguments (I could even inject a mocked instance as a parameter for my partial mock). Ultimately you don't want your testing infrastructure to dictate too heavily the design of your application. Here is an example where we are able to test the GetId method without creating a derived class to provide the override implementation:

 

public abstract class DomainObject
{
public virtual Guid GetUser()
{
Guid g
= GetId();
if
(g == Guid.Empty)
{
g
= Guid.NewGuid();
}
return g;
}
public abstract Guid GetId();
}

[Test()]
public void PatialMock()
{
MockRepository mocks
= new MockRepository();
DomainObject anObject =
(DomainObject)mocks.PartialMock(typeof(DomainObject));
Guid g = Guid.NewGuid();
Expect.Call(anObject.GetId()).Return(g);
mocks.ReplayAll();
Assert.AreEqual(g, anObject.GetUser());
mocks.VerifyAll();
}