Arun's profileArun gopalamPhotosBlogLists Tools Help

Blog


    BizTalk TDD - Pipeline Components

    Pipeline Components

    Testing with Pipeline Component Test library or PipelineObjects.DLL

    The 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 Mocks

    Mock 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...:(");

    }

    }

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://arungopalam.spaces.live.com/blog/cns!F1BE9972412F56CD!775.trak
    Weblogs that reference this entry
    • None