BizMock using it for orchestration unit testing
BizMock is a tool that allows for testing BizTalk artifacts without having to deploy artifacts. This is done by a private BizMock adapter that receives the messages.
BizMock generates a class based on an XML configuration file where the mapping to schemas, sample files, maps, orchestrations, mapping from logical to (virtual) physical ports are defined (all in your head ).
Advantages: The generated code to perform the test is simple, powerful and compact.
Disadvantages: It uses T4 templates; errors in the XML file are very difficult to debug and resolve. There is little documentation available and sample code does not show all possibilities.
Note: According to the developer a DSL tool is on the way providing an easy mechanism to manufacture the Xml file!
In the segments below are some code snippets that shows the usage of BizMock;
Application
The figure below is a sample project with two schemas, a map and an orchestration.
The sample orchestration receives a message from a location, performs a transformation, and then sends the message through a send port.
In order to test this orchestration you would normally have to deploy, create two physical ports bind these to the logical orchestration ports. After starting the bound ports, you realize that the full control rights haven’t been granted…ugh! Well fix this and we can start manually by creating some files…oh boy, haven’t even mentioned correlations…doing all this by hand is..... quite cumbersome.
BizMock offers an adapter that can simulate the physical ports by trapping messages and manipulate the behavior of BizTalk so that messages can be influenced. This prevents a lot of BizTalk configuration having being done in order to perform some tests.
BizMock provides a sample project that contains an Artifacts.TT file that should be copied to your application, the example Artifacts.XML can be viewed as a reference as your own Artifacts.XML is going to be quite different (different schema, different ports, namespaces etc).
The T4 template (Artifacts.tt) is used to convert the XML file to a class that can be used in the tests. The XML File (Artifacts.Xml) is a file that describes the various BizTalk artifacts, here is sample example Xml definition for my test project:
Orchestration
<Orchestration>
<Name>OrderApproval</Name>
<FullName>BizMockTest.OrderApproval</FullName>
<Ports>
<Port>
<Logical>RcvOrderRequestPort</Logical>
<Physical>PhysicalRcvOrderRequestPort</Physical>
</Port>
<Port>
<Logical>SndOrderApprovalPort</Logical>
<Physical>PhysicalSndOrderApprovalPort</Physical>
</Port>
</Ports>
</Orchestration>
Send Port
<OneWaySendPort>
<Name>PhysicalSndOrderApprovalPort</Name>
<PortName>PhysicalSndOrderApprovalPort</PortName>
<SendPipeline>
<Name></Name>
<Data></Data>
</SendPipeline>
<Dynamic>false</Dynamic>
</OneWaySendPort>
</OneWaySendPorts>
MessageType
<MessageInstances>
<SingleMessageInstances>
<SingleMessageInstance>
<Name>OrderRequestType</Name>
<Properties>
<Property>
<Name>ID</Name>
<xpath>/*[local-name()='OrderRequest' and namespace-uri()='http://BizMockTest.OrderRequest']/*[local- name()='ID' and namespace-uri()='']</xpath>
</Property>
</Properties>
<ContextProperties />
</SingleMessageInstance>
Sample Message
<Artifacts name="Artifacts" appName="BizMockTest" >
<MessageInstanceArtifacts>
<MessageInstance>
<Name>SampleOrderRequest</Name>
<Type>OrderRequestType</Type>
<Files>
<File>OrderRequest.xml</File>
</Files>
</MessageInstance>
Etc.
Note: If a field is required in the Artifacts.XML, ALL values should be set, otherwise the translation of the Xml using the T4 template is not properly carried out which will lead to strange errors that are difficult to ‘debug’ (look out for the Dynamic port!).
After configuring the Artifacts.Xml the ‘TextTemplatingFileGenerator’ can be started. Verify by clicking on the file that Artifacts.TT TextTemplatingFileGenerator linked. Right-click on the TT file and choose Run Custom Tool "and then the full Artifacts.CS file should be generated.
To create tests I suggest you look carefully at the example in the BizMock samples, below an example of my tests;
After running the test, you can use the debugger as would be possible when running orchestrations;
In the Message Flow you can see that the BizMock adapter is used to BizMock send the message!
Conclusion: BizMock is a pretty cool tool and I highly recommend to use it. For now I am anxious to see the promised upcoming DSL tool as it would enable us to use it also in rather complex projects. The lack of documentation (on the site at least) is what makes it unclear for me if BizMock can be used in combination with Custom pipelines that requires properties to be set, ESB Toolkit scenarios with itineraries etc.
To test maps and schemas BizUnit provides more than enough possibilities, however the capabilities are very promising. I hope to be able to get an update from the developer to see what possibilities are for using BizMock in conjunction with the ESB Toolkit.
Still, I think this tool is brilliant and really suggest to take a look at it!
Comments