| Arun's profileArun gopalamPhotosBlogLists | Help |
BizTalk TDD - Pipeline ComponentsPipeline ComponentsTesting with Pipeline Component Test library or PipelineObjects.DLLThe Pipeline Component Test Library basically provides a simpler API to the PipelineObjects.dll which comes with the Pipeline.exe tool in the SDK. This is an open source c# library (Winterdom.BizTalk.PipelineTesting)
[Test] public void TestAddNamespacePipelineComponentUsingPTL() { IBaseMessage inputMessage = PTL.MessageHelper.CreateFromStream( MessageHelper.LoadMessage( @"C:\Projects\BMC.Middleware.Sample\BMC.Middleware.Sample.Tests\TestFiles\TestPipelineComponent.xml")); PTL.ReceivePipelineWrapper testPipelineWrapper = PTL.PipelineFactory.CreateEmptyReceivePipeline(); AddNamespace component = new AddNamespace(); component.Namespace = "http://www.MediaCompany.com/Newnamespace"; testPipelineWrapper.AddComponent(component, PTL.PipelineStage.Decode); PTL.MessageCollection outputMessages = testPipelineWrapper.Execute(inputMessage); IBaseMessage outputMessage = outputMessages[0]; StreamReader streamReader = new StreamReader(outputMessage.BodyPart.Data); Assert.AreEqual(streamReader.ReadToEnd(), "<ns0:PurchaseRequest xmlns:ns0='http://www.MediaCompany.com/Newnamespace'></ns0:PurchaseRequest>", "AddNamespace Pipeline Component is not working...:("); } Testing with MocksMock objects are a good way to test if your code uses resources which cannot be created easily. Below is an example of testing using RhinoMock where BizTalk context is mocked. I recommend using the Mocking framework to mock the BizTalk objects if possible if not use the PipelineObjects.DLL.
[Test] public void TestAddNamespacePipelineComponentUsingMock () { Stream messageBodyStream = MessageHelper.LoadMessage(@"C:\Projects\BMC.Middleware.Sample\BMC.Middleware.Sample.Tests\TestFiles\TestPipelineComponent.xml"); messageBodyStream.Seek(0, SeekOrigin.Begin); IBaseMessage inMsg = MessageHelper.CreateFromStream(messageBodyStream);
IResourceTracker mockResourceTracker = _mocks.DynamicMock<IResourceTracker>(); using (_mocks.Record()) { MemoryStream memoryStream = new MemoryStream(); mockResourceTracker.AddResource(memoryStream); LastCall.IgnoreArguments(); Expect.On(_mockContext).Call(_mockContext.ResourceTracker).Return(mockResourceTracker); } using (_mocks.Playback()) { AddNamespace component = new AddNamespace(); component.Namespace = "http://www.MediaCompany.com/Newnamespace"; IBaseMessage outputMessage = component.Execute(_mockContext, inMsg); StreamReader streamReader = new StreamReader(outputMessage.BodyPart.Data); string outMsg = streamReader.ReadToEnd(); Assert.AreEqual(outMsg, "<ns0:PurchaseRequest xmlns:ns0='http://www.MediaCompany.com/Newnamespace'></ns0:PurchaseRequest>", "AddNamespace Pipeline is not working...:("); } } TrackbacksThe trackback URL for this entry is: http://arungopalam.spaces.live.com/blog/cns!F1BE9972412F56CD!775.trak Weblogs that reference this entry
|
|
|