Geeks With Blogs

News View Michael Stephenson's profile on BizTalk Blog Doc View Michael Stephenson's profile on LinkedIn
Michael Stephenson keeping your feet on premise while your heads in the cloud

Following on from the BDD articles I will cover how we have been using BDD development techniques to develop BizTalk maps. A BizTalk map is a discreet component in BizTalk which is ideally suited to development based on desired behaviours from the component. It fits well with our practices. If you imagine we are at a point where we have worked with our Business Analyst to work out the data formats required for various systems then we are in a position to work with them to begin understanding how the data transformation between systems needs to take place.

Using the Specflow feature file and gherkin syntax we have talked about previously gives us an excellent way to begin looking at the behaviour required from the map. In this scenario the maps behaviour is documented in the specflow example below. Note that this will be a very simple transformation.

Feature: Map System A Person to System B Person

    In order to load data into System B

    As a integration server

    I want to transform a person from the system A format to the system B format


Scenario: Default Scenario

    Given I have a person from System A

        | Firstname | Surname |

        | Joe | Bloggs |    

    When I execute the map

    Then the person in systems B full name should be JOE BLOGGS


Scenario: Person has no first name

    Given I have a person from System A

        | Firstname | Surname |

        | | Bloggs |    

    When I execute the map

    Then the person in systems B full name should be BLOGGS


Scenario: Person has no surname

        Given I have a person from System A

        | Firstname | Surname |

        | Joe | |    

    When I execute the map

    Then the person in systems B full name should be JOE With A Space


Scenario: Person has no name

        Given I have a person from System A

        | Firstname | Surname |

        | | |    

    When I execute the map

    Then the person in systems B full name should be empty




In this example you can see that I am using the table feature in Specflow to provide data from the specification which we will use behind the scenes in our test implementation to execute the test cases.

Building the Test

We now have a clear view of what the transformation needs to do so the Business Analyst can let us get on with developing our test implementation and then the map which we will develop again with the red/green/refactor process. The test implementation for this case will look something like the following.

In this test we will be using classes generated from the schemas and then populate the objects with data from the Specflow test. This gives us the excellent benefit of strong typing around the test data used with the map so that if the schema changes then we are able to catch compile errors and deal with this in a nice easy to handle way. Once we have the input class we will serialize it and use it to input into the map. We will then take the output from the map and deserialize it to the output object from where we will be able to use assertions against the object in the normal .net way.

A sample of the code behind this test is below:

using System.IO;

using System.Xml.Serialization;

using BizTalkStuff.Messages;

using Microsoft.BizTalk.TestTools.Mapper;

using Microsoft.BizTalk.TestTools.Schema;

using TechTalk.SpecFlow;

using Microsoft.VisualStudio.TestTools.UnitTesting;


namespace Test



public class StepDefinitions


private readonly SystemAPerson _systemAPerson = new SystemAPerson();

private SystemBPerson _systemBPerson = new SystemBPerson();


[Given(@"I have a person from System A")]

public void GivenIHaveAPersonFromSystemA(Table table)


var firstName = table.Rows[0]["Firstname"];

var surname = table.Rows[0]["Surname"];


_systemAPerson.Firstname = firstName;

_systemAPerson.Surname = surname;



[Then(@"the person in systems B full name should be (.*)")]

public void ThenThePersonInSystemsBFullNameShouldBe(string name)


if (name == "JOE With A Space")

name = "JOE ";

if(name == "empty")

name = string.Empty;


Assert.AreEqual(name, _systemBPerson.Fullname);




[When(@"I execute the map")]

public void WhenIExecuteTheMap()


const string testInputFileName = @"c:\maptestinput.xml";

const string outputFileName = @"c:\maptestoutput.xml";


SerializeInput(testInputFileName, _systemAPerson);

TestableMapBase map = new BizTalkStuff.SystemAPerson_To_SystemBPerson();

map.TestMap(testInputFileName, InputInstanceType.Xml, outputFileName, OutputInstanceType.XML);

_systemBPerson = DeserializeOutput<SystemBPerson>(outputFileName);



private static void SerializeInput(string filePath, object o)


using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write))


var serializer = new XmlSerializer(o.GetType());

serializer.Serialize(stream, o);





private static T DeserializeOutput<T>(string filePath)


using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))


var serializer = new XmlSerializer(typeof(T));

return (T)serializer.Deserialize(stream);






Building the Map

Before you build the tests you will have created your schema and generated the .net messages to help you write the tests, but you can now drive the TDD approach to building the map using the tests you have created. In this scenario the map was very simple and looked like the following:




Hopefully you can see that BizTalk maps are another good candidate where a BDD approach involving the use of Specflow can significantly reduce the total cost of ownership of the map because you have documentation of what the map is supposed to do in plain business like language. This was obviously a very simple sample but if you imagine some of the big maps you often come across where it's a complete nightmare to understand anything about them, this approach could really make life simpler for no additional effort.

The sample for this post is at the following location:


Posted on Friday, July 13, 2012 11:25 AM BizTalk , BizTalk Testing | Back to top

Comments on this post: Developing BizTalk Maps with Specflow & BDD

# re: Developing BizTalk Maps with Specflow & BDD
Requesting Gravatar...
many thanks for this tutorial..just what i was looking in order to complete all the stages of my project so that i could start to write my essay today and have the weekend all to myself
Left by Sybil on Mar 03, 2017 4:45 AM

# re: Developing BizTalk Maps with Specflow & BDD
Requesting Gravatar...
Neglect the Apple ID and also sync all data including pictures, get iCloud on iPhone iPad.
Left by tyson on Aug 25, 2017 10:07 PM

# re: Developing BizTalk Maps with Specflow & BDD
Requesting Gravatar...
the seller to your address. Your bundle is given a tracking number to what buyers do to stalk track their packages. Everything from
Left by Coveny on Nov 03, 2017 7:53 PM

Your comment:
 (will show your gravatar)

Copyright © Michael Stephenson | Powered by: