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:
- Bins folder, containing DLL's that you will need to build you BizUnit tests.
- 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:
- AuthoringTests.txt, contains a short description of how to create, run and view test results.
- 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.
- 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.
- Right click references
- browse to where ever your BizUnit is installed, in my case that is: %Program Files%\BizUnit\BizUnit 2.3
- add a reference to Microsoft.Services.BizTalkApplicationFramework.BizUnit.dll
STEP 4. Create a Test Case.
- 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.
- VS creates several 'using' references for you already however you will need to add: using Microsoft.Services.BizTalkApplicationFramework.BizUnit;
- your class needs the attribute [TestClass] though most likely VS has added this for you already.
- 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).
- 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.
- Right Click folder TestCases and add an XML file called TESTCASE01.xml
- 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><TestCase testName="TESTCASE01"> <TestSetup> </TestSetup> <TestExecution> <TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileCreateStep"> <SourcePath> <em>%YourPath%</em> \TestCases\Request01.xml</SourcePath> <CreationPath> <em>%YourPath%</em> \Filedrop\ReceiveRequest\Request01.xml</CreationPath> </TestStep> <TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileCreateStep"> <SourcePath> <em>%YourPath%</em> \TestCases\Request500.xml</SourcePath> <CreationPath> <em>%YourPath%</em> \Filedrop\ReceiveRequest\Request500.xml</CreationPath> </TestStep> <TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileCreateStep"> <SourcePath> <em>%YourPath%</em> \TestCases\Request501.xml</SourcePath> <CreationPath> <em>%YourPath%</em> \Filedrop\ReceiveRequest\Request501.xml</CreationPath> </TestStep> </TestExecution> </TestCase></td>
</tr>
</tbody>
</table>
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.