Click here to Skip to main content
Click here to Skip to main content

How to Unit Test BizTalk 2006 Orchestrations using BizUnit 2006

By , 26 Apr 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

Transformation Map - PO to POA

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

Orchestration

The screen shot below shows the POProcess Orchestration.

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).

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:

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

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.

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:

<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:

Event Viewer

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

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)

About the Author

Naveen Karamchetti
Architect
United States United States
Member
Naveen has done his Masters (M.S.) in Computer science, has started his career programming the mainframes and now has more than a decade of programming, development and design experience. Naveen has a sharp eye and keen observation skills. Naveen has worked for several companies and strived hard to build large scale business applications and bringing better solutions to the table.
Quite recently Naveen has built a fairly complex integration platform for a large bank. His hobbies include training, mentoring and research. Naveen spends his free time visiting National Parks nationwide.
 
Naveen has developed the BizTalk Control Center (BCC)
http://biztalkcontrolcenter.codeplex.com

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralA new BizTalk unit testing framework you might be interested in ...memberAli Kheyrollahi9 Mar '09 - 1:19 
http://www.codeproject.com/KB/biztalk/Excellence.aspx[^]
GeneralRe: A new BizTalk unit testing framework you might be interested in ...memberBruno Spinelli22 Feb '10 - 8:44 
Interesting, more details on how to Unit Test a BizTalk solution here: http://whiteboardworks.com/
GeneralBizUnit testing with the "FactBasedRuleEngineStep"memberONeil Tomlinson30 Oct '08 - 2:10 
Hi
Im trying to write a business rule bizunit test (using the FactBasedRuleEngineStep). the problem is that i dont understand what each element in the test represents. from the bizunit documentation there is a sample and brief description of the elements but its not emough to get an understanding, the description for the elements are as below. but they are no help really.
 

RuleStoreName-----------------The location of the rule store
RuleSetInfoCollectionName-----The name of the rule set collection
DebugTracking------------------Location of the debug tracking
ResultFilePath----------------The path used to write updated fact documents to
Facts---------------------Facts to pass to rules engine prior to ruleset execution
 

I have a Policy.xml, Vocab.xml and a InputData.xml file located at (c:\BizApp\TestApp). how do i fit this information in the sample file that comes with bizunit documentation?
Thanks ONeil
Questioncan you get a example on this orchestration by LoadGen?memberetehadi2 Aug '08 - 23:49 
can you get a example on this orchestration by LoadGen?
please.
it could be beter if the orchestration was one of example published by microsoft as tutorial or sample
thank you.
QuestionBizUnit using the "FileValidateStep"memberONeil Tomlinson24 Jun '08 - 23:24 
Hi
I have a bizUnit test case that I just can get working. Can anyone help please
 
