July 2008 Entries

If you're using BizTalk Server maps, it is about 99.999% likely that you are using logic in them.  Testing this functionality in Visual Studio can be tedious as the only way to change the test document is in the properties of the map.  So if you have quite a few scenarios to test, this method sucks.  BizTalk Server 2000 and 2002 allowed you to select the test document at runtime, which was nice I suppose but it still meant that you had to do it manually all the time.

With the exception of either figuring out how to use BizUnit and actually deploying your solution, there are not too many ways to quickly test multiple scenarios of documents in your maps.  I wanted to create a series of tests for a project that I was working on so that I could very quickly test the outcome of my BizTalk Server maps and essentially 'tick some boxes' before moving in to system testing.  There is nothing worse than a BizTalk Server deploy just to find out you've forgotten something that is key in your map.

Using BizTalk Server Maps in Code

I use Test Projects in Visual Studio to do a majority of my unit tests have recently stopped using NUnit.  What I wanted was a nice way to simply perform multiple BizTalk Server map tests at the click of a button.  Saving me a great deal of time and helping me to ensure my deployments contain maps that fulfil the project requirements.

I'll not go in to how to create the actual test projects, the purpose of this article is to call a BizTalk Server map in code so that we can examine the output.

In order to reference BizTalk Server maps, you must first add a reference to Microsoft.XLANGs.BaseTypes which can be found in C:\Program Files\Microsoft BizTalk Server 2006\Microsoft.XLANGs.BaseTypes.dll or wherever you ended up installing BizTalk Server.  Once you have this, it's actually pretty simple (although it took me a while to figure everything out and I was trying to do stuff manually that was already done for me).

Below is the code I used to execute a map.

// Create an instance of the map from the BizTalk Server project
MyBizTalkProjects.Schemas.MapProduct map = new MyBizTalkProjects.Schemas.MapProduct();

// Create an XPath document based on the XML file that is our source
System.Xml.XPath.XPathDocument source;

// Open the XML document from the file system and load it in to the XPath document
using (
    System.IO.StreamReader sRead = new StreamReader(
        @"D:\BraitrimDotNet\BizTalk\Schemas TestProject\EBizDocuments\DespatchConfirmation.xml"
        )
    )
{
    source = new System.Xml.XPath.XPathDocument(sRead);
}

// This took a while to figure out.  Essentially the map is a fully declared XslTransform.  as such, the
// extension objects (i.e. functiod references) are already referenced and so we can use this reference
// rather than trying to build it ourselves.
System.Xml.Xsl.XsltArgumentList args = map.TransformArgs;

// Set the XmlReader to the transorm.
System.Xml.XmlReader xReader = map.Transform.Transform(source, args);

// Perform the transform and load it in to an XmlDocument for examination
System.Xml.XmlDocument result = new System.Xml.XmlDocument(xReader.NameTable);
result.Load(xReader);

Once I have the XmlDocument, I can simply use XPath queries to check values in the XML match my anticipated output.

In Visual Studio, I essentially create a test method for piece of map logic that I want to test.  That way, when I run my tests from the Test View window, I can quickly see what has worked and what has not.


Bookmark with :
Digg It! DZone StumbleUpon Technorati Reddit Del.icio.us Newsvine Furl Blinklist

I tend to spend a lot of time adding assemblies to the GAC (Global Assembly Cache) in order to run unit tests or work with BizTalk Server assemblies.  Usually, I'll do this using the Visual Studio command prompt or the .Net configuration tool. I wanted to find a marginally quicker way to add assemblies to the GAC so I started to look at the 'Send To' menu.

In order to add shortcuts to your 'Send To',  simply navigate to the following folder:

  • C:\Documents and Settings\<User Name>\SendTo

In here you can create simple shortcuts to applications.  So for example you can add a 'Send To Notepad' shortcut.  I'm not going to go in to all of the detail of creating a shortcut here though.

What I wanted to do was add shortcut to gacutil.exe.  The first thing to think about is where Microsoft decided to put the thing in your particular version of .Net.  To help you here, I created a little list of places that you are likely to find gacutil.exe for different versions of the framework

Framework Version Possible Locations
1.0 C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705
1.1 C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322
2.0 C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\bin\
3.0 C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin  (not too sure about this one)
3.5 C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin

Once you've located your gacutil.exe, create a shortcut to it in the SendTo folder mentioned above.  In order to get it to work, simply modify the target of the shortcut so that there is a '/i' at the end of the target (outside of the quotes) as in the following diagram:

SendToGAC

That should do it, from now on you should get the following in your context menu:

SendToGAC_inuse


Bookmark with :
Digg It! DZone StumbleUpon Technorati Reddit Del.icio.us Newsvine Furl Blinklist