While working on the BTS2013 project, I started writing unit test for Schemas and Maps. I found that unit test for maps do not work anymore with the BTS2013 upgrade. I keep on getting “Transform failure” error messages. I with the help of one of my colleague figure out actually Microsoft had missed on to upgrade TestableMapBase class. They still using the BTSXslTransform instead of using XslCompiledTransform.
This post is to show how we can resolve this issue by creating wrapper class and changing the TestableMapBase class to use XslCompiledTransform.
I used reflector to pull out source code from the Microsoft.BizTalk.TestTools. Re-factor it to use in the wrapper class and change the use of BTSXslTransform to XslCompiledTransform and re-written the PerformTransform method as per below.
The below code is using XslCompiledTransform method rather then BTSXslTransform in TestMapTransform.cs.
The below code is re-written to call Transform Load and transform method in TestableMapBase.cs.
To prove this I have created the two test method, TestMethod (Unit_Sample) is referencing our wrapper class and other is TestMethod (Unit_Sample_2) is using the Microsoft BizTalk Test tools.
You can see from the below that the Unit_Sample passed the unit test while Unit_Sample_2 failed.
The unit test source code is on https://skydrive.live.com/redir?resid=867C3BC1B30476B2%21149. Happy doing unit test now :). Thank you Johaan for sticking with me :).
Regards,
Shadab
Reblogged this on Adventures inside the Message Box and commented:
Shadab has written a good post on how you can write a wrapper for the TestableMapBase class to get around current problems with BizTalk 2013 map unit tests. Come on Microsoft, fix this soon….I suppose we should log it first 🙂
Pingback: Beta release BizTalk Sofware Factory for BizTalk Server 2013 - Jean-Paul Smit
Does the latest CU correct this problem? The fix list doesn’t suggest this is the case: http://support.microsoft.com/kb/2892599. Has the issue been logged ? 🙂
P.S. The SkyDrive link for the code just comes up with “This item might not exist or is no longer available”
Hi Simon,
Thank you for the comment.
Well it dosen’t look like it is fixed in the latest CU. However, I haven’t yet applied the CU on machines. I will be doing this later this month.
The SkyDrive link appears to be working :), however I have send you the shared link on your email.
Many thanks.
Shadab
Thanks Shadab.
Pingback: [BizTalk 2010] Testing a multiple input map with Visual Studio 2010 - Jean-Paul Smit
Hi,
I am also facing the same issue. And whenever I click on download in skydrive, I am getting message “item doesnt exist or item no longer available”. can you please send me downloadable link or content.
Thanks
Can you check the link now?
Alas you can access from here https://skydrive.live.com/redir?resid=867C3BC1B30476B2%21106
Please let me know if it doesent work.
Regards
Hi, whenever I build the code, am getting reference errors with Datacom and LIC dlls. I am not able to run the code. Can you please send me reference to those dlls. thank you so much.
Please send me source code of those wrapper if you can. Is there any fix release for this from microsoft? literally struck with map testing. Dont know what to use for map testing ?
I am not sure if this has been resolved in CU2 from Microsoft. The code which I send you is what I can send. It should work for you, you should not be needing a wrapper classes.
The code sample is just unit tests. It does not include the replacement for TestableMapBase where it is changed to use XslCompiledTransform. I assume the code is in the Datacom.BizTalk.TestTools DLL which is not supplied. There are snippets in the screen shots but the full code would be helpful.
Hello,
I too am unable to get the link to function properly. Could you please send me the link.
Greatly appreciated 🙂
Hi There,
Sorry for the broken link. It looks like it is working now.
Regards
Shadab
Shadabanwer,
Thank you for your quick response. I was able to understand your examples, was the goal from your post to have others include your refactor of the Testable map class dll until the CU updates corrects this oversight by Microsoft?
If this was not the case, do you plan on sharing the internal code refactoring performed, such as the screen shots indicate?
Thanks again
Hey Ryan, Did you installed CU2 updates from MS? It is available now, try and see if this has been resolved. The goal of the post was to let people know that there is issue with the Map unit test, so that people do not waste their time. I cannot send the internal code, it is internal to our company, sorry about that. Let me know how you go with the CU2.
Regards
Shadab
Shadabanwer,
I did install both CU1 & CU2 before attempting my unit testing. I use a SQL ce 4.0 .sdf to store values and then dynamically build the input schema, then test the map for an automated build option. I stumbled upon your post after searching on the error message. In the meantime ill use your .dll with thanks, since basic map testing within the context menu is operational for others its not a high priority. Its kinda like the ESB portal its broken right out of the box… Welcome to BizTalk, always an adventure 🙂
Suggested implementation of the PerformTransform method in the article does not work if a map contains custom referenced functoids. You should always use Transform method that takes TransformArgs parameter, which can be null. Also, original Microsoft’s implementation of the PerformTransform method contained a bug that prevented an original exception thrown by the Transform method to be reported. Here is my version of the PerformTransform method
private void PerformTransform(string inputXmlFile, string outputXmlFile)
{
try
{
var transform = new XslCompiledTransform();
using (var stylesheet =
new XmlTextReader(new StringReader(this.mapper.XmlContent)))
{
transform.Load(stylesheet, new XsltSettings(true, true), null);
}
using (var input = XmlReader.Create(inputXmlFile))
{
input.MoveToContent();
var settings = new XmlWriterSettings
{
Indent = true,
IndentChars = “\t”
};
using (var results = XmlWriter.Create(outputXmlFile, settings))
{
transform.Transform(input, this.mapper.TransformArgs, results);
}
}
}
catch (Exception exception)
{
string errorMessage = string.Format(CultureInfo.InvariantCulture,
Resource.IDS_ERROR_UNABLETOWRITEOUTPUTINSTANCE, outputXmlFile);
StringBuilder builder = new StringBuilder(errorMessage);
for (var currentException = exception; currentException != null; currentException = currentException.InnerException)
{
builder.Append(“\t\n”).Append(currentException.Message);
}
throw new BizTalkTestAssertFailException(builder.ToString());
}
}
Pingback: BizTalk Server 2013: Step-by-Step to implement Unit Testing in Schemas and Maps | Sandro Pereira BizTalk Blog
It seems that BTS2013r2 still has a problem when testing maps to flat file, http://stackoverflow.com/questions/27704034/testable-map-base-xml-to-flat-file-fails-in-bts2013r2
Hi Shadab,
Fyi, an alternative is to create a .testsettings file which forces MSTest to run the test in 32-bit mode – that seems to stop the problem from happening.
See:
https://sandroaspbiztalkblog.wordpress.com/2014/08/28/biztalk-server-2013-step-by-step-to-implement-unit-testing-in-schemas-and-maps/#comment-17098
http://geekswithblogs.net/michaelstephenson/archive/2013/05/05/152868.aspx
https://sandroaspbiztalkblog.wordpress.com/2014/08/28/biztalk-server-2013-step-by-step-to-implement-unit-testing-in-schemas-and-maps/#comment-17138
Thanks Adam. Very useful information.