Sunday, August 23, 2009

New BizTalk Unit Testing Framework : “Bizmonade”

For the past few months, I have been developing a new unit testing framework for BizTalk. This framework is specialized on unit testing Orchestrations, and unlike existing tools, it allows testing orchestrations without first deploying into BizTalk and without doing any configuration (bindings). The project is now complete enough to release a “preview” version. It still lacks important features, but it is a working implementation and I would be very interested in hearing feedback from the BizTalk community.

Tests can be written in C# using NUnit, MSTest or any other .Net testing framework.

Example test written using this tool:

[Test]
public void TotalForOrder413ShouldBe14_99()
{
OrchestrationSimulator.Test<SubmitOrder__Simulated>()
.When(MessageReceived.FromFile<PurchaseOrder>(
Path.Combine(exampleInstancesPath, "PurchaseOrder_413.xml")
))
// Ensure the orchestration publishes an updated "PurchaseOrder" with the correct price quote
.ExpectMessageSent<PurchaseOrder>
(
msg =>
{
// NUnit asserts, if using another framework, substitute with that framework's syntax
Assert.AreEqual(14.99m, msg.DistinguishedFields["Total"]);
Assert.AreEqual("priceQuoteSubmitted", msg.PromotedProperties[typeof(orderStatus)]);
}
)
// Simulate that the client sent an "Approved Purchase Order" in response
// to the price quote.
.When(MessageReceived.FromFile<PurchaseOrder>(
Path.Combine(exampleInstancesPath, "PurchaseOrder_413_Approved.xml")
))
// Ensure the orchestration publishes the right Invoice in reaction to the approval
.ExpectMessageSent<Invoice>
(
// Not using NUnit asserts this time, can be used with any test framework,
// but provides less deatailed errors in case of failure (for now)
msg =>
msg.GetDistinguishedField<string>("Number") == "1") &&
msg.GetDistinguishedField<decimal>("TotalPrice") == 14.99m
)
// Ensure the orchestration completes successfully
.ExpectCompleted()
.ExecuteTest();
}


The tool does not depend on BizTalk’s orchestration engine, instead it provides its own implementation of the XLang/s language. It generates C# code from ODX files (using an interpreter generated with SableCC), and the generated C# code uses Bizmonade’s “fake orchestration engine” implementation. This allowed developing the tool without worrying about internal BizTalk implementation details.



More details and download on bizmonade.matricis.com.