(1) This is the Test Case
#######################################################
[Test]
public void Test_04_ValidateDenied()
{
BizUnit bizUnit = new BizUnit(@"C:\Development\DeniedValidation.xml");
bizUnit.RunTest();        
#############################################################
 

 

(2)This is the "DeniedValidation.xml" configuration file
#############################################################
<TestCase testName="Test_1_ProcessPO">  
<TestExecution>
<TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileValidateStep">
            <Timeout>60000</Timeout>
            <Directory>C:\Development\Filedrop\RequestDenied\</Directory>
            <SearchPattern>Denied*.xml</SearchPattern>
            <DeleteFile>true</DeleteFile>
 
            <ValidationStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.XmlValidationStep">
                  <XmlSchemaPath>C:\Development\ \EAISchemas1\RequestDenied.xsd</XmlSchemaPath>
                  <XmlSchemaNameSpace>http://EAISchemas1.RequestDenied</XmlSchemaNameSpace>
 
                  <XPathList>
                  <XPathValidation query="/*[local-name()='DeclineReq' and namespace-uri()='']/*[local-name()='ReqID' and namespace-uri()='']/text()">R12345_</XPathValidation>
                  </XPathList>
            </ValidationStep>
      </TestStep>
</TestExecution>
</TestCase>
#############################################################
 

 
(3)This is the denied.xml file
#############################################################
<DeclineReq>
      <ReqID>R12345_</ReqID>
      <Qty>600</Qty>
</DeclineReq>
#############################################################
 

(4) and Im geting the folowing error
########################################################
Data: Loaded FILE: C:\Development\Denied{3EAACFB0-6B7F-407A-8E3B-1C5B648EB516}.xml
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<ns0:DeclineReq xmlns:ns0="http://EAISchemas1.DeclineReq1"><ReqID>R12345_</ReqID><Qty>600</Qty></ns0:DeclineReq>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Validation: Microsoft.Services.BizTalkApplicationFramework.BizUnit.XmlValidationStep started @ 09:53:33.021 25/06/2008
Info: XmlValidationStep evaluting XPath /*[local-name()='DeclineReq' and namespace-uri()='']/*[local-name()='ReqID' and namespace-uri()='']/text() equals "R12345_"
*******************************************************************************
Error: Exception caught!
System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Services.BizTalkApplicationFramework.BizUnit.XmlValidationStep.ExecuteValidation(Stream data, XmlNode validatorConfig, Context context)
   at Microsoft.Services.BizTalkApplicationFramework.BizUnit.BizUnit.ExecuteValidator(Stream data, XmlNode validatorConfig, Context ctx)
   at Microsoft.Services.BizTalkApplicationFramework.BizUnit.Context.ExecuteValidator(Stream data, XmlNode validatorConfig)
   at Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileValidateStep.Execute(XmlNode testConfig, Context context)
   at Microsoft.Services.BizTalkApplicationFramework.BizUnit.BizUnit.ExecuteSteps(XmlNodeList steps)
*******************************************************************************
###########################################################
 

What am i doing wrong?
GeneralBizUnit DesignermemberMember 203831923 Mar '08 - 3:26 
You may want to check out BizUnit Designer - a GUI that allows rapid creation of BizUnit test cases which can be used for unit testing or system testing distributed applications.
 
Makes creation of test cases a snap using its graphical interface.
 
http://www.codeplex.com/bud[^]
GeneralBinding Info Problem...memberrajatpk29 Nov '07 - 8:49 
Naveen,
 
Thanks for your wonderful article. I'm getting the below issue.
 
Failed to update binding information.Can’t update Send Port and Transport information.
 
Please suggest me...
 
Thanks,
Raja Kumaravel
GeneralBizUnit Error! The path is not of legal form!memberChenue10 May '07 - 4:48 
Downloaded the libraries, setup everything and tried to run the BizUnit Test.
 
Kept on spitting 'The path is not of legal form'. Help me out someone! Thanx.Mad | :mad: Mad | :mad:
GeneralRe: BizUnit Error! The path is not of legal form!memberNaveen Karamchetti10 May '07 - 4:52 
The Nunit project file and the dll might have to be present in the same directory. Can you try this and let me know...
 
Always be there....| MCSD.NET | Sun Certified...

GeneralRe: BizUnit Error! The path is not of legal form!memberChenue10 May '07 - 22:22 
I did just that and I got the following error message:
 
'BizTalkUnitTest.TestPO (TestFixtureSetUp) : The path is not of a legal form.'
 
When I click on the error message the following details come up:
 
'at Microsoft.Services.BizTalkApplicationFramework.BizUnit.BizUnit.TearDown()
at Microsoft.Services.BizTalkApplicationFramework.BizUnit.BizUnit.RunTest()
at BizTalkUnitTest.TestPO.Setup() in C:\BizTalkUnitTest\TestPO.cs:line 21 '
GeneralBizUnit with SOAPmemberBizTalkFreak12 Mar '07 - 7:23 
HI Your post was really helpfull and I was able to test with Sql Adapter in my orchestration but when I try to use soap adapter it doesnot work. It gives the following error
 
Following is the test step that I am trying to use
 


<!--Parameters that are passed in the step-->

WebServiceWSDLURL http://localhost/POWebService/SubmitPOService.asmx?wsdl
ServiceName SubmitPOService
WebMethod submitPO
InputMessageTypeName InboundPO
MessagePayload .\ConsumeWebService\ConsumeWebServiceInput.xml
 

 
The web service sample is available with BizTalk 2006 samples in sdk under orchestration
 
System.InvalidOperationException: There is an error in XML document (1, 2). ---> System.InvalidOperationException: was not expected.
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderInboundPO.Read3_InboundPO()
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader)
at Microsoft.Services.BizTalkApplicationFramework.BizUnit.SOAPHTTPRequestResponseStep.LoadMessage(Assembly assembly, String msgTypeName, String messagePath) in C:\Projects\BizUnit2006\src\BizUnit\TestSteps\SOAPHTTPRequestResponseStep.cs:line 277
at Microsoft.Services.BizTalkApplicationFramework.BizUnit.SOAPHTTPRequestResponseStep.Execute(XmlNode testConfig, Context context) in C:\Projects\BizUnit2006\src\BizUnit\TestSteps\SOAPHTTPRequestResponseStep.cs:line 115
at Microsoft.Services.BizTalkApplicationFramework.BizUnit.BizUnit.ExecuteSteps(XmlNodeList steps) in C:\Projects\BizUnit2006\src\BizUnit\BizUnit.cs:line 499
 

 
Any Help is appreciated
GeneralBizUnit with SOAPmemberBizTalkFreak12 Mar '07 - 7:16 
HI Your post was really helpfull and I was able to test with Sql Adapter in my orchestration but when I try to use soap adapter it doesnot work. It gives the following error
 
Following is the test step that I am trying to use
 
<!--Creating the file to be dropeed in the in folder-->




 
<!-- SOAP Testing-->

http://localhost/POWebService/SubmitPOService.asmx?wsdl
SubmitPOService
submitPO
<InputMessageTypeName>InboundPO</InputMessageTypeName>
C:\Program Files\Microsoft BizTalk Server 2006\SDK\Samples\Orchestrations\ConsumeWebService\ConsumeWebServiceInput.xml
 
<!--
<XmlSchemaPath takeFromCtx="OutputSchemaFile"></XmlSchemaPath>
<XmlSchemaNameSpace takeFromCtx="TargetNamespace"></XmlSchemaNameSpace>
-->

 
The web service sample is available with BizTalk 2006 samples in sdk under orchestration
 
System.InvalidOperationException: There is an error in XML document (1, 2). ---> System.InvalidOperationException: was not expected.
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderInboundPO.Read3_InboundPO()
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader)
at Microsoft.Services.BizTalkApplicationFramework.BizUnit.SOAPHTTPRequestResponseStep.LoadMessage(Assembly assembly, String msgTypeName, String messagePath) in C:\Projects\BizUnit2006\src\BizUnit\TestSteps\SOAPHTTPRequestResponseStep.cs:line 277
at Microsoft.Services.BizTalkApplicationFramework.BizUnit.SOAPHTTPRequestResponseStep.Execute(XmlNode testConfig, Context context) in C:\Projects\BizUnit2006\src\BizUnit\TestSteps\SOAPHTTPRequestResponseStep.cs:line 115
at Microsoft.Services.BizTalkApplicationFramework.BizUnit.BizUnit.ExecuteSteps(XmlNodeList steps) in C:\Projects\BizUnit2006\src\BizUnit\BizUnit.cs:line 499
 

 
Any Help is appreciated
GeneralRe: BizUnit with SOAP [modified]memberofilipe7 Feb '08 - 6:03 
I have the same problem.
I can't test it with SOAP.
 

I tried this:
 
<testexecution>
<teststep assemblypath="" typename="Microsoft.Services.BizTalkApplicationFramework.BizUnit.HttpRequestResponseStep">
<sourcepath>F:\Biztalk\InputFiles\Input.xml</sourcepath>
<destinationurl>http://localhost:88/webservice/webservice.asmx</destinationurl>
<requesttimeout>60000</requesttimeout>
     
<!-- Optional
<ValidationStep></ValidationStep>
-->
</teststep>
</testexecution>
 

But had no sucess. Mad | :mad:
 
#############################################
Correction...
 
Ok I found my problem.
The problems was related with the F:\Biztalk\InputFiles\Input.xml, this file must be some thing like this:
 

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <MySchemaName xmlns="http://tempuri.org/">
         <MySchemaRoot>
               <header>....</header>
               <body>.......</body>
         </MySchemaRoot>
      </MySchemaName>
   </soap:Body>
</soap:Envelope>
 
####################
I was trying to use (no more than an "generated instance" of my webservice input schema):
####################
 
<MySchemaName xmlns="http://tempuri.org/">
   <MySchemaRoot>
               <header>....</header>
               <body>.......</body>
      </MySchemaRoot>
</MySchemaName>
 
<div class="ForumMod">modified on Friday, February 8, 2008 9:11 AM</div>

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 27 Apr 2006
Article Copyright 2006 by Naveen Karamchetti
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid