public void CanCreateReceivePipelineFromType() { ReceivePipelineWrapper receivePipeline = PipelineFactory.CreateReceivePipeline(typeof(XMLReceive)); Assert.IsNotNull(receivePipeline); }
public void CanExecuteLoadedPipeline() { ReceivePipelineWrapper pipeline = PipelineFactory.CreateReceivePipeline(typeof(ReceivePipeline1)); // Create the input message to pass through the pipeline Stream stream = DocLoader.LoadStream("SampleDocument.xml"); IBaseMessage inputMessage = MessageHelper.CreateFromStream(stream); // Add the necessary schemas to the pipeline, so that // disassembling works pipeline.AddDocSpec(typeof(Schema1_NPP)); pipeline.AddDocSpec(typeof(Schema2_WPP)); // Execute the pipeline, and check the output MessageCollection outputMessages = pipeline.Execute(inputMessage); Assert.IsNotNull(outputMessages); Assert.IsTrue(outputMessages.Count > 0); // check we promoted properties correctly const string ns = "http://SampleSchemas.PropSchema1"; Assert.IsTrue(PropertyExists(outputMessages[0], ns, "Property1")); Assert.IsTrue(PropertyExists(outputMessages[0], ns, "Property1")); }
public void ContextPropertyExtractorClearsWrittenProperty() { const string content = "<ns0:Any xmlns:ns0=\"urn:schemas.stateless.be:biztalk:any:2012:12\"><message>content</message></ns0:Any>"; using (var stream = new StringStream(content)) { var pipeline = PipelineFactory.CreateReceivePipeline(typeof(ReceivePipelineInterpreter <XmlReceive>)); pipeline.AddDocSpec(typeof(Any)); var microPipeline = (MicroPipelineComponent)pipeline.GetComponent(PipelineStage.Decode, 1); microPipeline.Components = new[] { new ContextPropertyExtractor { Extractors = new[] { new PropertyExtractor(BizTalkFactoryProperties.CorrelationToken.QName, ExtractionMode.Clear) } } }; var inputMessage = MessageHelper.CreateFromStream(stream); inputMessage.SetProperty(BizTalkFactoryProperties.CorrelationToken, "written-token"); Assert.That(inputMessage.GetProperty(BizTalkFactoryProperties.CorrelationToken), Is.EqualTo("written-token")); Assert.That(inputMessage.IsPromoted(BizTalkFactoryProperties.CorrelationToken), Is.False); var outputMessages = pipeline.Execute(inputMessage); Assert.That(outputMessages[0].GetProperty(BizTalkFactoryProperties.CorrelationToken), Is.Null); Assert.That(outputMessages[0].IsPromoted(BizTalkFactoryProperties.CorrelationToken), Is.False); using (var reader = new StreamReader(outputMessages[0].BodyPart.Data)) { var readOuterXml = reader.ReadToEnd(); Assert.That(readOuterXml, Is.EqualTo(content)); } } }
public void ThrowExceptionWhenInputMsgIsNull() { ReceivePipelineWrapper pipeline = PipelineFactory.CreateReceivePipeline(typeof(ReceivePipeline1)); pipeline.Execute(null); }
public void TransformBatchContentToEnvelopeAndPromotePartition() { using (var stream = ResourceManager.Load("Data.BatchContent.xml")) { var inputMessage = MessageHelper.CreateFromStream(stream); inputMessage.Promote(BtsProperties.InboundTransportLocation, "mssql://localhost//BizTalkFactoryTransientStateDb"); var pipeline = PipelineFactory.CreateReceivePipeline(typeof(ReceivePipelineInterpreter <BatchReceive>)); pipeline.AddDocSpec(typeof(Batch.Content)); pipeline.AddDocSpec(typeof(Envelope)); var outputMessages = pipeline.Execute(inputMessage); Assert.That(outputMessages, Is.Not.Null); Assert.That(outputMessages.Count, Is.EqualTo(1)); Assert.That(outputMessages[0].GetProperty(BtsProperties.MessageType), Is.EqualTo(Schema <Envelope> .MessageType)); Assert.That(outputMessages[0].GetProperty(BizTalkFactoryProperties.EnvelopePartition), Is.EqualTo("partition-one")); Assert.That(outputMessages[0].IsPromoted(BizTalkFactoryProperties.EnvelopePartition)); using (var reader = ValidatingXmlReader.Create <Envelope, Batch.Release>(outputMessages[0].BodyPart.Data)) { var xmlDocument = new XmlDocument(); xmlDocument.Load(reader); Assert.That(xmlDocument.OuterXml, Is.EqualTo(ResourceManager.LoadXmlString("Data.ReleaseBatches.xml"))); } } }
public void JSONReceive_JSONMessage_CorrectValidXMLReturned() { string rootNode = "ServiceResponse"; string namespaceUri = "http://schemas.finance.yahoo.com/API/2014/08/"; string sourceDoc = Path.Combine(TestContext.DeploymentDirectory, "sample.json"); string schemaPath = Path.Combine(TestContext.DeploymentDirectory, "ServiceResponse.xsd"); string outputDoc = Path.Combine(TestContext.DeploymentDirectory, "JSONReceive.out"); var pipeline = PipelineFactory.CreateReceivePipeline(typeof(JSONReceive)); configureJSONReceivePipeline(pipeline, rootNode, namespaceUri); using (var inputStream = File.OpenRead(sourceDoc)) { pipeline.AddDocSpec(typeof(ServiceResponse)); var result = pipeline.Execute(MessageHelper.CreateFromStream(inputStream)); Assert.IsTrue(result.Count > 0, "No messages returned from pipeline."); using (var outputFile = File.OpenWrite(outputDoc)) { result[0].BodyPart.GetOriginalDataStream().CopyTo(outputFile); outputFile.Flush(); } } ServiceResponse schema = new ServiceResponse(); Assert.IsTrue(schema.ValidateInstance(outputDoc, Microsoft.BizTalk.TestTools.Schema.OutputInstanceType.XML), "Output message failed validation against the schema"); Assert.AreEqual(XDocument.Load(outputDoc).Descendants("Bid").First().Value, "44.97", "Incorrect Bid amount in output file"); }
public void DeferredPluginIsAlwaysExecuted() { using (var stream = ResourceManager.Load("Data.Content.zip")) { var pipeline = PipelineFactory.CreateReceivePipeline(typeof(ReceivePipelineInterpreter <ZipPassThruReceive>)); var pluginComponent = (ContextBuilderComponent)pipeline.GetComponent(PipelineStage.Decode, 0); pluginComponent.ExecutionMode = PluginExecutionMode.Deferred; pluginComponent.Builder = typeof(ContextBuilder); var inputMessage = MessageHelper.CreateFromStream(stream); var outputMessages = pipeline.Execute(inputMessage); Assert.That(outputMessages, Is.Not.Null); Assert.That(outputMessages.Count, Is.EqualTo(1)); Assert.That(outputMessages[0].GetProperty(TrackingProperties.Value1), Is.EqualTo("Plugin has been executed.")); } }
public void CanExecutePipelineWithFlatFile() { ReceivePipelineWrapper pipeline = PipelineFactory.CreateReceivePipeline(typeof(CSV_FF_RecvPipeline)); // Create the input message to pass through the pipeline Stream stream = DocLoader.LoadStream("CSV_FF_RecvInput.txt"); IBaseMessage inputMessage = MessageHelper.CreateFromStream(stream); inputMessage.BodyPart.Charset = "UTF-8"; // Add the necessary schemas to the pipeline, so that // disassembling works pipeline.AddDocSpec(typeof(Schema3_FF)); // Execute the pipeline, and check the output MessageCollection outputMessages = pipeline.Execute(inputMessage); Assert.IsNotNull(outputMessages); Assert.IsTrue(outputMessages.Count > 0); }
/// <summary> /// TestStepBase.Execute() implementation /// </summary> /// <param name='context'>The context for the test, this holds state that is passed beteen tests</param> public override void Execute(Context context) { if (_docSpecsRawList.Count > 0) { var ds = new List <Type>(_docSpecsRawList.Count); foreach (var docSpec in _docSpecsRawList) { var ass = AssemblyHelper.LoadAssembly((string)docSpec.AssemblyPath); context.LogInfo("Loading DocumentSpec {0} from location {1}.", docSpec.TypeName, ass.Location); var type = ass.GetType(docSpec.TypeName); ds.Add(type); } _docSpecs = ds.ToArray(); } context.LogInfo("Loading pipeline {0} from location {1}.", _pipelineTypeName, _pipelineAssemblyPath); var pipelineType = ObjectCreator.GetType(_pipelineTypeName, _pipelineAssemblyPath); var pipelineWrapper = PipelineFactory.CreateReceivePipeline(pipelineType); if (!string.IsNullOrEmpty(_instanceConfigFile)) { pipelineWrapper.ApplyInstanceConfig(_instanceConfigFile); } if (null != _docSpecs) { foreach (Type docSpec in _docSpecs) { pipelineWrapper.AddDocSpec(docSpec); } } MessageCollection mc = null; using (Stream stream = new FileStream(_source, FileMode.Open, FileAccess.Read)) { var inputMessage = MessageHelper.CreateFromStream(stream); if (!string.IsNullOrEmpty(_sourceEncoding)) { inputMessage.BodyPart.Charset = _sourceEncoding; } // Load context file, add to message context. if (!string.IsNullOrEmpty(_inputContextFile) && new FileInfo(_inputContextFile).Exists) { var mi = MessageInfo.Deserialize(_inputContextFile); mi.MergeIntoMessage(inputMessage); } mc = pipelineWrapper.Execute(inputMessage); } for (var count = 0; count < mc.Count; count++) { string destination = null; if (!string.IsNullOrEmpty(_destinationFileFormat)) { destination = string.Format(_destinationFileFormat, count); if (!string.IsNullOrEmpty(_destinationDir)) { destination = Path.Combine(_destinationDir, destination); } PersistMessageHelper.PersistMessage(mc[count], destination); } if (!string.IsNullOrEmpty(_outputContextFileFormat)) { var contextDestination = string.Format(_outputContextFileFormat, count); if (!string.IsNullOrEmpty(_destinationDir)) { contextDestination = Path.Combine(_destinationDir, contextDestination); } var mi = BizTalkMessageInfoFactory.CreateMessageInfo(mc[count], destination); MessageInfo.Serialize(mi, contextDestination); } } }
public void ThrowExceptionWhenInvalidTypeForReceivePipeline() { PipelineFactory.CreateReceivePipeline(typeof(XMLTransmit)); }
public void ThrowExceptionWhenNullReceivePipelineCreated() { PipelineFactory.CreateReceivePipeline(null); }
public void ContextPropertyExtractorPromotesConstant() { ContextPropertyExtractorPromotesConstant(PipelineFactory.CreateReceivePipeline(typeof(ReceivePipelineInterpreter <XmlReceive>))); }
public void ContextPropertyExtractorClearsWrittenProperty() { ContextPropertyExtractorClearsWrittenProperty(PipelineFactory.CreateReceivePipeline(typeof(ReceivePipelineInterpreter <XmlReceive>))); }
public void ContextPropertyExtractorClearsPromotedProperty() { ContextPropertyExtractorClearsPromotedProperty(PipelineFactory.CreateReceivePipeline(typeof(XmlReceive))); }
internal ReceivePipelineBuilder(Type type) { _pipeline = PipelineFactory.CreateReceivePipeline(type); }