【问题标题】:How to test XElement's child element's attributes, values by using Fluent Assertions?如何使用 Fluent Assertions 测试 XElement 的子元素的属性、值?
【发布时间】:2015-04-29 07:05:27
【问题描述】:

假设我有一个XElement 对象,它表示类似Xml

<modification name="givenName" operation="add" xmlns="urn:oasis:names:tc:DSML:2:0:core">
    <value>Changed name</value>
    <child id="abc">Some dummy value</child>
</modification>

如何测试&lt;value&gt; 元素的值为“已更改名称”,&lt;child&gt; 元素具有属性id“abc”,值为“某个虚拟值”?

【问题讨论】:

    标签: fluent-assertions


    【解决方案1】:
    element.Should().HaveElement("value").Which.Should().HaveValue("Changed name");
    element.Should().HaveElement("child").Which.Should().HaveAttribute("id", "abc").And.HaveValue("Some dummy value");
    

    【讨论】:

      猜你喜欢
      • 2012-08-19
      • 2016-05-02
      • 2016-08-15
      • 2019-10-28
      • 2013-07-18
      • 2018-02-22
      • 2020-05-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多