Skip to content

Commit 0ce7916

Browse files
committed
Added tests for #20
1 parent 98040df commit 0ce7916

File tree

3 files changed

+90
-4
lines changed

3 files changed

+90
-4
lines changed

AngleSharp.Scripting.JavaScript.Tests/AngleSharp.Scripting.JavaScript.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
<ItemGroup>
8282
<Compile Include="FireEventTests.cs" />
8383
<Compile Include="GeneratorTests.cs" />
84+
<Compile Include="Helper.cs" />
8485
<Compile Include="IntegrationTests.cs" />
8586
<Compile Include="InteractionTests.cs" />
8687
<Compile Include="JqueryTests.cs" />
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
namespace AngleSharp.Scripting.JavaScript.Tests
2+
{
3+
using NUnit.Framework;
4+
using System;
5+
using System.Net.NetworkInformation;
6+
7+
class Helper
8+
{
9+
/// <summary>
10+
/// Indicates whether any network connection is available
11+
/// Filter connections below a specified speed, as well as virtual network cards.
12+
/// Additionally writes an inconclusive message if no network is available.
13+
/// </summary>
14+
/// <returns>True if a network connection is available; otherwise false.</returns>
15+
public static Boolean IsNetworkAvailable()
16+
{
17+
if (IsNetworkAvailable(0))
18+
{
19+
return true;
20+
}
21+
22+
Assert.Inconclusive("No network has been detected. Test skipped.");
23+
return false;
24+
}
25+
26+
/// <summary>
27+
/// Indicates whether any network connection is available.
28+
/// Filter connections below a specified speed, as well as virtual network cards.
29+
/// </summary>
30+
/// <param name="minimumSpeed">The minimum speed required. Passing 0 will not filter connection using speed.</param>
31+
/// <returns>True if a network connection is available; otherwise false.</returns>
32+
public static Boolean IsNetworkAvailable(Int64 minimumSpeed)
33+
{
34+
if (NetworkInterface.GetIsNetworkAvailable())
35+
{
36+
foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
37+
{
38+
// discard because of standard reasons
39+
if ((ni.OperationalStatus != OperationalStatus.Up) ||
40+
(ni.NetworkInterfaceType == NetworkInterfaceType.Loopback) ||
41+
(ni.NetworkInterfaceType == NetworkInterfaceType.Tunnel))
42+
continue;
43+
44+
// this allow to filter modems, serial, etc.
45+
// I use 10000000 as a minimum speed for most cases
46+
if (ni.Speed < minimumSpeed)
47+
continue;
48+
49+
// discard virtual cards (virtual box, virtual pc, etc.)
50+
if ((ni.Description.IndexOf("virtual", StringComparison.OrdinalIgnoreCase) >= 0) ||
51+
(ni.Name.IndexOf("virtual", StringComparison.OrdinalIgnoreCase) >= 0))
52+
continue;
53+
54+
// discard "Microsoft Loopback Adapter", it will not show as NetworkInterfaceType.Loopback but as Ethernet Card.
55+
if (ni.Description.Equals("Microsoft Loopback Adapter", StringComparison.OrdinalIgnoreCase))
56+
continue;
57+
58+
return true;
59+
}
60+
}
61+
62+
return false;
63+
}
64+
}
65+
}
Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
11
namespace AngleSharp.Scripting.JavaScript.Tests
22
{
3+
using AngleSharp.Dom;
34
using NUnit.Framework;
5+
using System;
46
using System.Threading.Tasks;
57

68
[TestFixture]
79
public class IntegrationTests
810
{
11+
static Task<IDocument> LoadPage(String url)
12+
{
13+
var configuration = Configuration.Default.WithDefaultLoader().WithCss().WithCookies().WithJavaScript();
14+
var context = BrowsingContext.New(configuration);
15+
return context.OpenAsync(url);
16+
}
17+
918
[Test]
1019
public async Task PageEcoEnergyShouldLoadFine()
1120
{
12-
var config = Configuration.Default.WithDefaultLoader().WithCss().WithCookies().WithJavaScript();
13-
var context = BrowsingContext.New(config);
14-
var document = await context.OpenAsync("http://www.eco2energie.biz/");
15-
Assert.IsNotNull(document);
21+
if (Helper.IsNetworkAvailable())
22+
{
23+
var document = await LoadPage("http://www.eco2energie.biz/");
24+
Assert.IsNotNull(document);
25+
}
26+
}
27+
28+
[Test]
29+
public async Task PageGamestarShouldLoadFine()
30+
{
31+
if (Helper.IsNetworkAvailable())
32+
{
33+
var document = await LoadPage("http://www.gamestar.de/index.cfm?pid=103&op=10");
34+
Assert.IsNotNull(document);
35+
}
1636
}
1737
}
1838
}

0 commit comments

Comments
 (0)