【发布时间】:2020-05-28 16:22:51
【问题描述】:
var xml = new XmlDocument();
xml.LoadXml("<add name=\"console\" type=\"DefaultTraceLoader\" value=\"Error\"/>");
string path = @"D:\Config.xml";
System.IO.Fakes.ShimFile.ExistsString = p => true;
System.Xml.Fakes.ShimXmlDocument.AllInstances.LoadString = (a,b)=>
{
a = xDoc;
b = path;
};
System.Xml.fakes:
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
<Assembly Name="System.Xml" Version="4.0.0.0"/>
<ShimGeneration>
<Add FullName="System.Xml.XmlDocument!"/>
</ShimGeneration>
</Fakes>
我正在编写一个单元测试用例来填充 xmldocument 加载方法。当我调试原始项目时,它没有返回到 xmldocument 以上。我是否没有为 loadstring 函数在主项目中返回预期的 xml 文档做正确的方法?
【问题讨论】:
标签: c# unit-testing microsoft-fakes