我们需要验证生成的 xml 文档的内容。是否有任何框架可以帮助轻松提取和验证文档内容?
我们需要知道的事情
- 包含元素x
- 元素 x 的值
- 元素 x 包含值为 z 的属性 y
- 意外元素
如果没有断言也没关系,这可以通过 MSTest 来完成
最佳答案
查看 Fluent Assertions 库文档:https://fluentassertions.com/introduction
标题为“XML 类”的部分听起来像是您所追求的内容。该代码在底层使用 LINQ-to-XML。
xDocument.Should().HaveRoot("configuration");
xDocument.Should().HaveElement("settings");
xElement.Should().HaveAttribute("age", "36");
xElement.Should().HaveElement("address");
xAttribute.Should().HaveValue("Amsterdam");
您可以在此处从 nuget 安装 FluentAssertions:http://nuget.org/packages/FluentAssertions
关于.net - MSTest 的 XML 单元测试框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13755113/