BizTalk 2009 Testing Features

Link. January 1, 2009. Comments [0]. Posted in: BizTalk

Warning: This post is about a beta product. Details might change before final release.

The beta of BizTalk Server 2009 brings a welcome new feature: Some basic support for Unit Testing BizTalk artifacts; specifically for Pipelines, Maps and Schemas.

You can read the basics about how the new feature works in the product documentation; there’s not too much yet, but it’s enough to get a good idea of how you use it.

I’d like to now share a few thoughts on this feature. Note: This is just my personal opinion from playing with the API for a bit.

The Good

The first really good part about this feature is the fact that it even exists at all. Facilities for creating and automating tests of BizTalk artifacts has been a sorely lacking area of the product.

While Visual Studio had the Test option for maps and schemas since BizTalk 2004, and it was sort of useful, it required way too much manual intervention and there was no way to decently drive it through automation, making it useless for either unit or regression testing.

The second thing I like about the unit testing feature is that, in it’s current incarnation, it’s not intrinsically tied to MSTest (i.e. the Visual Studio Team System stuff). This means you can use it with NUnit, xUnit, or your favorite testing tool.

The third interesting thing about the API is that it is a very simple API. In most cases it really consists of just a single method call. Here’s an example of testing a schema:

string fin = @"c:\temp\test1_in.xml";
Schema1 schema = new Schema1();
Assert.IsTrue(schema.ValidateInstance(fin, OutputInstanceType.XML));

The Not-so-Good

Not everything is rosy in BizTalk-land. Personally, I was somewhat underwhelmed by the implementation of the Unit Testing features available in beta 1; particularly since some of it could be addressed with fairly minor adjustments.

API Issues

Let’s start with the API: I mentioned before that the new testing API was simple. However, it’s actually too simple. For example, consider the small test for a schema I presented above: You simply create an input file to test with, call ValidateInstance() and check the result. Great, no?

Well, if the test succeeds, then yes, it’s just fine. If it fails, however, because the input file does not pass validation, then, it turns out, it’s missing one extremely important functionality: There’s no way to get any details about why the schema validation failed [1].

This means that diagnosing a failed test involves, at the very least, changing your project settings in VS to use the failed input file as input to the schema in VS, use the Validate Instance option in the IDE and examine the results in the output window, where fortunately you do get more detailed error information.

This is extremely sub-optimal and requires way too much manual work. Can you imagine if a change in a schema broke tens of tests and having to do this for each and every single one of those? Ouch!

Another place where I feel the current API is not as nice as it could be is that it’s strictly file-based. That is, you need to create actual files on disk to represent inputs to the tests and store the resulting outputs. This is somewhat convenient for many scenarios, and matches the existing functionality in BizTalk pretty well. It does, however, make it very inconvenient to deal with dynamically generated inputs or inputs stored someplace else.

The classic example here, would be, resources. For example, I very much like to keep my unit tests as independent from the environment and as self-hosting as possible. One very nice way of doing this is to store necessary input files as embedded resources on my testing assembly. I do this all the time with PipelineTesting and it works great. However, since you can’t provide streams instead of file paths to the BizTalk 2009 testing features, you’d need to first save the embedded resource to a temporary file, which adds a bit of friction to the process.

Compilation Changes

My biggest gripe with the Unit Testing features, is that enabling them implies a change in the build process, that changes the generated code for the BizTalk artifacts themselves.

When you enable the Unit Testing option in Project –> Properties –> Deployment, the compilation process will change the generated CLR types so that they inherit from the TestableXXX classes defined in the Microsoft.BizTalk.TestTools.dll assembly, instead of the normal BizTalk artifact classes.

These new Testable base classes, in turn, derive from the original BizTalk classes, so the change isn’t all that big. However, it does smell wrong. Could it introduce any problems/bugs if you were to enable the testing features for all builds? Hopefully no, but no way to know until you run into them.

Of course, you could just enable Unit Testing for debug builds, but then you can’t run your unit tests on the release builds of your BizTalk assemblies. It also introduces yet another asymmetry between development and deployment builds which, to be honest, makes me somewhat nervous.

Conclusion

The new Unit Testing features in BizTalk Server 2009 are a sorely needed and welcome feature, if somewhat lacking in the first beta.

Will it improve? On one hand, I’m somewhat optimistic that some improvements might make an appearance in forthcoming builds. However, I’m also not getting my hopes up, as MS is notable for trying to avoid significant API changes during after beta 1 hits the street (BizTalk, unfortunately, doesn’t use the CTP model, where significant API change requests are more likely to be considered).

[1] TestableMap.TestMap() does throw exceptions on failure instead of a Boolean return value, but said exceptions might not contain detailed error information.

