Ox.BizTalk.TestComponents 1.1.0

dotnet add package Ox.BizTalk.TestComponents --version 1.1.0
NuGet\Install-Package Ox.BizTalk.TestComponents -Version 1.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Ox.BizTalk.TestComponents" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Ox.BizTalk.TestComponents --version 1.1.0
#r "nuget: Ox.BizTalk.TestComponents, 1.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Ox.BizTalk.TestComponents as a Cake Addin
#addin nuget:?package=Ox.BizTalk.TestComponents&version=1.1.0

// Install Ox.BizTalk.TestComponents as a Cake Tool
#tool nuget:?package=Ox.BizTalk.TestComponents&version=1.1.0

Ox.BizTalk.TestComponents

This library is meant to be a very basic implementation of BizTalk interfaces that can be used with test frameworks for the unit testing of BizTalk components (adapters and pipelines) without having to execute code in the BizTalk engine.

It is not guaranteed to behave in the same was as the BizTalk engine (in fact, I gaurantee it won't!), but to aid in stubbing components.

All methods are marked as virtual so you can override bits as you feel fit.

Building

It is built against .NET 4.7.2 as this covers BizTalk Server 2016 and BizTalk Server 2020. You may need to adjust your references to the relevant local versions of BizTalk assemblies to compile.

Usage

You might need to use Binding Redirects in your calling code to match up to local versions of the BizTalk dlls on your file system if you're using a different version of BizTalk.

This code should only be used in unit tests when the BizTalk runtime is unavailable. It doesn't fully implement all the required bits, and most certainly doesn't do it in a clever way.

A common approach used in these test classes is to allow you to register event handlers on methods which use the MethodCalledEventArgs class, which simply contains the arguments passed into a method, in signature order. This allows you to check that a method is being called with the expected values. For example:

// Create a task to track when the callback has been completed.
var eventsComplete = new TaskCompletionSource<bool>();

// Setup some unique test data
var testData = Guid.NewGuid().ToString();

// Create an inline function to handle our event and test the result
void ReceiverShuttingDown(object sender, MethodCalledEventArgs e)
{
    // Test that the inserted data matches our input
    Assert.AreEqual(testData, (string)e.Args[0]);

    // Mark the test complete
    eventsComplete.SetResult(true);
}

// Setup the test class
var proxy = new TestTransportProxy();

// Register our event handler
proxy.OnReceiverShuttingDown += ReceiverShuttingDown;

// Submit some test data
proxy.ReceiverShuttingDown(testData, null);

// Wait for the event handler to be called, or fail after a timeout period
if(!eventsComplete.Task.Wait(TEST_TIMEOUT))
{
    Assert.Fail("Tests methods were not called.");
}

Naturally this exmaple is rather dim, because it's checking that the data we pass in is the data that is logged, which will always be the case. Where this approach is useful when we have classes that call these methods as a dependency and we want to test whether that was called correctly.

Simple Pipeline Component Testing

You can use this library when unit testing pipeline components, e.g:

var pipeline = new MyPipelineComponent();

var pInMsg = new TestMessage()
                    .AddPart("example.txt", 
                        "text/plain", 
                        new MemoryStream(Encoding.UTF8.GetBytes("Hello World")));

var output = pipeline.Execute(new TestPipelineContext(), pInMsg);

Pipeline Validator

The PipelineResultValidator class allows for building a validator for running common pipeline component tests against the result of the pipeline. It uses MS Test Framework for assertions.

Most methods can be called multiple times against the key (e.g. part name), so you can add validators for each message part explicitly. The use of an Action callback allows for using a delegate to have common or bespoke validation logic without having to extend the class.

This component relies on known named message part names.

var result = myPipeline.Execute(pContext, pInMsg);

new PipelineResultValidator()
    .AssertPartCount(2)                           // Checks the PartCount
    .AssertPartContentType("body", "text/xml")    // Checks the content type of a named part
    .AssertPartStream("body", "Hello world")      // Checks the data stream against an expected value
    .AssertUnexpectedParts()                      // Have extra parts appeared?
    .AssertPartOrder("body", "extra")             // Ensure parts are in order
    .Validate(result)                             // Executes the built validator

Interfaces

Interfaces/abstract classes covered:

Orchestration

  • XLANGPart (TestXLANPart)
  • XLANGMessage (TestXLANGMessage)

Pipelines

  • IBaseMessagePart (TestMessagePart)
  • IBaseMessageFactory (TestMessageFactory)
  • IBaseMessageContext (TestMessageContext)
  • IBaseMessage (TestMessage)
  • IPipelineContext (TestPipelineContext)

Adapters

  • IBTTransportBatch (TestTransportBatch)
  • IBTTransportConfig (TestTransportConfig)
  • IBTTransportProxy (TestTransportProxy)
  • IBTBatchCallBack (TestBatchCallBack)

General

  • IResourceTracker (TestResourceTracker)
  • IBasePropertyBag (TestProperyBag)
  • IPropertyBag (TestPropertyBag)

Changes

There are amany methods that aren't implemented, you may need to add some functionality.

Please submit a pull request with changes.

Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 251 3/20/2023
1.0.2 415 4/14/2022

v1.0.0 - Initial release
1.1.0 - Added IPipelineContext handler, improved pipeline compatibility