sabato, luglio 17, 2010

Introducing Mocking BizTalk

According to Wikipedia mock objects are:

simulated objects that mimic the behavior of real objects in controlled ways.

[…]

mock objects can simulate the behavior of complex, real (non-mock) objects and are therefore useful when a real object is impractical or impossible to incorporate into a unit test.

From the BizTalk environment point of view the concept of unit testing is a bit tricky, as BizUnit project has shown, this is because, being BizTalk an integration platform, the only unit test one is able to do with it is, in fact, an integration test.

But to conduct integration tests all systems needs to be completely developed and online and this, obviously, can’t be guaranteed if not very late in the development iterations of integration projects.

Mock objects seems the natural way to bring real unit testing in BizTalk projects realm and several projects are born to fill this gap such as BizMock or Mocking Bird, they’re valid framework but they requires a testing infrastructure outside of BizTalk.

With Mocking BizTalk project i decided to try a quite different approach: BizTalk for external systems is just a black box with several ports but from BizTalk point of view, all the external world is a black box, and ports are the only point where BizTalk and external systems communicate.

Therefore, the focal point to mock external systems for BizTalk lies in its ports or, more precisely, in its pipelines.

Honestly, the best point is probably inside a custom adapter but since custom pipeline components are easier to build i decided to give it a try before building a full blown custom adapter.

The degree of flexibility necessary to mock every possible external system required me to implement some sort of DSL to drive the mock up, but after a while i thought “instead of inventing some sort of limited DSL why i don’t imply embed a full .NET language  as DSL in the pipeline?”

So i took my favorite dynamic language for .NET (boo) and embedded it in a couple of custom pipeline components (one for each pipeline stage) and at codeplex is published the result of the effort.

Mocking BizTalk is therefore not only a way to mock up external system, but also to mock up or prototype pipeline components, you may test a prototype of your pipeline component just writing a code script in boo, long before having to go throught the whole code component in c# –> compile –> prepare pipeline –> deploy, development cycle: just modify a text file containing the boo code and retry.