From 586687e8825a7e21fbd524f8d482ef28822ab74e Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sat, 21 Jan 2023 09:13:57 +0100 Subject: [PATCH 1/2] Add more tests for Issue59 --- tests/XPath2.Tests/XPathNavigatorTests.cs | 33 +++++++---------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/tests/XPath2.Tests/XPathNavigatorTests.cs b/tests/XPath2.Tests/XPathNavigatorTests.cs index 9c4d367..d8b843e 100644 --- a/tests/XPath2.Tests/XPathNavigatorTests.cs +++ b/tests/XPath2.Tests/XPathNavigatorTests.cs @@ -366,37 +366,22 @@ public void XPath2Evaluate_FullPathWithAttributeSelection() /// - https://learn.microsoft.com/en-us/dotnet/api/system.xml.xpath.xpathnodeiterator.count?view=net-7.0 /// - Count = Gets the index of the last node in the selected set of nodes. /// - [Fact] - public void Issue59_XDocumentParse_XPath2SelectNodes_Count_Returns_TheIndexOfTheLastNode() + [Theory] + [InlineData("/report/brand", 5, 4)] + [InlineData("/report/brand[units > 20000]", 2, 1)] + public void Issue59_XDocumentParse_XPath2SelectNodes_Count_And_CurrentPosition_Is_Correct(string xpath, int expectedItemCount, int expectedCount) { // Arrange var xml = GetXml(); var navigator = XDocument.Parse(xml).CreateNavigator(); - // Act 1 - var brandSet = navigator.XPath2SelectNodes("/report/brand"); - - // Assert 1 - brandSet.Count.Should().Be(4); - - // Act 2 - var brandCount = (int)navigator.XPath2Evaluate("count(/report/brand)"); - - // Assert 2 - brandCount.Should().Be(5); - - // Act 3 - var highVolumeBrandSet = navigator.XPath2SelectNodes("/report/brand[units > 20000]"); - - // Assert 3 - highVolumeBrandSet.Count.Should().Be(1); - - // Act 4 - var highVolumeBrandCount = (int)navigator.XPath2Evaluate("count(/report/brand[units > 20000])"); + // Act + var nodes = navigator.XPath2SelectNodes(xpath); - // Assert 4 - highVolumeBrandCount.Should().Be(2); + // Assert + nodes.Should().HaveCount(expectedItemCount); + nodes.Count.Should().Be(expectedCount); } [Fact] From fa48f1555da585998544ab1a0cd94c03768ea26d Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Tue, 28 Nov 2023 19:18:55 +0100 Subject: [PATCH 2/2] ? --- tests/XPath2.Tests/XPathNavigatorTests.cs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/XPath2.Tests/XPathNavigatorTests.cs b/tests/XPath2.Tests/XPathNavigatorTests.cs index d8b843e..c68fbce 100644 --- a/tests/XPath2.Tests/XPathNavigatorTests.cs +++ b/tests/XPath2.Tests/XPathNavigatorTests.cs @@ -369,7 +369,7 @@ public void XPath2Evaluate_FullPathWithAttributeSelection() [Theory] [InlineData("/report/brand", 5, 4)] [InlineData("/report/brand[units > 20000]", 2, 1)] - public void Issue59_XDocumentParse_XPath2SelectNodes_Count_And_CurrentPosition_Is_Correct(string xpath, int expectedItemCount, int expectedCount) + public void Issue59_XDocumentParse_XPath2SelectNodes_Count_And_Enumerator_Is_Correct(string xpath, int expectedItemCount, int expectedCount) { // Arrange var xml = GetXml(); @@ -384,6 +384,27 @@ public void Issue59_XDocumentParse_XPath2SelectNodes_Count_And_CurrentPosition_I nodes.Count.Should().Be(expectedCount); } + /// + /// + /// + /// + [Fact] + [InlineData(new[] { "/report/brand" })] + public void Issue59_XDocumentParse_XPath2SelectNodes_Count_And_CurrentPosition_Is_Correct(string[] names) + { + // Arrange + var xml = GetXml(); + + var navigator = XDocument.Parse(xml).CreateNavigator(); + + // Act + var nodes = navigator.XPath2SelectNodes("/report/brand"); + + // Assert + nodes.Should().HaveCount(expectedItemCount); + nodes.Count.Should().Be(expectedCount); + } + [Fact] public void Issue59_XDocumentParse_XPath2SelectNodes_CountMethod_Returns_Number_Of_Items_In_Expression() {