unit testing biztalk

Post on 24-Feb-2016

102 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Unit Testing BizTalk. An Intro to BizMock. Difficulties in Unit Testing BizTalk. The Value of Test-Driven Development is well-known. However, doing it in BizTalk can be difficult: SOA and ESB solutions are loosely-coupled by design and as a result, difficult to test. - PowerPoint PPT Presentation

TRANSCRIPT

Unit Testing BizTalkAn Intro to BizMock

DIFFICULTIES IN UNIT TESTING BIZTALK

The Value of Test-Driven Development is well-known. However, doing it in BizTalk can be difficult:– SOA and ESB solutions are loosely-coupled by design and as a result,

difficult to test.– Testing can usually take place only after external solutions are

available and online.– Most pieces of a BizTalk solution (such as pipelines,

orchestrations, .dll’s) perform only narrow and specific tasks with many follow-on dependents.

– Most BizTalk unit tests simply involve the act of copying a file to one location and picking output up from another.

BIZMOCK AS A UNIT-TEST UTILITY

• Available at http://bizmock.codeplex.com• BizMock allows us to overcome many of the difficulties in

unit-testing BizTalk by providing a framework to “mock-up” BizTalk endpoints.

• BizMock works with BizTalk as a special adapter that sends and receives messages into and from the BizTalk system

• Ports and other artifacts can be dynamically generated and removed at runtime.

• BizMock exposes a number of test functions which allow for richer BizTalk unit-testing than can be done in the typical “file drop” scenario.

BIZMOCK DRAWBACKS

• The number one drawback of using BizMock is that it is very poorly documented.

• To understand how it works, you’ll need to spend a great deal of time studying BizMock’s source code, which is available in the CodePlex download.

SETTING IT UP

1. Deploy your BizTalk assemblies (orchestrations, pipelines, maps, schemas)

2. Create a test project and add BizMock assembly references:– BizMockArtifactsSchema– BizMockery– BizMockMessaging– BizMockReceiveAdapter– BizMockSamples

3. Add artifacts.tt and artifacts.xml from the Sample project to your test project

4. Modify artifacts.xml to reflect your artifact definitions5. Execute the template to generate your code6. Write unit tests

ARTIFACTS.XML OVERVIEW

ARTIFACTS.XML: CUSTOM TYPES• Message Verifiers : Validates messages against schema and property.

– Single Message Verifiers

– Multipart Message Verifiers

ARTIFACTS.XML: CUSTOM TYPES (CONT’D)• Message Instances

– Single Message Instance

– Multipart message Instance

ARTIFACTS.XML: ARTIFACTS

• Artifacts element Attributes:– name: choose the name you wish your artifacts collection class to be called in code. For most

purposes, the default value , “Artifacts”, is a pretty good choice.– appName: the name of the BizTalk application that artifacts will be deployed to for testing.

• Message Instances<MessageInstance>        <Name>Msg_Simple</Name>        <Type>SimpleMessageType</Type>        <Files>          <File>SimpleSchema_input.xml</File>        </Files> </MessageInstance>

• Message Verifiers <MessageVerifier>

    <Name>Vrf_Simple</Name>    <Type>SimpleSchemaTypeVerifier</Type> </MessageVerifier>

ARTIFACTS.XML: ARTIFACTS (CONT’D)

• Maps <Map>

    <Name>xyzMap</Name> <MapFullName>BizMock.Samples.xyzMap</MapFullName></Map>

• Ports– Two-Way Send

<TwoWaySendPort>    <Name>GetDataService</Name>    <PortName>GetDataService</PortName>    <SendPipeline>          <Name></Name>          <Data></Data>    </SendPipeline>    <ReceivePipeline>         <Name></Name>         <Data></Data>    </ReceivePipeline>    <Dynamic>true</Dynamic></TwoWaySendPort>

ARTIFACTS.XML: ARTIFACTS (CONT’D)

• Ports– One Way Receive

<OneWayReceiveLocation>      <Name>OWPort_1</Name>      <PortName>OWPort_1</PortName>      <ReceivePipeline>          <Name></Name>    <Data></Data>      </ReceivePipeline></OneWayReceiveLocation>

• Databases

<Database>     <TypeName>DatabaseArtifact</TypeName>  <Name></Name>

<ConnectionString></ConnectionString></Database>

ARTIFACTS.XML: ARTIFACTS (CONT’D)

• Event Log<EventLog>    <Name>BizMock_EventLog</Name>    <Log>Application</Log>    <Source>BizMock</Source></EventLog>

• Orchestration<Orchestration>    <Name>MultipartWithLoopOrchestration</Name>    <FullName>BizMock.Samples.MultipartWithLoop</FullName>    <Ports>     <Port>         <Logical>Port_1</Logical>          <Physical>OWPort_1</Physical>        </Port>        <Port>          <Logical>Port_2</Logical>          <Physical>OWPort_2</Physical>        </Port></Ports></Orchestration>

WRITING BIZMOCK UNIT TESTS

• Add test documents to your project• Call the Initialize() method of your artifacts class in

the ClassInitialize() or TestInitialize() method of your testing class

• Call BizMockery.DeleteAllInstances() in your ClassCleanup() method.

• In each TestMethod, be sure to add a DeploymentItem for each test document used.

SAMPLE TEST

[TestMethod][DeploymentItem("SimpleSchema_input.xml")][DeploymentItem("SimpleSchema2_input.xml")][DeploymentItem("Service1_request.xml")]public void MultipartWithLoopTest(){ artifacts.MultipartWithLoopOrchestration.Start();

artifacts.Msg_MultiPart.InterchangeID = "X"; //art.Vrf_Multipart.MultiPart1.Field = "Y";//art.Vrf_Multipart.MultiPart2.Field = "Y";             Submit.Request(artifacts.Msg_MultiPart).To( artifacts.OWPort_1);Expect.AtLeast(2).Request.At(artifacts.OWPort_2).Verify( artifacts.Vrf_Multipart);

}

DEMO

CONTACT INFO

• Ed Jones, MCT, MCPD, MCTS– Email:

talentedmonkey@hotmail.com– Blog: Extremely Talented Monkeys

http://talentedmonkeys.wordpress.com

THANK YOU!

top related