none
BizTalk 2009 EDI map unit testing - Why does not work OutputInstanceType.Native? RRS feed

  • Question

  • Hello,

    I just read that it is quite easy to write unit tests for maps in case of BizTalk 2009 and VS 2008 SP1.

    I have a map which converts an inhouse XML message to EDIFACT D02B UTILTS format. The provided unit test source code works like a charm as long as the OutputInstanceType is not changed from XML to Native. When the native EDIFACT format should be generated I get a NullReferenceException and it seems there is nothing I can do about it.


    It would be really nice to be able to get the native EDIFACT out of the test call as it is much more compact than xml, it is easier to write the master copy to which to compare the result of the test call and anyway that should be the final output from BizTalk. I suppose it should be possible as you can do something very similar when testing a map manually from Visual Studio - maybe even the same code is executed?


    The following code executes without any problem:

      TestableMapBase map = new MyMap ();
      map.TestMap("INHO_UTILTS_ERR_E5SE9A.xml",InputInstanceType.Xml,"EFACT_UTILTS_ERR_E5SE9A.xml",OutputInstanceType.XML);


    However running this code results in an exception:

       TestableMapBase map = new MyMap ();
       map.TestMap("INHO_UTILTS_ERR_E5SE9A.xml",InputInstanceType.Xml,"EFACT_UTILTS_ERR_E5SE9A.edi",OutputInstanceType.Native);


    The exception is the following:

    Error Message:
    Test method BizTalkDemo.Test.MapTest.Test_MI2E_UTILTS_ERR threw exception:  System.NullReferenceException: Object reference not set to an instance of an object..

    Error Stack Trace:
    Microsoft.BizTalk.TOM.CXSDSchemaTree.CreateNativeInstance(String strXMLInstFileName, String strNativeInstanceOutputFileName, InstanceGenerationOptions options, ITOMErrorInfo[]& errInstanceCreationErrors)
    Microsoft.BizTalk.TOM.CXSDSchemaTree.CreateNativeInstanceFromXMLInstance(String strXMLInstFileName, String strNativeInstFileName, ITOMErrorInfo[]& errInstCreationErrors)
    Microsoft.BizTalk.TestTools.Mapper.TestableMapBase.TestMap(String inputInstanceFilename, InputInstanceType inputType, String outputInstanceFilename, OutputInstanceType outputType)
    BizTalkDemo.Test.MapTest.Test_MI2E_UTILTS_ERR() in F:\project\BizTalkTest\BizTalkDemo.Test\MapTest.cs: line 72


    Did someone encounter this problem and has a solution?
    Or do you have other way for automatically testing inhouse XML 2 EDIFACT mappings?


    Thank you in advance!
    -Zoli
    • Edited by hadadiz Thursday, April 23, 2009 7:34 AM
    Tuesday, April 21, 2009 11:01 AM

Answers

  • If you are creating flat files and not EDI, this process would work fine. EDI is a different beast.
    Eric Stott [http://blog.biztalk-info.com] - Mark as Answer if this reply does.
    Thursday, April 23, 2009 7:35 AM

All replies

  • Creating native EDI files is not supported from Map Unit tests. You can use below work around.

    1. create xml file from map and dump it to a file.
    2. create a EDI send port which reads above file.
    3. EDI send port will create edi file in native format.
    Bhola Meena [http://blogs.msdn.com/biztalkrfidinside]
    Tuesday, April 21, 2009 5:07 PM
  • Thank you for your suggestion, I will try it. However this way it will be not possible to run the automatic tests without BizTalk.

    By the way, when a map is tested manually in VS2008 and with output option native does VS actually use the BizTalk instance to generate the output or it does it all by itself?

    What is the purpose of OutputInstanceType.Native if actually it can not be used to get native EDIFACT?

    Thank you,
    Zoli
    Thursday, April 23, 2009 7:33 AM
  • If you are creating flat files and not EDI, this process would work fine. EDI is a different beast.
    Eric Stott [http://blog.biztalk-info.com] - Mark as Answer if this reply does.
    Thursday, April 23, 2009 7:35 AM
  • Eric,

    Is it really works for flat files? I have no success with these either.
    I have simple tab delimited flat file schema, whihc validates fine in VS.NET (both schema validate instance and Map TestMap). But unit tests throw "Generate schema instance failure" when I try to call TestMap.

    If output type is set to OutputInstanceType.Xml, it generates the file,
    If it is set to OutputInstanceType.Native, no file generated at location specified,
    but the FlatFile.xml is generated at %TEMP% location,

    Schema validation was as bad, till I wrote custom schema/instance validator
    based on samples in BiztalkHotRod http://biztalkhotrod.com/Issues.aspx

    Is there any sample of working UT for Map/flat file, which actually tests flat file generated?

    Monday, August 10, 2009 5:13 PM