public
Description: BizTalk 2006 library for unit-testing pipelines and custom pipeline components
Home | Edit | New

Simple API Examples

The “Simple” API provides a better, simpler to use object model for running tests. The new API doesn’t actually change how you execute a pipeline; instead it focuses on simplifying how you create and configure a pipeline instance.

With the new API, the setup of your tests should be more intuitive to write, you’ll need less code and the result will be a lot more readable.

Using the API

To use the new API you need to import these namespaces:


using Winterdom.BizTalk.PipelineTesting;
using Winterdom.BizTalk.PipelineTesting.Simple;

Running a Standard Pipeline

The following example shows how to create a standard XMLTransmit pipeline, provide a schema to use and execute the pipeline with an input message:


string msgBody = "...";
SendPipelineWrapper pipeline = Pipelines.Xml.Send()
   .WithSpec<Schema1_NPP>();

IBaseMessage output = pipeline.Execute(
   MessageHelper.CreateFromString(msgBody)
);

Batching Messages in a Send Pipeline

This example will create an empty Send pipeline and add a standard XML Assembler and S/MIME encoder components to it. The XML Assembler component will be configured with an Envelope and a Document schema.

The example then feeds multiple messages to the pipeline, batching them into a single output document:


XmlAssembler xml = Assembler.Xml()
   .WithDocumentSpec<SimpleBody>()
   .WithEnvelopeSpec<SimpleEnv>();
SendPipelineWrapper pipeline = Pipelines.Send()
   .WithAssembler(xml)
   .WithEncoder(new MIME_SMIME_Encoder());

// Create the input message to pass through the pipeline
string body =
   "<o:Body xmlns:o='http://SampleSchemas.SimpleBody'>"
 + "this is a body</o:Body>";
// Execute the pipeline, and check the output
// we get a single message batched with all the
// messages grouped into the envelope's body
IBaseMessage outputMessage = pipeline.Execute(
   MessageHelper.CreateFromString(body),
   MessageHelper.CreateFromString(body),
   MessageHelper.CreateFromString(body)
   );
Assert.IsNotNull(outputMessage); 

Parsing a Flat File

This example shows how to create a new receive pipeline from scratch with the Flat File disassembler component, and use it to parse a CSV file:


FFDisassembler ff = Disassembler.FlatFile()
   .WithDocumentSpec<Schema3_FF>();
ReceivePipelineWrapper pipeline = Pipelines.Receive()
   .WithDisassembler(ff);

IBaseMessage input = MessageHelper.CreateFromStream(
   DocLoader.LoadStream("CSV_FF_RecvInput.txt")
   );

MessageCollection output = pipeline.Execute(input);

Assert.AreEqual(1, output.Count); 

Last edited by tomasr, Mon Sep 01 20:02:37 -0700 2008
Home | Edit | New
Versions: