Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

How to Unit Test BizTalk 2006 Orchestrations using BizUnit 2006

3.50/5 (11 votes)
26 Apr 2006CPOL3 min read 1   1.1K  
This article explains how to perform unit testing of BizTalk 2006 Orchestrations using BizUnit 2006

Introduction - Unit Testing

Essentially a Unit Test is a procedure used to validate a particular piece of source code. Effective Unit Testing is vital to the success of any project. Unit Testing results in reduced defects in the next level of testing. Traditionally we have used NUnit to test any assembly (*.DLL). For testing BizTalk Orchestrations, we use a similar approach. We test BizTalk Orchestrations as a Black Box.

Required Downloads

We would need to download the following, in order to perform unit testing of BizTalk Orchestrations.

  • Download BizUnit 2006 from Kevin B. Smith's Blog. The default installation directory of BizUnit would be "C:\Program Files\Microsoft Services\BizUnit 2.1"
  • Download NUnit (NUnit-2.2.8-net-2.0.msi) from NUnit.org The default installation directory of NUnit would be "C:\Program Files\NUnit-Net-2.0 2.2.8"

Overview - Purchase Order Sample

Schemas

The screen shot below shows the Purchase Order (PO) schema and the Purchase Order Acknowledgement (POA) schema.

PO and POA schemas
Image 1 Image 2

Transformation Map - PO to POA

The screen shot below shows the transformation of PO to POA.

Image 3

Orchestration

The screen shot below shows the POProcess Orchestration.

Image 4

ProcessPO Orchestration Summary

  • A PO Request is received by the Receive Shape.
  • A PO Acknowledgement is generated for every PO request.
  • A Send Shape is used to send out the POA message.
  • A Decide Shape is used to set the PO status to either APPROVED or REJECTED.
  • A Send Shape is used to send out the APPROVED or REJECTED PO.

Sample PO Data using InfoPath 2003

The screen shot below shows the sample Purchase Order (PO).

Image 5

Using BizUnit2006 to Perform Orchestration Unit Testing

After the installation of BizUnit2006, create a new "class library" project in Visual Studio 2005 and add the following code as shown below:

C#
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Services.BizTalkApplicationFramework.BizUnit;
using NUnit.Framework;

namespace BizTalkUnitTest
{
    [TestFixture]
    public class TestPO
    {
        public TestPO()
        {
        }

        [TestFixtureSetUp]
        public void Setup()
        {
            // Stopping and Starting BizTalkHostInstance
            BizUnit bizUnit = new BizUnit
		(@"C:\PurchaseOrderSystem\TestCases\Test_Setup.xml", 
                BizUnit.TestGroupPhase.TestGroupSetup);
            bizUnit.RunTest();
        }

        [Test]
        public void ValidatePO_Rejected()
        {
            // Testing Orchestration - PO - Rejection
            BizUnit bizUnit = new BizUnit
		(@"C:\PurchaseOrderSystem\TestCases\Test_1_POSystem.xml");
            bizUnit.RunTest();
        }

        [Test]
        public void ValidatePO_Approved()
        {
            // Testing Orchestration - PO - Approval
            BizUnit bizUnit = new BizUnit
		(@"C:\PurchaseOrderSystem\TestCases\Test_2_POSystem.xml");
            bizUnit.RunTest();
        }
    }
}

Points to Note in the Above Code

C#
using Microsoft.Services.BizTalkApplicationFramework.BizUnit;
using NUnit.Framework;

These references are required to create an instance of BizUnit class and mark the attributes [Test]/[TestFixture] respectively.

C#
BizUnit bizUnit = new BizUnit(@"C:\PurchaseOrderSystem\TestCases\Test_1_POSystem.xml");
bizUnit.RunTest();

Create an instance of BizUnit class (NOTE: The actual test steps and validation is present in the XML file Test_1_POSystem.xml) and invokes the method RunTest.

The BizUnit Test Case XML File

The BizUnit XML file used to test the Orchestration is shown below:

XML
<TestCase testName="Test_1_ProcessPO">

<TestSetup>
</TestSetup>

<TestExecution>
    <TestStep assemblyPath="" typeName=
	"Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileCreateStep">
        <SourcePath>C:\PurchaseOrderSystem\InputFiles\PO_001.xml</SourcePath>
        <CreationPath>C:\PurchaseOrderSystem\POIn\PO_001.xml</CreationPath>
    </TestStep>

    <TestStep assemblyPath="" typeName=
	"Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileValidateStep">
        <Timeout>60000</Timeout>
        <Directory>C:\PurchaseOrderSystem\POAckOut</Directory>
        <SearchPattern>*.xml</SearchPattern>
        <DeleteFile>true</DeleteFile>

        <ValidationStep assemblyPath="" typeName=
	"Microsoft.Services.BizTalkApplicationFramework.BizUnit.XmlValidationStep">
            <XmlSchemaPath>C:\PurchaseOrderSystem\POA.xsd</XmlSchemaPath>
            <XmlSchemaNameSpace>http://PurchaseOrderSystem.POA</XmlSchemaNameSpace>
            <XPathList>
                <XPathValidation query="/*[local-name()='POAck' and 
                namespace-uri()='http://PurchaseOrderSystem.POA']/
				*[local-name()='PONum' and 
                namespace-uri()='']">PO_001</XPathValidation>
                <XPathValidation query="/*[local-name()='POAck' and 
                namespace-uri()='http://PurchaseOrderSystem.POA']/
				*[local-name()='POItemsCount' and 
                namespace-uri()='']">2</XPathValidation>
            </XPathList>
        </ValidationStep>
    </TestStep>

    <TestStep assemblyPath="" typeName=
	"Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileValidateStep">
        <Timeout>60000</Timeout>
        <Directory>C:\PurchaseOrderSystem\POOut</Directory>
        <SearchPattern>*.xml</SearchPattern>
        <DeleteFile>true</DeleteFile>

        <ValidationStep assemblyPath="" typeName=
	"Microsoft.Services.BizTalkApplicationFramework.BizUnit.XmlValidationStep">
            <XmlSchemaPath>C:\PurchaseOrderSystem\PO.xsd</XmlSchemaPath>
            <XmlSchemaNameSpace>http://PurchaseOrderSystem.PO</XmlSchemaNameSpace>
            <XPathList>
                <XPathValidation query="/*[local-name()='PORequest' and 
                namespace-uri()='http://PurchaseOrderSystem.PO']/
				*[local-name()='PONum' and 
                namespace-uri()='']">PO_001</XPathValidation>
                <XPathValidation query="/*[local-name()='PORequest' and 
                namespace-uri()='http://PurchaseOrderSystem.PO']/
				*[local-name()='POStatus' and 
                namespace-uri()='']">REJECTED</XPathValidation>
            </XPathList>
        </ValidationStep>
    </TestStep>

</TestExecution>

<!-- Test cleanup: test cases should always 
leave the system in the state they found it -->
<TestCleanup>

</TestCleanup>

</TestCase>

XML TestCase - Points to Note

  • The XML file is divided into three sections:
    • TestSetup
    • TestExecution
    • TestCleanup
  • The TestExecution step has several TestStep tags. Each TestStep performs one activity.
  • In the above example, the TestStep checks the folder C:\PurchaseOrderSystem\POAckOut for the POAck XML file. The ValidationStep validates the XML file with the schema and also the values in the elements/attributes of the XML document. In this way, we can setup the test conditions for the generated POAck XML file.
  • We would need to build this DLL and copy it, in the NUnit project folder.
  • Refer to the help file Microsoft.Services.BizTalkApplicationFramework.BizUnit.chm for more description of the XML tags.

NUnit GUI

The screen shot below shows the NUnit GUI:

Image 6

Event Viewer

The screen shot below shows the Event Viewer, observe the events listed.

Image 7

About the Downloadable Code

  • Unzip the zip file in the C:\ drive.
  • Use the PurchaseOrderSystem.BindingInfo.xml file to create the send and receive ports.
  • The PO sample is placed in the InputFiles directory.

History

  • 27th April, 2006: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)