Using BizUnit with Visual Studio

Hi everyone,

In the last blog that I did (here) I wrote a short description on how to use LoadGen 2007 to perform a simple Load Test on your BizTalk solution using the FileTransport. In this blog I would like to setup a simple test using BizUnit. If you are already familiar with Unit Testing then you will most likely see the benefits this can provide for your BizTalk environment. There are several different versions of BizUnit. The newest version can be found at www.codeplex.com/BizUnit.For my test I am using version 2.3 (at the time of this writing 3.0 was ready however I was getting Assembly errors while using Visual Studio 2005 so I switched to 2.3). I tested with Visual Studio 2005, BizTalk 2006 R2 and BizUnit 2.3.

STEP 1. Install BizUnit www.codeplex.com/BizUnit (if you check https://bizunit.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=29779 you will see that there are various versions that you can download depending upon your needs)

install directory is %Program Files%\BizUnit\BizUnit 2.3 under this new folder there will be 2 subfolders containing:

  1. Bins folder, containing DLL's that you will need to build you BizUnit tests.
  2. Src folder, containing source code and examples.

STEP 2. Open your Visual Studio 2005 BizTalk Project and add new project to your solution (make sure you choose C# > Test if that is what you wish otherwise you will get default VB > Test)

Besides the usual Properties and References folders you should also see the following files:

  1. AuthoringTests.txt, contains a short description of how to create, run and view test results.
  2. ManualTest1.mht, a template file to aid you if you need to do manual tests as part of your testing regimen. You may remove this if you do not wish to run manual tests.
  3. UnitTest1.cs

STEP 3. In your new Test project add a reference to %Program Files%\BizUnit\BizUnit 2.3\bins\Microsoft.Services.BizTalkApplicationFramework.Bizunit.dll

Create a reference in your VS Test project to the BizUnit dll.

  1. Right click references
  2. browse to where ever your BizUnit is installed, in my case that is: %Program Files%\BizUnit\BizUnit 2.3
  3. add a reference to Microsoft.Services.BizTalkApplicationFramework.BizUnit.dll

STEP 4. Create a Test Case. 

  1. Open UnitTest1.cs or create your own new class, we want to create a reference via an 'using' statement in order to invoke the BizUnit functionality.
  2. VS creates several 'using' references for you already however you will need to add: using Microsoft.Services.BizTalkApplicationFramework.BizUnit;
  3. your class needs the attribute [TestClass] though most likely VS has added this for you already.
  4. now we should also see a Constructor and a default test method (assuming you are using the Default UnitTest1.cs they will be UnitTest1 and TestMethod1 respectively).
  5. I recommend now added a folder to your project called TestCases. There is a wizard that we can use to create tests but lets' keep it simple first.
  6. Right Click folder TestCases and add an XML file called TESTCASE01.xml
  7. Add the following text to the new XML file:

* in this test we are creating 3 separate files Request01.xml, Request500.xml and Request501.xml from your creation folder and dropping them into a File Folder directory which is also the file pickup up point for an endpoint configured (this could be an UNC path) on your BizTalk Solution.

1.

<table>
<tbody>
<tr class="odd">
<td>&lt;TestCase testName="TESTCASE01"&gt;  &lt;TestSetup&gt; &lt;/TestSetup&gt;    &lt;TestExecution&gt;   &lt;TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileCreateStep"&gt;     &lt;SourcePath&gt; <em>%YourPath%</em> \TestCases\Request01.xml&lt;/SourcePath&gt;    &lt;CreationPath&gt; <em>%YourPath%</em> \Filedrop\ReceiveRequest\Request01.xml&lt;/CreationPath&gt;   &lt;/TestStep&gt;   &lt;TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileCreateStep"&gt;    &lt;SourcePath&gt; <em>%YourPath%</em> \TestCases\Request500.xml&lt;/SourcePath&gt;    &lt;CreationPath&gt; <em>%YourPath%</em> \Filedrop\ReceiveRequest\Request500.xml&lt;/CreationPath&gt;   &lt;/TestStep&gt;   &lt;TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileCreateStep"&gt;    &lt;SourcePath&gt; <em>%YourPath%</em> \TestCases\Request501.xml&lt;/SourcePath&gt;    &lt;CreationPath&gt; <em>%YourPath%</em> \Filedrop\ReceiveRequest\Request501.xml&lt;/CreationPath&gt;   &lt;/TestStep&gt;  &lt;/TestExecution&gt;   &lt;/TestCase&gt;</td>
</tr>
</tbody>
</table>
  1. Open the UnitTest1.cs and add the following code to public void TestMethod1():

    BizUnit biz = new BizUnit(@"..\..\..\<YourSolution>\TestCases\TESTCASE01.xml"); //this path depends where you have placed the XML testcase file. biz.RunTest();

STEP 5. Run the Test (Choose Menu > Test > Start Selected Test Project with/without Debugging)

STEP 6. View the Results.