我正在尝试使用以下代码对地图进行单元测试,
protected string Map(TransformBase map, string xml)
{
StringWriter str = new StringWriter();
XmlTextWriter writer = new XmlTextWriter(str);
map.Transform.Transform(new XPathDocument(new StringReader(xml)), new XsltArgumentList(), writer);
return str.ToString();
}
它的调用如下,
[Test]
public void Map_Test()
{
var result = Map(new TestMap(),File.ReadAllText(_dataDir.GetFiles("TestRequest.xml")[0].FullName));
Assert.IsTrue(result.Contains("4323432"));
}
这适用于大多数地图,但是如果我使用来自外部程序集的函数,这将不起作用并失败并出现错误
Result Message: System.Xml.Xsl.XslTransformException : Cannot find a script or an extension object associated with namespace 'http://schemas.microsoft.com/BizTalk/2003/ScriptNS0'.
Result StackTrace:
at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args)
at <xsl:template match="/workOrderRequest">(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current)
at <xsl:template match="/">(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current)
at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results)
at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer)
at System.Xml.Xsl.XslCompiledTransform.Transform(XmlReader input, XsltArgumentList arguments, XmlWriter results)