Last week I spent some time working on a new minor release of my PipelineTesting library for BizTalk Server 2006/R2. The new release is available in the usual places: Binary and Source Snapshot, and the Source Repository at GitHub.

The new release includes some minor documentation updates, a couple of bug fixes and a new wrapper for doing basic testing of flat file and xml schemas that provides a somewhat equivalent functionality to that offered by the TestableSchema class offered in BizTalk 2009 I’ve talked about before.

Here’s the documentation and sample for the new functionality.


Testing Schemas

It is possible to target BizTalk schemas in your testing efforts using all versions of PipelineTesting if you don’t mind doing a little bit of grunt work. This is possible for both flat file and xml schemas, and is done simply by instantiating a pipeline (either a compiled pipeline or by creating a new one from scratch) and then running your instance documents through it and checking the output.

This works particularly well for advanced scenarios involving envelopes or batching/debatching, but it’s overkill for the simple scenarios.

Beginning with PipelineTesting v1.2.1.0, there’s a new feature for easy testing of schemas in those simple scenarios. Partially inspired by the new functionality offered in BizTalk Server 2009, the SchemaTester class allows you to parse/assemble a document according to a single document schema with a single method call.

To use SchemaTester, simply provide the type of the BizTalk schema to use and call one of it’s static methods. The options offered are:

  • ParseFF: Parses a flat file into an XML document
  • ParseXml: Parses an XML document
  • AssembleFF: Assembles an XML document into a new flat file
  • AssembleXml: Assembles an XML document

All method come with overloads that use streams or paths to files. Here’s an example of how to use it based on one of the unit tests for this feature:

Stream input = DocLoader.LoadStream("CSV_FF_RecvInput.txt");
Stream output = SchemaTester.ParseFF(input);
// Load resulting XML document
XmlDocument doc = new XmlDocument();
doc.Load(output);

If the document cannot be converted, an exception will be raised. Remember that you must consume the resulting stream (if using the stream-variants of the SchemaTester methods). You can then check the resulting exception to look into why the parsing/assembling is failure.

To make it easier to deal with the different parsing exceptions, and how to extract meaningful information out of it, you can use the ErrorHelper.GetErrorMessage() helper method.


Tomas Restrepo

Software developer located in Colombia. Sr. PFE at Microsoft.