This project is read-only.

Getting started

This is the essential guide for getting started using TransMock. For more detailed guide based on a real-world integration please visit the blog post here. It is still recommended to read this Getting started guide before continuing to the blog post.

This guide is based on the assumption that BTDF is utilized for deployment purposes. A guide for conventional BizTalk deployment is coming soon.

1. Install the framework through the installer after downloading it from the download section

2. In your BizTalk project navigate to the PortBindingsMaster.xml file and tag all the receive locations and send port primary transports with the commented syntax for mocking as shown below:

                                  <!-- <Mock /> -->


Make sure that you have placed the tag right under the ReceiveLocation tags or SendPort tags respectively as shown in the snippet below:

             .....
             <SendPort Name="SomeSendPort" IsStatic="True" ... >
                 <!-- <Mock /> -->
             .....
                 <ReceiveLocation Name="SomeReceiveLocation">
                     <!-- <Mock /> -->
             .....                                  


NOTE: For mocking send ports this is a breaking change in syntax since version 0.9.7. Prior to this version the Mock tag was placed under the PrimaryTransport tag for send ports. If you have used TransMock already you have to update the bindings file to match this requirement.

3. In your BTDFproj file add the following code:

             .....
             <Import Project="[TransMock install path]\Ext\TransMock.targets" />
             ......


Make sure that this Import statement is placed at the very end of the .btdfproj file, just prior to the closing Project tag. This will ensure that the Mockifier would be invoked at the correct point in time so that the bindings file with the already mocked endpoints would be imported to the BizTalk application in order to allow for the mocking to funciton properly. At the same time this will ensure that any already existing overrides of the CustomDeployTarget target will be executed as well.

For testing BizTalk 2010 integrations only - make sure that you add the following line to the first PropertyGroup section in the btdfproj file:

             .....
             <BTSVersion>2010</BTSVersion>
             ......


This property is defined in the TransMock.targets file and is used to indicate which version of BizTalk Server is being tested. The default value is 2013 which is applicable for both 2013 and 2013 R2, hence there is no need to define a value for this property for testing such solutions . The version of the BizTalk server is used as an input parameter for the Mockifier so that it generates the correct mock adapter configuration accordingly due to a difference in the syntax for the bindings file between versions 2010 and 2013 and up.

4. Now it is time to deploy the project by executing the btdfproj file. This is an important step which will ensure that the Mockifier is executed. As a result of this a helper class with the mocked addresses will be produced. The default name of this class is <My BizTalk Solution Name>MockAddresses and it is stored under the Deployment folder of your BizTalk solution.

5. In your Test project refer to the assembly TransMock.Integration.BizUnit.dll from the [TransMock install path]\Ext folder

6. Create a BizUnit test by utilizing the appropriate Mock* steps defined in the TransMock.Integration.BizUnit namespace.

The easiest way to show this is by an example:

At the figure below is shown a simple integration for the infamous PO submission, involving several different systems utilizing different transports, data formats and message exchange patterns.

TransMockExample.png

In order to mock the reception of the first message that is received over an MSMQ queue in real life, define a step of type MockSendStep. This step emulates one way send from an imaginary system to a one-way BizTalk receive location. Make sure that you have set the correct mock endpoint URL and point to the correct file in the RequestPath property of the step. For convinience when setting the URL property value use the properties from the generated helper class <My BizTalk Solution Name>MockAddresses, where each property has the name of the corresponding receive location or send port that has been mocked. This class is to be found under the Deployment folder under the VS solutions root and should be added manually (for now) to your Test project. Setting the URL property is demonstrated with an example below:
For simplicity let's assume that our receive location is called ReceivePO_ERP_MSMQ and that the BizTalk solution is called OrderProcess. In order to set the correct mock endpoint URL then we simply write:

var sendPOstep = new MockSendStep(){
    ....
    URL = OrderProcessMockAddresses.ReceivePO_ERP_MSMQ
    ....
};


Then it is time to mock the web service that receives a request from and sends a response back to BizTalk server. Mocking this service is achieved by utilizing the MockRequestResponseStep step type. This step should have values set for the URL and ResponsePath properties. The URL value is set the same way as the example above - just remember to use the property named as the corresponding send port.

Finally we mock the sending of a flat file over FTP to the trading party's mainframe with the help of the MockReceiveStep. Again the URL should be set accordingly to how the address is set in the corresponding send port. Please use the MockAdresses helper file for this purpose. No other properties are requiret set on this step, however since it is a flat file in the picture it might be a good idea to set the Encoding property accordingly. This way it will be possible to easiliy vaildate the contents of the received message.

The result of the above operations is shown in the picture below:

TransMockExampleMocked.png

The systems and related infrastructure have been seemlesly replaced by a set of Mock* BizUnit test steps!

7. Make sure that you have the appropriate test files in your test project and that they are properly referred to by the test case. The easiest way of achieving this is to place all the test files under a catalog called TestFiles under your project, enable deployment from the test settings in the solution and then use the DeploymentItem attribute with the parameter @"TestData\<Test file name>" for each test file employed by a particular test case. Make sure that the test files have their "Build action" in the Properties window in Visual studio set to "Content" as well as the "Copy to Output Directory" property is set to "Copy always".

8. Finally it is time to hit the Run tests button and if everything is right with the test and the integration implementation itself, the test should run successfully. You can then inspect the BizTalk group hub and should be able to see the message flow that has been driven by the test execution.

NOTE: If you have dynamic send ports in your solution read the Advanced usage page for learning how to mock such ports.

Last edited Sep 30, 2015 at 5:34 PM by cyberbyber, version 22