unit testing biztalk

17
Unit Testing BizTalk An Intro to BizMock

Upload: ellis

Post on 24-Feb-2016

111 views

Category:

Documents


0 download

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

Page 1: Unit Testing BizTalk

Unit Testing BizTalkAn Intro to BizMock

Page 2: Unit Testing BizTalk

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.

Page 3: Unit Testing BizTalk

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.

Page 4: Unit Testing BizTalk

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.

Page 5: Unit Testing BizTalk

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

Page 6: Unit Testing BizTalk

ARTIFACTS.XML OVERVIEW

Page 7: Unit Testing BizTalk

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

– Single Message Verifiers

– Multipart Message Verifiers

Page 8: Unit Testing BizTalk

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

– Single Message Instance

– Multipart message Instance

Page 9: Unit Testing BizTalk

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>

Page 10: Unit Testing BizTalk

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>

Page 11: Unit Testing BizTalk

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>

Page 12: Unit Testing BizTalk

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>

Page 13: Unit Testing BizTalk

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.

Page 14: Unit Testing BizTalk

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);

}

Page 15: Unit Testing BizTalk

DEMO

Page 16: Unit Testing BizTalk

CONTACT INFO

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

[email protected]– Blog: Extremely Talented Monkeys

http://talentedmonkeys.wordpress.com

Page 17: Unit Testing BizTalk

THANK YOU!