@@ -64,18 +64,20 @@ public void GivenAnXmlFile_WhenSelectingASingleNode_ThenReturnsTheSecondPosition
6464 {
6565 var result = XmlNodesSelector . SelectSingleBook ( _document . DocumentElement ! ) ;
6666
67- Assert . Equal ( result , _expectedResults [ "Book2" ] ) ;
67+ Assert . Equal ( result ? . ReplaceLineEndings ( ) , _expectedResults [ "Book2" ] . ReplaceLineEndings ( ) ) ;
6868 }
6969
7070 [ Fact ]
7171 public void GivenAnXmlFile_WhenSelectingNodes_ThenReturnBooksWithPriceLowerThan50 ( )
7272 {
7373 var expected = _expectedResults
7474 . Where ( pair => pair . Key is "Book1" or "Book3" )
75- . Select ( pair => pair . Value )
75+ . Select ( pair => pair . Value . ReplaceLineEndings ( ) )
7676 . ToList ( ) ;
7777
78- var result = XmlNodesSelector . SelectBooks ( _document . DocumentElement ! ) ;
78+ var result = XmlNodesSelector . SelectBooks ( _document . DocumentElement ! )
79+ . Select ( x => x . ReplaceLineEndings ( ) )
80+ . ToList ( ) ;
7981
8082 Assert . Equal ( result , expected ) ;
8183 }
@@ -86,11 +88,53 @@ public void GivenAnXmlFile_WhenSelectingNodesUsingNamespaces_ThenReturnBookEleme
8688 var expected =
8789 _expectedResults
8890 . Where ( pair => pair . Key is "Book4" )
89- . Select ( pair => pair . Value )
91+ . Select ( pair => pair . Value . ReplaceLineEndings ( ) )
9092 . ToList ( ) ;
9193
92- var result = XmlNodesSelector . SelectBooksUsingNamespaces ( _document ) ;
94+ var result = XmlNodesSelector . SelectBooksUsingNamespaces ( _document )
95+ . Select ( x => x . ReplaceLineEndings ( ) )
96+ . ToList ( ) ;
9397
9498 Assert . Equal ( result , expected ) ;
9599 }
96- }
100+
101+ [ Fact ]
102+ public void GivenAnXmlFile_WhenSelectSingleNodeMatchesNothing_ThenReturnsNull ( )
103+ {
104+ var node = _document . DocumentElement ! . SelectSingleNode ( "//catalog/book[price>1000]" ) ;
105+
106+ Assert . Null ( node ) ;
107+ }
108+
109+ [ Fact ]
110+ public void GivenAnXmlFile_WhenSelectNodesMatchesNothing_ThenReturnsAnEmptyList ( )
111+ {
112+ var nodes = _document . DocumentElement ! . SelectNodes ( "//catalog/book[price>1000]" ) ;
113+
114+ Assert . NotNull ( nodes ) ;
115+ Assert . Equal ( 0 , nodes . Count ) ;
116+ }
117+
118+ [ Fact ]
119+ public void GivenABookInADefaultNamespace_WhenQueryingWithAnUnprefixedName_ThenReturnsThreeOfTheFourBooks ( )
120+ {
121+ var nodes = _document . DocumentElement ! . SelectNodes ( "//catalog/book" ) ;
122+
123+ Assert . NotNull ( nodes ) ;
124+ Assert . Equal ( 3 , nodes . Count ) ;
125+ }
126+
127+ [ Fact ]
128+ public void GivenAnXDocument_WhenSelectingWithXPathSelectElements_ThenReturnsTheSameBooksAsSelectNodes ( )
129+ {
130+ var expected = XmlNodesSelector . SelectBooks ( _document . DocumentElement ! )
131+ . Select ( x => x . ReplaceLineEndings ( ) )
132+ . ToList ( ) ;
133+
134+ var result = XmlNodesSelector . SelectBooksWithLinqToXml ( XDocument . Load ( "BooksCatalog.xml" ) )
135+ . Select ( x => x . ReplaceLineEndings ( ) )
136+ . ToList ( ) ;
137+
138+ Assert . Equal ( expected , result ) ;
139+ }
140+ }
0 commit comments