Quantcast
Channel: Fluent Assertions
Viewing all articles
Browse latest Browse all 1402

New Post: Test XElement child node

$
0
0
Hi, say we have a xml file "Book.xml".
<?xml version="1.0"?>
<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>An in-depth look at creating applications 
      with XML.</description>
   </book>
   <book id="bk102">
      <author>Ralls, Kim</author>
      <title>Midnight Rain</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-12-16</publish_date>
      <description>A former architect battles corporate zombies, 
      an evil sorceress, and her own childhood to become queen 
      of the world.</description>
   </book>
</catalog>
Now I want to test the child attribute, how ?
        public XElement CheckBook()
        {
            XElement doc = XElement.Load(@"C:\Book.xml");
            return doc;
        }
In my xml unit testing code, we have
[TestMethod]
    public void TestBookXMLMethod()
    {
        BookXMLCheck bc = new BookXMLCheck();
        bc.CheckBook().Should().HaveAttribute("id","bk101")
            .And.HaveAttribute("id","bk102")
            .And.HaveElement("price")
            .And.HaveValue("44.95");
    }
Thank you

Viewing all articles
Browse latest Browse all 1402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>