/// <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); } } }
/// <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.CreateSendPipeline(pipelineType); if (!string.IsNullOrEmpty(_instanceConfigFile)) { pipelineWrapper.ApplyInstanceConfig(_instanceConfigFile); } if (null != _docSpecs) { foreach (Type docSpec in _docSpecs) { pipelineWrapper.AddDocSpec(docSpec); } } var mc = new MessageCollection(); FileInfo[] contexts = null; if (!string.IsNullOrEmpty(_inputContextDir) && !string.IsNullOrEmpty(_inputContextSearchPattern)) { var cdi = new DirectoryInfo(_inputContextDir); contexts = cdi.GetFiles(_inputContextSearchPattern); } var di = new DirectoryInfo(_sourceDir); int index = 0; foreach (FileInfo fi in di.GetFiles(_searchPattern)) { Stream stream = new FileStream(fi.FullName, 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 ((null != contexts) && (contexts.Length > index)) { string cf = contexts[index].FullName; if (System.IO.File.Exists(cf)) { MessageInfo mi = MessageInfo.Deserialize(cf); mi.MergeIntoMessage(inputMessage); } } mc.Add(inputMessage); index++; } var outputMsg = pipelineWrapper.Execute(mc); PersistMessageHelper.PersistMessage(outputMsg, _destination); if (!string.IsNullOrEmpty(_outputContextFile)) { var omi = BizTalkMessageInfoFactory.CreateMessageInfo(outputMsg, _destination); MessageInfo.Serialize(omi, _outputContextFile); } }