In a
previous post, I talked about abstracting the BizTalk XLANGMessage away from the code through an IOrchestrationMessage interface. After some deliberation and inspiration from
Phil Haack, I decided to take another look at using Rhino Mocks to help my cause.
In this case, I'd like to use Extension Methods, but I'd rather not mix and match Visual Studio 2005 with 2008 just yet. But you could imagine it would look something like this when done:
public static XLANGMessage CreateBizTalkMessage(
this MockRepository repository)
{
XLANGMessage message = repository.DynamicMock<
XLANGMessage>();
XLANGPart part = repository.DynamicMock<
XLANGPart>();
SetupResult.For(message[0]).Return(part);
SetupResult.For(message.GetPropertyValue(typeof(FILE.
ReceivedFileName))).Return(@
"C:\index.xml");
FileStream stream =
new FileStream(@"C:\index.xml",
FileMode.Open,
FileAccess.Read);
SetupResult.For(part.RetrieveAs(
typeof(
Stream))).Return(stream);
repository.ReplayAll();
return message;
}
Pretty simple code and easy to use. Rhino Mocks handles this perfectly and I'm able to use them in my test methods like so.
[Test]
public void OrchestrationHelper_ProcessMessage_Success()
{
MockRepository repository =
new MockRepository();
XLANGMessage btsMessage = repository.
CreateBizTalkMessage();
...
}
So, at the end of the day, it makes my life much easier to test parts of my custom code that requires me to hand it the BizTalk XLANG message. No fake interfaces required!