Som*_*Guy 8 .net xml nunit unit-testing xmlunit
我有几个单元测试,我需要确保方法生成的XML包含与预期的Xml文档相同的元素/值.
我在Java中使用了xmlunit,虽然它们有.net版本但它似乎不支持命名空间.在.net中有没有替代方法呢?
只要我可以比较2个Xml字符串并得到一个真/假的结果告诉我它们是否匹配,只要涉及到的数据,我很高兴...
尝试 Microsoft.XmlDiffPatch:
static public bool IsXmlEqual( XmlReader x1, XmlReader x2,
bool IgnoreChildOrder, bool IgnoreComments, bool IgnorePI, bool IgnoreWhitespace,
bool IgnoreNamespaces, bool IgnorePrefixes, bool IgnoreXmlDecl, bool IgnoreDtd
)
{
XmlDiffOptions options = XmlDiffOptions.None;
if (IgnoreChildOrder) options |= XmlDiffOptions.IgnoreChildOrder;
if (IgnoreComments) options |= XmlDiffOptions.IgnoreComments;
if (IgnorePI) options |= XmlDiffOptions.IgnorePI;
if (IgnoreWhitespace) options |= XmlDiffOptions.IgnoreWhitespace;
if (IgnoreNamespaces) options |= XmlDiffOptions.IgnoreNamespaces;
if (IgnorePrefixes) options |= XmlDiffOptions.IgnorePrefixes;
if (IgnoreXmlDecl) options |= XmlDiffOptions.IgnoreXmlDecl;
if (IgnoreDtd) options |= XmlDiffOptions.IgnoreDtd;
XmlDiff xmlDiff = new XmlDiff(options);
bool bequal = xmlDiff.Compare(x1, x2, null);
return bequal;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1386 次 |
最近记录: |