Home Page › Forums › BizTalk 2004 – BizTalk 2010 › NUnit Test for Custom Pipelines
- This topic has 3 replies, 1 voice, and was last updated 9 years, 2 months ago by
community-content.
-
AuthorPosts
-
-
December 22, 2005 at 10:17 PM #12563
Is there any documentation for testing custom pipelines with nunit.
We have created a custom pipeline using the HL7 accelerater and we would like add some unit testing functionality to the project.
I’m having problems creating the IPipelineContext and the IBaseMessage
Help!
-
January 3, 2006 at 11:51 AM #12564
[quote:4b69f03814=\”beewil \”]Is there any documentation for testing custom pipelines with nunit.
We have created a custom pipeline using the HL7 accelerater and we would like add some unit testing functionality to the project.
I’m having problems creating the IPipelineContext and the IBaseMessage
Help![/quote:4b69f03814]
well, you could call pipeline.exe (<installlocation>\\SDK\\Utilities\\PipelineTools) to execute your pipeline programmatically. This utility allows you to pass in the document (message) and schema and obtain the resulting message at the end of the pipeline.
-
January 3, 2006 at 12:47 PM #12565
[quote:eb983a3758=\”beewil \”]Is there any documentation for testing custom pipelines with nunit.
We have created a custom pipeline using the HL7 accelerater and we would like add some unit testing functionality to the project.
I’m having problems creating the IPipelineContext and the IBaseMessage
Help![/quote:eb983a3758]
In fact, going further, to make this completely programmatic you can make use of the PipelineObjects assembly in the same location. You can call this as shown below to exceute an arbitrary pipeline as a unit test.
In this case I am just calling the standard passthru receive pipeline and passing a simple xml message. I then output the resulting message at the end of the pipeline showing the same message as was entered.
PipelineFactory factory = new PipelineFactory();
string pipelineName = \”Microsoft.BizTalk.DefaultPipelines.PassThruReceive, Microsoft.BizTalk.DefaultPipelines, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\”;
IPipeline p = factory.CreatePipelineFromType(pipelineName);
MessageFactory msgFactory = new MessageFactory();
IBaseMessage message = msgFactory.CreateMessage ();
IBaseMessageContext context = msgFactory.CreateMessageContext();
PipelineContext ctx = new PipelineContext();XmlDocument doc = new XmlDocument();
doc.LoadXml(\”<test><this>is a test</this></test>\”);IBaseMessagePart part = msgFactory.CreateMessagePart();
Stream s = new MemoryStream();
doc.Save(s);
s.Seek(0,0);
part.Data = s;
message.AddPart(\”part\”,part,true);
p.InputMessages.Add (message);p.Execute(ctx);
IBaseMessage output = p.GetNextOutputMessage(ctx);
while (output != null)
{
byte[] buffer = new byte[output.BodyPart.Data.Length];
output.BodyPart.Data.Read(buffer,0,(int)output.BodyPart.Data.Length);
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
string result = new string(encoding.GetChars(buffer));
Console.WriteLine(result);
output = p.GetNextOutputMessage(ctx);
}you’ll need to add the following ‘using’ clauses to the class file to compile it:
using Microsoft.BizTalk.Message.Interop; // from microsoft.biztalk.pipeline.dll
using Microsoft.Test.BizTalk.PipelineObjects; // from PipelineObjects.dll
using System.Xml;
using System.IO;-
December 28, 2005 at 10:19 PM #12566
Sorry, I do not know of any way to test it using NUnit.
What I did in the past using NUnit for Orchestration was expose them as web service. Then, I made a call and waited for the response file. You could try something like that. Not very programmatic though.
I’d be curious how it works out for you.
-
-
-
-
AuthorPosts
- The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.