c# - Biztalk 映射单元测试异常

标签 c# unit-testing xslt biztalk biztalk-2013r2

我正在尝试使用以下代码对 map 进行单元测试,

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"));
        }

这适用于大多数 map ,但是如果我使用来自外部程序集的函数,这将不起作用并因错误而失败

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)

最佳答案

无法调试引用外部程序集的自定义 xslt。

检查 this线程以获取更多信息

编辑: this您可能也会感兴趣。

关于c# - Biztalk 映射单元测试异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28161885/

相关文章:

xml - 如何将 XML 文件与 XSLT 文件链接起来?

excel - XSLT 处理从 Excel 转换的 XML

typescript - 如何在使用 React Navigation 和 TypeScript 时使用 Jest 和 Enzyme 对静态 navigationOptions 进行单元测试?

c# - 为什么我收到此错误 : requires a return value or an exception to throw?

c# - 如何使用 C# 和 LINQ 深入提取 XML 中的信息?

c# - 使用C#检查运行进程的结果

javascript - 导入 SASS 文件的测试组件时出现语法错误

ios - 从框架项目进行单元测试时应用程序崩溃

xslt - XMLStarlet + XInclude + XSLT

c# - 我如何从 C# 中的选定内容中排序