BizTalk Server 2009 MSBuild Tasks

Link. December 26, 2008. Comments [0]. Posted in: BizTalk

I’ve been looking around the new project system introduced in the BizTalk Server 2009 beta. As you might have heard before, it’s now based on MSBuild. This is an extremely welcome change from the obscure compilation model in previous BizTalk versions that caused so much frustration.

BizTalk Projects now look much like regular C# projects (they even have the same icon in solution explorer) but they can contain BizTalk artifacts like schemas, orchestrations, maps and pipelines.

Opening up the .btproj file reveals some of the differences and custom MSBuild tasks used by the new BizTalk project system. Two things are initially important to mark an MSBuild file as a BizTalk project.

The first one is the <ProjectTypeGuids/> value:

<ProjectTypeGuids>{EF7E3281-CD33-11D4-8326-00C04FA0CE8D};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

This means:

  • {EF7E3281-CD33-11D4-8326-00C04FA0CE8D}: This represents the BizTalk project factory, and tells VS where to find the item templates for BizTalk artifacts and so on.
  • {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}: This represents the C# project system.

So, in fact, a BizTalk Project is a C# project. Right now you can’t add C# artifacts to the project without editing the .btproj file by hand, but one can hope this will be supported in upcoming builds.

The second part important to making a .btproj is importing the BizTalk MSBuild tasks, which is accomplished by this line:

<Import Project="$(MSBuildExtensionsPath)\Microsoft\BizTalk\BizTalkC.targets" />

If we look at the BizTalkC.targets file, we can see that the BizTalk MSBuild tasks are implemented in the Microsoft.VisualStudio.BizTalkProject.BuildTasks assembly, which you'll find in your 'Microsoft BizTalk Server 2009\Developer Tools' folder.

Global Project Properties

There are several properties that will get set in the project files depending on your project settings that are BizTalk-specific:

  • <BpelCompliance/>: This is a Boolean (true, false) property that indicates if the generated assembly should be marked as BPEL compliant (I think).
  • <EnableUnitTesting/>: Corresponds to the Enable Unit Testing option in the Deployment tab of the project settings dialog, and controls whether the unit testing features for pipelines, schemas and maps are enabled.

Other settings are per-user settings and stored in the .btproj.user file:

  • <Server/>: The name of the SQL Server instance that has the BizTalk databases for deployment.
  • <ConfigurationDatabase/>: The name of the BizTalkMgmt database.
  • <ApplicationName/>: The name of the BizTalk application you want to deploy to.
  • <Redeploy/>: Boolean property that indicates if you want to allow redeployments from within Visual Studio.
  • <RestartHostInstance/>: If true, the BizTalk hosts will be restarted after each deployment.
  • <Register/>: If true, the generated assembly will be registered in the Global Assembly Cache (GAC).

Per-File Project Properties

The per-user project file (.btproj.user) can also include a bunch of item-specific properties, which are visible when you select a file in Solution Explorer and open the Properties window.

In this category you’ll find properties for setting paths for map input and output files for testing/debugging as well as paths for input and output files for testing schemas.

Here’s an example:

<File Path="E:\Projects\BizTalk\PipelineTesting\SampleSchemas\Map1.btm">
   <ValidateTestMapInput>True</ValidateTestMapInput>
   <ValidateTestMapOutput>True</ValidateTestMapOutput>
   <TestMapInputInstanceFilename></TestMapInputInstanceFilename>
   <TestMapOutputInstanceFilename></TestMapOutputInstanceFilename>
   <TestMapSourceType>0</TestMapSourceType>
   <TestMapTargetType>0</TestMapTargetType>
   <EditorOutputInstanceFilename></EditorOutputInstanceFilename>
   <EditorInputInstanceFilename></EditorInputInstanceFilename>
   <GenerateInstanceOutputType>0</GenerateInstanceOutputType>
   <ValidateInstanceInputType>0</ValidateInstanceInputType>
   <PropertySchemaFileName>PropertySchema.xsd</PropertySchemaFileName>
   <AutoRefreshSchema>0</AutoRefreshSchema>
</File>
<File Path="E:\Projects\BizTalk\PipelineTesting\SampleSchemas\NoNS.xsd">
   <ValidateTestMapInput>True</ValidateTestMapInput>
   <ValidateTestMapOutput>True</ValidateTestMapOutput>
   <TestMapInputInstanceFilename></TestMapInputInstanceFilename>
   <TestMapOutputInstanceFilename></TestMapOutputInstanceFilename>
   <TestMapSourceType>0</TestMapSourceType>
   <TestMapTargetType>0</TestMapTargetType>
   <EditorOutputInstanceFilename></EditorOutputInstanceFilename>
   <EditorInputInstanceFilename></EditorInputInstanceFilename>
   <GenerateInstanceOutputType>0</GenerateInstanceOutputType>
   <ValidateInstanceInputType>0</ValidateInstanceInputType>
   <PropertySchemaFileName>PropertySchema.xsd</PropertySchemaFileName>
   <AutoRefreshSchema>0</AutoRefreshSchema>
