-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more unit tests for issue 58 (#61)
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>" | ||
}; | ||
} | ||
} |