This post was originally published here

Hi All,

I just came across an issue/bug with the pipeline unit test in BizTalk 2013/r2. In my case, I’ve multiple document specification present in the  XML disassembler stage. When we write Unit test for this custom pipeline it fails with the error “System.InvalidOperationException: None of the disassembler components could recognize a data”. The error basically means that I do not have a Schema Document Specification added to the XML Disassembler for the message, but that’s not correct. I’ve the doc spec available along with the  other schema doc specs in the collection.

I’ve written unit test using Spec Flow and Winterdom BizTalk Pipeline Testing tool. The Unit test is mentioned below:

Feature: Pipelines
Scenario Outline: Test Inbound Request Pipeline
Given the pipeline has been configured with the “<TypeName>” and “<SubscriberName>”
When the inbound request pipeline is executed with the “<InputMessage>”
Then the following Context Properties should be promoted “<MessageType>”, “<SubscriberName>”
Examples:
| InputMessage                     | TypeName                  | MessageType                                                                                                                       | SubscriberName |
| ManageAlertResponse.xml | SQLProviderResponse | http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/dbo#ManageAlertsResponse |                |

using System;
using System.IO;
using System.Linq;
using Microsoft.BizTalk.Message.Interop;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TechTalk.SpecFlow;
using Common.Patterns.PipelineComponent;
using Common.Utilities.BAM.Message.V1;
using Common.Utilities.Helper.Component;
using DB.Common.Pipelines;
using DB.Common.Schemas;

using Winterdom.BizTalk.PipelineTesting;

namespace DB.Common.Test.Bindings.Pipelines
{
[Binding]
public sealed class InboundRequestPipeline : BasePipelineBinding
{
[Given(@”the pipeline has been configured with the “”(.*)”” and “”(.*)”””)]
public void GivenThePipelineHasBeenConfiguredWithTheAnd(string typeName, string subscriberName)
{
ReceivePipelineWrapper pipeline = PipelineFactory.CreateReceivePipeline(typeof(RcvDBResponseMsg));
pipeline.AddDocSpec(typeof(TypedProcedure_dbo));

ScenarioContext.Current.Add(“Pipeline”, pipeline);
}

[When(@”the inbound request pipeline is executed with the “”(.*)”””)]
public void WhenTheInboundRequestPipelineIsExecutedWithThe(string inputMessageName)
{
var pipeline = (ReceivePipelineWrapper)ScenarioContext.Current[“Pipeline”];

string inputMessagePath = String.Format(“{0}.{1}”, MESSAGE_RESOURCE_PATH, “Input”);

using (Stream inputMessageStream = GetResourceStream(inputMessagePath, inputMessageName))
{
IBaseMessage inputMessage = MessageHelper.CreateFromStream(inputMessageStream);

inputMessage.Context.Promote(“InterchangeID”, “http://schemas.microsoft.com/BizTalk/2003/system-properties”, Guid.NewGuid().ToString());
inputMessage.Context.Promote(“CorrelationToken”, “http://schemas.microsoft.com/BizTalk/2003/system-properties”, Guid.NewGuid().ToString());
   MessageCollection outputMessageCollection = pipeline.Execute(inputMessage);

IBaseMessage outputMessage = outputMessageCollection.FirstOrDefault();

ScenarioContext.Current.Add(“OutputMessage”, outputMessage);
}
}

[Then(@”the following Context Properties should be promoted “”(.*)””, “”(.*)”””)]
public void ThenTheFollowingContextPropertiesShouldBePromoted(string targetMessageType, string targetSubscriberName)
{
var outputMessage = (IBaseMessage)ScenarioContext.Current[“OutputMessage”];

string messageType = outputMessage.Context.Read(“MessageType”, “http://schemas.microsoft.com/BizTalk/2003/system-properties”).ToString();

Assert.AreEqual(targetMessageType, messageType);
}

#region PrivateHelper

#endregion
}
}

The test fail on the highlighted step above with the below exception :

Test Name:    TestInboundRequestPipeline_ManageAlertResponse_Xml
Test FullName:    DB.Common.Test.Features.PipelinesFeature.TestInboundRequestPipeline_ManageAlertResponse_Xml
Test Source:     : line 2147483647
Test Outcome:    Failed
Test Duration:    0:00:00.1399699

Result Message:
Test method DB.Common.Test.Features.PipelinesFeature.TestInboundRequestPipeline_ManageAlertResponse_Xml threw exception:
System.InvalidOperationException: None of the disassembler components could recognize a data
Result StackTrace:
at Microsoft.Test.BizTalk.PipelineObjects.Stage.Execute(IPipelineContext pipelineContext, IBaseMessage inputMessage)
at Microsoft.Test.BizTalk.PipelineObjects.GenericPipeline.ExecuteSubPipeline(IPipelineContext pipelineContext, IBaseMessage inputMessage, Int32 startStageIndex, Int32 endStageIndex)
at Microsoft.Test.BizTalk.PipelineObjects.ReceivePipeline.Execute(IPipelineContext pipelineContext)
at Winterdom.BizTalk.PipelineTesting.ReceivePipelineWrapper.Execute(IBaseMessage inputMessage)
at .DB.Common.Test.Bindings.Pipelines.InboundRequestPipeline.WhenTheInboundRequestPipelineIsExecutedWithThe(String inputMessageName) in c:ShadabWSDevelopmentIntegrationDBCommon2.0DB.Common.TestBindingsPipelinesInboundRequestPipeline.cs:line 46
at lambda_method(Closure , IContextManager , String )
at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStep(StepInstance stepInstance)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep()
at TechTalk.SpecFlow.TestRunner.CollectScenarioErrors()
at .DB.Common.Test.Features.PipelinesFeature.ScenarioCleanup() in c:ShadabWSDevelopmentIntegrationDBCommon2.0DB.Common.TestFeaturesPipelines.feature.cs:line 0
at .DB.Common.Test.Features.PipelinesFeature.TestInboundRequestPipeline(String inputMessage, String typeName, String messageType, String subscriberName, String[] exampleTags) in c:ShadabWSDevelopmentIntegrationDBCommon2.0.DB.Common.TestFeaturesPipelines.feature:line 7
at .DB.Common.Test.Features.PipelinesFeature.TestInboundRequestPipeline_ManageAlertResponse_Xml() in c:ShadabWSDevelopmentIntegrationDBCommon2.0..Common.TestFeaturesPipelines.feature.cs:line 0

After doing some investigation, We found that if there is other Schemas Doc Specification present first in the order to the doc spec which is passed  from the unit test, the unit test component did not recognize the schema spec and fails the unit test.

For example: I’ve passed schema type “TypedProcedure_dbo“ from my unit test to the pipeline which is second in the list.

The unit test fails, because the first Schema type in the list is “EmployerSecurity”.

As soon as I move the “TypedProcedure_Dbo” up in the order, compile, Gac and run the unit test, all looks good and success.

It looks like the Pipeline Unit test only validate schema with the first spec, my question is why does the order matter in the Unit test while it does not matter at the run time? Just wondering if anyone have already experience similar issue and have a better solution?

Regards,

Shadab

Advertisements