Skip to content

Commit

Permalink
Add more unit tests for issue 58 (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefH committed Dec 5, 2022
1 parent ec78c36 commit 70a0c04
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/XPath2.Tests/XPath2.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<DebugType>full</DebugType>
<ProjectGuid>{31DC2EF8-C3FE-467D-84BE-FB5D956E6100}</ProjectGuid>
<LangVersion>10</LangVersion>
</PropertyGroup>

<!--<ItemGroup>
Expand Down
81 changes: 81 additions & 0 deletions tests/XPath2.Tests/XmlDocumentTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System.Xml;
using FluentAssertions;
using Wmhelp.XPath2;
using Xunit;

namespace XPath2.Tests;

public class XmlDocumentTests
{
// Issue #58
[Theory]
[InlineData("max(/R/A/number(@id))")]
[InlineData("max(/R/A/@id)")]
public void XmlDocument_XPath2Evaluate_MaxFromNumber(string xpath)
{
// Arrange
var doc = GetIssue58();

// Act
var result = doc.XPath2Evaluate(xpath);

// Assert
result.Should().Be(2);
}

// Issue #58
[Theory]
[InlineData("/R/A[@id=2]")]
[InlineData("/R/A[@id='2']")]
[InlineData("/R/A[@id=\"2\"]")]
public void XmlDocument_SelectNodes_By_Attribute(string xpath)
{
// Arrange
var doc = GetIssue58();

// Act
var result = doc.SelectNodes(xpath);

// Assert
result.Should().HaveCount(1);
result![0].OuterXml.Should().Be("<A id=\"2\" />");
}

// Issue #58
[Fact(Skip = "System.Xml.XPath.XPathException : Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.")]
public void XmlDocument_SelectNodes_By_AttributeEqualsMaxId_Version1()
{
// Arrange
var doc = GetIssue58();

// Act
var result = doc.SelectNodes("/R/A[@id=max(/R/A/@id)]");

// Assert
result.Should().HaveCount(1);
result![0].OuterXml.Should().Be("<A id=\"2\" />");
}

// Issue #58
[Fact]
public void XmlDocument_SelectNodes_By_AttributeEqualsMaxId_Version2()
{
// Arrange
var doc = GetIssue58();

// Act
var result = doc.SelectNodes("/R/A[not(/R/A/@id > @id)]");

// Assert
result.Should().HaveCount(1);
result![0].OuterXml.Should().Be("<A id=\"2\" />");
}

private static XmlDocument GetIssue58()
{
return new XmlDocument
{
InnerXml = @"<R><A id=""1""/><A id=""2""/></R>"
};
}
}

0 comments on commit 70a0c04

Please sign in to comment.