There is one more question about map testing - is it usefull? I believe - YES, but not allways. When you reach some level of complexity and there can be at least some cahanges within map - it is better to have unit tests prepared. For small and simple maps it is unnecessary work. But for big ones, especially with a lot of nested loops - you should have some ways to check what your cahnges are effecting.
BizTalk 2010 already has some generators for unit test. You have to open your solution, then go to Visual Studio 2010 top meniu -> New Test...
After pressing OK, wizard will automatically generate new project inside your solution, add all the required references and generate simple unit test cases for selected classes:
As we see the main line in all tests si map object initialization:
Map1 target = new Map1();
So, the target variable will hold our map, and it can be used to transform required input and output xml files. Here is some code from other map unit test, which is counting few tags from the new document and makes the decision if the map works correctly.
XDocument inputXml = TestingHelperComponents.OpenXmlFile("Transactions.xml"); StringWriter writer = new StringWriter(); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(inputXml.ToString()); target.Transform.Transform(xmlDocument, null, writer); XDocument outputXml = XDocument.Parse(writer.ToString()); string temp = string.Empty; int inCount = inputXml.Descendants("Transactions").Count(); int outCount = outputXml.Descendants("Transactions").Count(); Assert.IsTrue(inCount > 0 && outCount == 0, "Transactions tag count: inCount: " + inCount + " OutCount: " + outCount);
As you see, I am checking only some tag occourence after transformation. This maybe more tedious task, than simple string comparison, but I believe it is more stable - after making some minor changes inside map, there can be cahnges inside the output, which have no effect on the result (from information point of view).
I believe it would be good to make xml comparison method, which could compare inner xml data, regardless to formating, whitespaces, empty or null tags.
In the future I hope to try BizUnit or NUnit for testing BizTalk Solutions.