MSTest的XML单元测试框架

Rya*_*ham 2 .net xml mstest

我们需要验证我们生成的xml文档的内容.是否有任何框架可以帮助您轻松提取和验证文档的内容?

我们需要知道的事情

  • 包含元素x
  • 元素x的值
  • 元素x包含值为z的属性y
  • 意外的元素

如果没有断言,那么无关紧要,这可以通过MSTest来完成

Jac*_*hes 6

请在此处查看Fluent Assertions库文档:http://fluentassertions.codeplex.com/documentation

标题为"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");
Run Code Online (Sandbox Code Playgroud)

您可以在此处安装来自nuget的FluentAssertions:http://nuget.org/packages/FluentAssertions