Geeks With Blogs
Nigel Parker BizTalk 2004 Developer - Auckland, New Zealand,

Nikolai a colleague of mine at Intergen is a huge advocate for “Test  Driven” development using nunit .

 

He has been using a technique which includes wrapping unit tests around methods written in C# assemblies that called from within the mapper in BizTalk.

 

An example of a method that you might like to use in an assembly is to convert from one DateTime format to another e.g.

 

public string convertDateTimeFormat(string dateIn, string dateInPattern, string dateOutPattern)

{

string dateOut = null;

 

       try

       {

              DateTime d = DateTime.ParseExact(dateIn,dateInPattern,new DateTimeFormatInfo(),DateTimeStyles.AllowWhiteSpaces);

              dateOut = d.ToString(dateOutPattern);

       }

       catch(Exception e)

       {

       }

      

return dateOut;

}

 

A test harness for this method could look something like:

 

[Test]

public void Test_convertDateTimeFormat()

{

       string convertDT = commonFunctions.convertDateTimeFormat("20040415 ","yyyyMMdd","yyyy-MM-ddTHH:mm:ss");

       Assert.AreEqual("2004-04-15T00:00:00",convertDT,@"CORRECT. 20040415 converted to 2004-04-15T00:00:00");

       Console.WriteLine(convertDT);

 

       convertDT = commonFunctions.convertDateTimeFormat("20041304 ","yyyyMMdd","yyyy-MM-ddTHH:mm:ss");

       Assert.AreEqual(null,convertDT,@"CORRECT. incorrect date format");

       Console.WriteLine(convertDT);

 

       convertDT = commonFunctions.convertDateTimeFormat("20041504 ","yyyyddMM","yyyy-MM-ddTHH:mm:ss");

       Assert.AreEqual("2004-04-15T00:00:00",convertDT,@"CORRECT. incorrect date format");

       Console.WriteLine(convertDT);

}

 

I have also been using this technique and have found that it provides you with the considerable advantage of being able to recheck all your assemblies with one button click after you make changes to anything in your underlying assembly.

 

 

I have written an end-to-end example that deals with the scenario of receiving a Purchase Order transforming it to another format using a map and an external assembly and then outputting the transformed Purchase order to the file system. I have included a unit test harness for the assembly that I have used in the sample. The sample is available at http://www.gobeyond.net.nz/Files/TestDrivenAssemblies.zip (extract all to c:\)

 

To deploy the sample you will need to perform the following steps:

  1. Open the solution in Visual Studio.
  2. Build the solution “Right click solution and select Build Solution”.
  3. Ensure that the dll for each project are created in the bin\Debug\ directory and that the Configuration Properties/Deployment/Server value is still showing as (LOCAL) for each BizTalk project.
  4. Select “Deploy BizTalk Solution” from the Tools menu in Visual Studio. If it's not there follow the instructions to bootstrap NANT to the Visual Studio Tools menu in the appendix below.

To run the unit tests:

  1. Open C:\Dev\Intergen.TestDrivenAssemblies\DEPLOYTOOLS\NUnitSubset\nunit-gui.exe, you will need to have nunit installed, download the latest version from http://www.nunit.org/ .
  2. File/ Open/ C:\Dev\Intergen.TestDrivenAssemblies\Intergen.TestDrivenAssemblies.UnitTests\bin\Debug\Intergen.TestDrivenAssemblies.UnitTests.dll then click “RUN”.

N.B. After deploying the solution the components assembly will be loaded into the GAC you will need to remove it from here (Go to C:\WINDOWS\assembly and right click on Intergen.TestDrivenAssemblies.Components and choose delete) before you will be able to run any new unit tests.

 

To test the sample perform the following steps:

  1. Copy the file “C:\Dev\Intergen.TestDrivenAssemblies\TEST\PO_101.xml” into the “C:\Dev\Intergen.TestDrivenAssemblies\TEST\IN” directory.
  2. Open the file that is written to the “C:\Dev\Intergen.TestDrivenAssemblies\TEST\OUT” directory.

More about Test-Driven Development in Integration Projects -  http://www.eaipatterns.com/docs/TestDrivenEAI.pdf

 

Appendix A: Bootstrapping NAnt in Visual Studio

 

To get started with NAnt, you can follow these steps:

 

1.      Download the latest NAnt (currently 0.84) from http://nant.sourceforge.net and unzip it under C:\Program Files\NAnt.

2.      Download the latest NAntContrib release from http://nantcontrib.sourceforge.net and copy all files in NAntContrib's bin directory into NAnt's bin directory.

3.      In C:\Program Files\NAnt\bin\NAnt.exe.config change the default framework to 1.1

4.      Create a VS.NET External tool (Tools-External Tools-Add), with:

 

Title: Deploy BizTalk Solution

Command: C:\Program Files\NAnt\bin\NAnt.exe

Arguments: /f:"$(SolutionDir)\$(SolutionFileName).deploy.build" debug.deploy 

Initial Directory: $(SolutionDir)

(You can create a variation for release deployments if you like.)

 

Turn on the “Use Output Window” checkbox.

Posted on Tuesday, November 16, 2004 6:53 PM BizTalk Tips & Tricks | Back to top


Comments on this post: Using test driven assemblies inside transformations… *BizTalk 2004 Sample*

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Nigel Parker | Powered by: GeeksWithBlogs.net