-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasicTest.cs
81 lines (67 loc) · 2.34 KB
/
BasicTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System.Net.Http;
using System.Threading.Tasks;
using Fizzler.Systems.HtmlAgilityPack;
using HtmlAgilityPack;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
namespace FreeProxySharp.Test
{
public class BasicTest : IClassFixture<TestFixture>
{
#region DI
private readonly TestFixture _test;
public BasicTest(TestFixture test)
{
_test = test;
}
#endregion
[Fact]
public async Task TestHttpClientCommon()
{
var factory = _test.Services.GetRequiredService<IHttpClientFactory>();
var client = factory.CreateClient("COMMON");
Assert.NotEmpty(await client.GetStringSafeAsync("https://httpstat.us"));
}
[Fact]
public async Task TestHttpClientNotFound()
{
var factory = _test.Services.GetRequiredService<IHttpClientFactory>();
var client = factory.CreateClient("404TEST");
await Assert.ThrowsAsync<HttpRequestException>(async () => await client.GetStringSafeAsync("https://httpstat.us/404"));
}
[Fact]
public async Task TestHttpClientProxy()
{
var factory = _test.Services.GetRequiredService<HttpProxyFactory>();
var client = factory.GetClientProxy("PROXY");
var html = await client.GetStringSafeAsync("http://www.whatismyip.cz/");
var doc = new HtmlDocument();
doc.LoadHtml(html);
var ipValue = doc.DocumentNode.QuerySelector("div.ip")?.InnerText;
Assert.Contains(_test.Options.Proxies, x => x.Ip == ipValue);
}
[Fact]
public async Task TestFreeProxyListNet()
{
// get proxy list
var proxies = await FreeProxyListNet.Parse();
Assert.NotEmpty(proxies);
Assert.Contains(proxies, x => !string.IsNullOrEmpty(x.Ip));
Assert.Contains(proxies, x => x.Port > 0);
Assert.Contains(proxies, x => !string.IsNullOrEmpty(x.Code));
Assert.Contains(proxies, x => !string.IsNullOrEmpty(x.Country));
Assert.Contains(proxies, x => x.Type == FreeProxyTypes.Elite);
Assert.Contains(proxies, x => x.IsHttps);
// check all proxies
var checkedProxies = await FreeProxyListNet.Check(proxies, codeFilter: new[] { "SE", "DE", "ES", "PL", "FR", "NL", "CZ", "US", "RU" }, required: 1, maxMiliseconds: 1200, timeoutSeconds: 3);
Assert.NotEmpty(checkedProxies);
Assert.All(checkedProxies, x => Assert.True(x.ElapsedMiliseconds > 0));
}
[Fact]
public void TestFreeProxyConfigAssign()
{
// check config for proxy list
Assert.NotEmpty(_test.Options.Proxies);
}
}
}