Skip to content

Commit 2c8f90b

Browse files
author
Denis Ivanov
committed
Added HtmlDocumentNavigable class
1 parent 1e4b513 commit 2c8f90b

File tree

7 files changed

+189
-13
lines changed

7 files changed

+189
-13
lines changed

src/AngleSharp.XPath.Tests/AngleSharp.XPath.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<ItemGroup>
3-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
3+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.0" />
44
<PackageReference Include="NUnit" Version="3.9.0" />
5-
<PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />
5+
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
66
</ItemGroup>
77
<ItemGroup>
88
<ProjectReference Include="..\AngleSharp.XPath\AngleSharp.XPath.csproj" />
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#region License
2+
// MIT License
3+
//
4+
// Copyright (c) 2018 Denis Ivanov
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
#endregion
24+
25+
using System;
26+
using AngleSharp.Parser.Html;
27+
using NUnit.Framework;
28+
29+
namespace AngleSharp.XPath.Tests
30+
{
31+
[TestFixture]
32+
public class HtmlDocumentNavigableTests
33+
{
34+
[Test]
35+
public void Ctor_NullDocumentArgument_DoesThrowException()
36+
{
37+
// Arrange
38+
39+
// Act
40+
41+
// Assert
42+
Assert.Throws<ArgumentNullException>(() => new HtmlDocumentNavigable(null));
43+
}
44+
45+
[Test]
46+
public void CreateNavigator_Call_ShouldReturnHtmlDocumentNavigator()
47+
{
48+
// Arrange
49+
var parser = new HtmlParser();
50+
var document = parser.Parse("<html></html>");
51+
var navigable = new HtmlDocumentNavigable(document);
52+
53+
// Act
54+
var navigator = navigable.CreateNavigator();
55+
56+
// Assert
57+
Assert.That(navigator, Is.TypeOf<HtmlDocumentNavigator>());
58+
}
59+
}
60+
}

src/AngleSharp.XPath.Tests/HtmlDocumentNavigatorTests.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
1-
using NUnit.Framework;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
1+
#region License
2+
// MIT License
3+
//
4+
// Copyright (c) 2018 Denis Ivanov
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
#endregion
24+
25+
using NUnit.Framework;
526
using System.Threading.Tasks;
627
using AngleSharp.Parser.Html;
7-
using AngleSharp.XPath;
828

929
namespace AngleSharp.XPath.Tests
1030
{

src/AngleSharp.XPath/AngleSharp.XPath.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<Version>1.0.1</Version>
3+
<Version>1.0.2</Version>
44
<Authors>Denis Ivanov</Authors>
55
<PackageId>AngleSharp.XPath</PackageId>
6-
<AssemblyVersion>1.0.1</AssemblyVersion>
7-
<FileVersion>1.0.1</FileVersion>
6+
<AssemblyVersion>1.0.2</AssemblyVersion>
7+
<FileVersion>1.0.2</FileVersion>
88
<Description>XPath support for AngleSharp</Description>
99
<PackageProjectUrl>https://github.com/denis-ivanov/AngleSharp.XPath/</PackageProjectUrl>
10+
<PackageLicenseUrl>https://github.com/denis-ivanov/AngleSharp.XPath/blob/master/LICENSE</PackageLicenseUrl>
1011
<PackageTags>HTML XPath AngleSharp</PackageTags>
1112
</PropertyGroup>
1213
<PropertyGroup>

src/AngleSharp.XPath/Extensions.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,31 @@
1-
using AngleSharp.Dom;
1+
#region License
2+
// MIT License
3+
//
4+
// Copyright (c) 2018 Denis Ivanov
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
#endregion
24+
25+
using AngleSharp.Dom;
226
using AngleSharp.Dom.Html;
327
using System;
428
using System.Collections.Generic;
5-
using System.Collections.Specialized;
629
using System.Diagnostics;
730
using System.Xml;
831
using System.Xml.XPath;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#region License
2+
// MIT License
3+
//
4+
// Copyright (c) 2018 Denis Ivanov
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
#endregion
24+
25+
using System;
26+
using System.Xml.XPath;
27+
using AngleSharp.Dom.Html;
28+
29+
namespace AngleSharp.XPath
30+
{
31+
/// <inheritdoc />
32+
public class HtmlDocumentNavigable : IXPathNavigable
33+
{
34+
private readonly IHtmlDocument _document;
35+
36+
/// <inheritdoc />
37+
public HtmlDocumentNavigable(IHtmlDocument document)
38+
{
39+
_document = document ?? throw new ArgumentNullException(nameof(document));
40+
}
41+
42+
/// <inheritdoc />
43+
public XPathNavigator CreateNavigator()
44+
{
45+
return _document.CreateNavigator();
46+
}
47+
}
48+
}

src/AngleSharp.XPath/HtmlDocumentNavigator.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
1-
using AngleSharp.Dom;
1+
#region License
2+
// MIT License
3+
//
4+
// Copyright (c) 2018 Denis Ivanov
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
#endregion
24+
25+
using AngleSharp.Dom;
226
using System;
327
using System.Xml;
428
using System.Xml.XPath;

0 commit comments

Comments
 (0)