Map Unit test does not work in BizTalk 2013 because TestableMapBase class is not correct.

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.

image

The below code is re-written to call Transform Load and transform method in TestableMapBase.cs.

image

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.

image

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 :).

http://www.sharptalktech.com

Regards,

Shadab

22 thoughts on “Map Unit test does not work in BizTalk 2013 because TestableMapBase class is not correct.

  1. Pingback: Beta release BizTalk Sofware Factory for BizTalk Server 2013 - Jean-Paul Smit

    • 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

  2. Pingback: [BizTalk 2010] Testing a multiple input map with Visual Studio 2010 - Jean-Paul Smit

  3. 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

  4. 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.

  5. 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 ?

  6. 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.

  7. 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.

      • 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 🙂

  8. 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());
    }
    }

  9. Pingback: BizTalk Server 2013: Step-by-Step to implement Unit Testing in Schemas and Maps | Sandro Pereira BizTalk Blog

Leave a comment