A while back in my series of articles about testing with BizTalk I covered a technique for testing schema. The background to the approach is still valid in BizTalk 2009, but the technique is improved. To review the previous article refer to the following link:
http://geekswithblogs.net/michaelstephenson/archive/2008/03/30/120850.aspx
In the newly released BizTalk 2009 CTP there have been some improvements in how you can do some of the testing and I would like to demonstrate this. I will walk through the steps to test your schema.
Before I go into the details, we start with a simple project with two projects. The first is a BizTalk project with a schema and the second is a C# test project. The following steps need to be taken to setup your tests
- Configure your BizTalk Project for Tests
The first step is to open the properties for your new BizTalk project. If you go to the Deployment section you can see highlighted in the below picture the setting which will turn on the generation of some additional code to allow you to test BizTalk artefacts.
- Adding references to your test assembly
In your test project you will need to add a couple of references, the main one is the new Microsoft.BizTalk.TestTools assembly which is in the Visual Studio Add Reference list. This will allow you to use these new testing features.
- The test code
The following code snippet shows how you can create an instance of your schema which derives from the new TestableSchemaBase object. This has the new ValidateInstance method which allows you to pass in the path to a file containing the message you wish to validate.
Summary
As you can see this new technique just simplifies what we had been doing in BizTalk 2006 R2 and is a very nice interface to support this testing.
The sample for this demo is available at the following location: http://www.box.net/shared/2ojysf5ys3
If you have problems accessing it then let me know.