public void XmlContextLoader_Positive() { ContextLoaderStepBuilder clsb = new ContextLoaderStepBuilder("BizUnit.XmlContextLoader", null); object[] args = new object[2]; args[0] = "MyContextKey"; args[1] = "*[local-name()='PurchaseOrder' and namespace-uri()='http://SendMail.PurchaseOrder']/*[local-name()='PONumber' and namespace-uri()='']"; clsb.SetProperty("XPathExpressions", args); Context ctx = new Context(); Stream data = ResourceLoaderHelper.GetResourceDataAsStream("Data", "PurchaseOrder001.xml"); clsb.ContextLoaderStep.Validate(ctx); clsb.ContextLoaderStep.ExecuteContextLoader(data, ctx); Assert.AreEqual("PONumber_0", ctx.GetValue("MyContextKey")); }
public override Stream Load(Context context) { var doc = new XmlDocument(); context.LogInfo("Loading file: {0}", FilePath); doc.Load(FilePath); if (null != UpdateXml) { foreach (var xpath in UpdateXml) { context.LogInfo("Selecting node in document, description: {0}, XPath: {1}", xpath.Description, xpath.XPath); XPathNavigator xpn = doc.CreateNavigator(); XPathNavigator node = xpn.SelectSingleNode(xpath.XPath); if (null == node) { context.LogError("XPath expression failed to find node"); throw new ApplicationException(String.Format("Node not found: {0}", xpath.Description)); } if (!string.IsNullOrEmpty(xpath.ContextKey)) { context.LogInfo("Updating XmlNode with value from context key: {0}", xpath.ContextKey); node.SetValue(context.GetValue(xpath.ContextKey)); } else { context.LogInfo("Updating XmlNode with value: {0}", xpath.Value); node.SetValue(xpath.Value); } } } MemoryStream ms = new MemoryStream(); doc.Save(ms); ms.Seek(0, SeekOrigin.Begin); return ms; }