C# Biztalk映射单元测试异常
我试图用以下代码对一个映射进行单元测试C# Biztalk映射单元测试异常,c#,unit-testing,xslt,biztalk,biztalk-2013r2,C#,Unit Testing,Xslt,Biztalk,Biztalk 2013r2,我试图用以下代码对一个映射进行单元测试 protected string Map(TransformBase map, string xml) { StringWriter str = new StringWriter(); XmlTextWriter writer = new XmlTextWriter(str); map.Transform.Transform(new XPathDocument(new
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)
结果消息:System.Xml.Xsl.XslTransformException:找不到与命名空间“”关联的脚本或扩展对象http://schemas.microsoft.com/BizTalk/2003/ScriptNS0'.
结果跟踪:
在System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(字符串名称、字符串名称空间URI、IList`1[]参数)处
在(XmlQueryRuntime{urn:schemas microsoft com:xslt debug}运行时,XPathNavigator{urn:schemas microsoft com:xslt debug}当前)
在(XmlQueryRuntime{urn:schemas microsoft com:xslt debug}运行时,XPathNavigator{urn:schemas microsoft com:xslt debug}当前)
在根目录下(XmlQueryRuntime{urn:schemas-microsoft-com:xslt-debug}运行时)
在执行时(XmlQueryRuntime{urn:schemas microsoft com:xslt debug}运行时)
在System.Xml.Xsl.XmlILCommand.Execute(对象defaultDocument、XmlResolver数据源、XslTargetList argumentList、XmlSequenceWriter结果)
在System.Xml.Xsl.XmlILCommand.Execute(对象defaultDocument、XmlResolver数据源、XslTargetList argumentList、XmlWriter)
在System.Xml.Xsl.xslcomiledTransform.Transform(XmlReader输入、XSLTargetList参数、XmlWriter结果)
无法参照外部程序集调试自定义xslt
检查线程以获取更多信息
编辑:您可能也会感兴趣。不可能参照外部程序集调试自定义xslt 检查线程以获取更多信息
编辑:您可能也会感兴趣。最后,我用以下代码(BT 2013 R2)实现了这一点, 方法
Map
执行实际映射并返回结果xml
参数
map -> new object of the map type instance
xml -> source xml content
extObjects -> *_extxml.xml file content generated when executing validate instance on the map
代码
示例用法
[Test]
public void Map_Test()
{
var result = Map(new A_To_B()
, File.ReadAllText("A.xml")
, File.ReadAllText("A_To_B_extxml.xml"));
Assert.IsNotNullOrEmpty(result);
}
最后,我用以下代码(BT 2013 R2)实现了这一点, 方法
Map
执行实际映射并返回结果xml
参数
map -> new object of the map type instance
xml -> source xml content
extObjects -> *_extxml.xml file content generated when executing validate instance on the map
代码
示例用法
[Test]
public void Map_Test()
{
var result = Map(new A_To_B()
, File.ReadAllText("A.xml")
, File.ReadAllText("A_To_B_extxml.xml"));
Assert.IsNotNullOrEmpty(result);
}