[英]Fluent assertions for xml
I have a xml file of the form:我有一个格式为 xml 的文件:
<Level1>
<Level2>
<Level3>
<Level4 attr1 = "123.4" attr2 = ""> </Level4>
</Level3>
</Level2>
<Level1>
I'm using XUnit to check the structure of the xml.我正在使用 XUnit 检查 xml 的结构。
[Fact]
public void Xml_Check()
{
var doc = XDocument.Load("test.xml");
doc.Should().HaveRoot("Level1");
doc.Should().HaveElement("Level2");
doc.Should().HaveElement("Level3"); //Erroring on this line
}
I'm getting the error: Expected XML document <Level1>...</Level1>
to have root element with child "Level3" but no such child element was found.我收到错误消息:预期 XML 文档
<Level1>...</Level1>
具有带有子“Level3”的根元素,但没有找到这样的子元素。 It is trying to treat Level3 as a child of Level1 instead of Level2.它试图将 Level3 视为 Level1 而不是 Level2 的子级。
How do I get the Level3 and check whether certain attributes exist in Level4?如何获取Level3并检查Level4中是否存在某些属性? Is there a way to check the type of the attribute value?
有没有办法检查属性值的类型?
Finally got it working and someone might find it useful in future终于让它工作了,将来有人可能会发现它有用
It should be:它应该是:
doc.Should().HaveElement("Level2").Which.Should().HaveElement("Level3");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.