[BizTalk 2010] Testing a multiple input map with Visual Studio 2010

By jpsmit
December 11, 2013
0

Since BizTalk 2010 we have a feature in Visual Studio 2010 which allows us to test maps without having to deploy them into BizTalk Server. Until then we were lucky to have frameworks like BizUnit. Also the BizTalk Software Factory uses this feature to test maps.

To test maps just using Visual Studio 2010 we use this piece of code in our unit test project:

Microsoft.BizTalk.TestTools.Mapper.TestableMapBase map = new …map_name…();

map.TestMap(inputFile, Microsoft.BizTalk.TestTools.Schema.InputInstanceType.Xml, outputFile, Microsoft.BizTalk.TestTools.Schema.OutputInstanceType.XML);

After this statement we have the output file available which we can use to compare it with the expected values.

But what if we have a map with multiple inputs? We’re not able to provide multiple input files. So how do we test them?

To understand this, we need to know how BizTalk handles these kinds of maps. By the way, this post assumes you know how to create a multiple input map. If not, you can check it here.

To handle multiple input maps, BizTalk creates a new schema which contains both input schemas. In this way BizTalk is only facing one (combined) schema again, which contains both input schemas. This schema is not visible for us developers but is used behind the scenes. So to be able to test a multiple input map, we only have to create such a combined message. How do we create such a message?

To explain this I’ve setup a test scenario, which uses the following artifacts.

First Schema:

<?xml
version=1.0
encoding=utf-16?>

<xs:schema
xmlns=http://Didago.Samples.MultipleInputMap.FirstSchema
xmlns:b=http://schemas.microsoft.com/BizTalk/2003
targetNamespace=http://Didago.Samples.MultipleInputMap.FirstSchema
xmlns:xs=http://www.w3.org/2001/XMLSchema>

<xs:element
name=FirstSchema>

<xs:complexType>

<xs:sequence>

<xs:element
name=FirstName
type=xs:string />

<xs:element
name=City
type=xs:string />

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

Second Schema:

<?xml
version=1.0
encoding=utf-16?>

<xs:schema
xmlns=http://Didago.Samples.MultipleInputMap.SecondSchema
xmlns:b=http://schemas.microsoft.com/BizTalk/2003
targetNamespace=http://Didago.Samples.MultipleInputMap.SecondSchema
xmlns:xs=http://www.w3.org/2001/XMLSchema>

<xs:element
name=SecondSchema>

<xs:complexType>

<xs:sequence>

<xs:element
name=LastName
type=xs:string />

<xs:element
name=Country
type=xs:string />

<xs:element
name=Age
type=xs:int />

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

Combined (target) schema:

<?xml
version=1.0
encoding=utf-16?>

<xs:schema
xmlns=http://Didago.Samples.MultipleInputMap.CombinedSchema
xmlns:b=http://schemas.microsoft.com/BizTalk/2003
targetNamespace=http://Didago.Samples.MultipleInputMap.CombinedSchema
xmlns:xs=http://www.w3.org/2001/XMLSchema>

<xs:element
name=CombinedSchema>

<xs:complexType>

<xs:sequence>

<xs:element
name=FirstName
type=xs:string />

<xs:element
name=LastName
type=xs:string />

<xs:element
name=City
type=xs:string />

<xs:element
name=Country
type=xs:string />

<xs:element
name=Age
type=xs:int />

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

I’ve created a map which transforms the first and second schema into the combined schema. If you open the map in an XML editor, you can view what BizTalk does with multiple input maps.

<xs:schema
xmlns:ns2=http://Didago.Samples.MultipleInputMap.SecondSchema
xmlns:tns=http://schemas.microsoft.com/BizTalk/2003/aggschema
xmlns:b=http://schemas.microsoft.com/BizTalk/2003
xmlns:ns1=http://Didago.Samples.MultipleInputMap.FirstSchema
targetNamespace=http://schemas.microsoft.com/BizTalk/2003/aggschema
xmlns:xs=http://www.w3.org/2001/XMLSchema>

<xs:import
schemaLocation=.FirstSchema.xsd
namespace=http://Didago.Samples.MultipleInputMap.FirstSchema />

<xs:import
schemaLocation=.SecondSchema.xsd
namespace=http://Didago.Samples.MultipleInputMap.SecondSchema />

<xs:element
name=Root>

<xs:complexType>

<xs:sequence>

<xs:element
name=InputMessagePart_0>

<xs:complexType>

<xs:sequence>

<xs:element
ref=ns1:FirstSchema />

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:element
name=InputMessagePart_1>

<xs:complexType>

<xs:sequence>

<xs:element
ref=ns2:SecondSchema />

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

BizTalk creates a new schema with a ‘Root’ and two sub nodes ‘InputMessagePart_0’ and ‘InputMessagePart_1’. If we recreate this message for our test, we can use the regular unit test code and it will work. The easy way is to take this (xs:)schema part from the map, create a new schema in BizTalk based on this and use the ‘Generate Instance’ feature to have a valid multiple schema example. We can fill this sample with our test message content to have a valid test. For my test scenario it will look like this example below.

<ns0:Root
xmlns:ns0=http://schemas.microsoft.com/BizTalk/2003/aggschema>

<InputMessagePart_0>

<ns1:FirstSchema
xmlns:ns1=http://Didago.Samples.MultipleInputMap.FirstSchema>

<FirstName>FirstName_0</FirstName>

<City>City_0</City>

</ns1:FirstSchema>

</InputMessagePart_0>

<InputMessagePart_1>

<ns2:SecondSchema
xmlns:ns2=http://Didago.Samples.MultipleInputMap.SecondSchema>

<LastName>LastName_0</LastName>

<Country>Country_0</Country>

<Age>10</Age>

</ns2:SecondSchema>

</InputMessagePart_1>

</ns0:Root>

All we have to do now is adjust the content of the test message to fit our needs. Based on this single input test message, we can perform the tests we need and verify it!

Two remarks though:

  1. Besides the Visual Studio testing, there are other test frameworks available. For example BizTalk Map Test Framework or the Fakes Framework
  2. This blog is specifically targeted at BizTalk 2010. Be aware that in BizTalk 2013 there is a bug preventing testing maps using Visual Studio!

Comments: 0

Leave a Reply

Your email address will not be published. Required fields are marked *