</File>

Building Pipelines

To build a pipeline, you can use the PipelineCompilerTask:

<ItemGroup>
   <Pipeline Include="CSV_FF_RecvPipeline.btp">
      <Namespace>SampleSchemas</Namespace>
      <TypeName>CSV_FF_RecvPipeline</TypeName>
   </Pipeline>
</ItemGroup>

Building Schemas

BizTalk Schemas can be compiled using the new SchemaCompiler task:

<ItemGroup>
   <Schema Include="Schema1_NPP.xsd">
      <Namespace>SampleSchemas</Namespace>
      <TypeName>Schema1_NPP</TypeName>
   </Schema>
</ItemGroup>

Building Maps

BizTalk Maps can be compiled using the new MapperCompiler task:

<ItemGroup>
   <Map Include="Map1.btm">
      <TypeName>Map1</TypeName>
      <Namespace>SampleSchemas</Namespace>
      <SubType>Task</SubType>
   </Map>
</ItemGroup>

I'm not sure yet what the <Subtype/> element does.

Building Orchestrations

BizTalk Orchestrations can be built with the new XLangTask:

<ItemGroup>
   <XLang Include="BizTalk Orchestration1.odx">
      <TypeName>BizTalk_Orchestration1</TypeName>
      <Namespace>SampleSchemas</Namespace>
      <SubType>Task</SubType>
   </XLang>
</ItemGroup>
<ItemGroup>

PipelineTesting and BizTalk 2009

Link. December 24, 2008. Comments [0]. Posted in: BizTalk

Now that the a public beta release of BizTalk Server 2009 is out, I thought I’d download it and try building and testing PipelineTesting on the new release.

After downloading and installing the beta, I proceeded to import the existing Visual Studio 2005 project file into Visual Studio 2008 with the new BizTalk project system (a huge improvement over the old one, if I may say so [1]). The import worked just fine overall.

The only change I had to make was remove the reference to PipelineObjects.dll from the projects and add it again with the new version in BizTalk 2009. The new version seems to be slightly different than the one in R2 (it’s 3KB smaller), but I haven’t looked closely to see what the differences might be.

In either case, PipelineTesting builds perfectly with the new version, and all Unit Tests are still passing in the green!

[1] I did hit a small snag with the project system: When building the imported solution, only the SampleSchemas project gets built, though all are selected to build in the configuration manager. Had to manually build the other projects from the project context menu.

Encryption Pipeline Component now on GitHub

Link. October 12, 2008. Comments [0]. Posted in: BizTalk

I’ve been working on organizing the code for my old custom Symmetric Encryption Pipeline Components for BizTalk Server 2006 and I’ve posted the updated code on a new GitHub repository. Be aware that I renamed things a little bit and cleaned other parts of the code.

The code includes both the encryption and decryption component, some basic tests using PipelineTesting, and the Windows Forms Configuration Utility that stores the crypto keys used by the components in a custom Configuration Application in Enterprise Single Sign-On.

Update to /dev/null R2 Adapter

Link. October 4, 2008. Comments [0]. Posted in: BizTalk

Antti Somersalo brought to my attention that there was a bug in my R2 version of the /dev/null adapter. The bug manifested itself when you tried to export the bindings of any BizTalk Application that used the adapter in one of its send ports, failing with an ArgumentNullException.

The problem was simple: The adapter management class was returning null from the GetConfigSchema() call. Fixing it was just as simple: Just change the implementation so that it returns an empty Xml schema:

public string GetConfigSchema(ConfigType configType) {
   return @"<schema xmlns='http://www.w3.org/2001/XMLSchema'/>";
}

I’ve updated the ZIP file with the code snapshot.

Syndicate

About

Tomas Restrepo is a software developer located in Colombia, South America. His interests include .NET, Connected Systems, PowerShell and lately dynamic programming languages. More...

tomasrestrepo @ twitter My Flickr photostream My saved links on delicious My Technorati Profile

email: tomas@winterdom.com
msn: tomasr@passport.com

View my profile on LinkedIn

MVP logo

Ads


Categories

Statistics

Total Posts: 1050
This Year: 1
This Month: 1
This Week: 0
Comments: 825

Archive

Other

Copyright © 2002-2008, Tomas Restrepo.

Powered by: newtelligence dasBlog 2.2.8279.16125

Sign In