blob: 1a3aec7877da23d5bf9777c5185e1637c2ca0a58 (
plain)
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
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Xunit;
namespace System.Net.Tests
{
public class WebRequestTest
{
private readonly NetworkCredential _explicitCredentials = new NetworkCredential("user", "password", "domain");
[Fact]
public void DefaultWebProxy_VerifyDefaults_Success()
{
IWebProxy proxy = WebRequest.DefaultWebProxy;
Assert.NotNull(proxy);
// Since WebRequest.DefaultWebProxy is a static property, the initial default value for
// Credentials is only null iff. no other test method in the test process has changed
// the value in a prior test.
Assert.Null(proxy.Credentials);
}
[Fact]
public void DefaultWebProxy_SetCredentialsToNullThenGet_ValuesMatch()
{
IWebProxy proxy = WebRequest.DefaultWebProxy;
proxy.Credentials = null;
Assert.Equal(null, proxy.Credentials);
}
[Fact]
public void DefaultWebProxy_SetCredentialsToDefaultCredentialsThenGet_ValuesMatch()
{
IWebProxy proxy = WebRequest.DefaultWebProxy;
proxy.Credentials = CredentialCache.DefaultCredentials;
Assert.Equal(CredentialCache.DefaultCredentials, proxy.Credentials);
}
[Fact]
public void DefaultWebProxy_SetCredentialsToExplicitCredentialsThenGet_ValuesMatch()
{
IWebProxy proxy = WebRequest.DefaultWebProxy;
ICredentials oldCreds = proxy.Credentials;
try
{
proxy.Credentials = _explicitCredentials;
Assert.Equal(_explicitCredentials, proxy.Credentials);
}
finally
{
// Reset the credentials so as not to interfere with any subsequent tests,
// e.g. DefaultWebProxy_VerifyDefaults_Success
proxy.Credentials = oldCreds;
}
}
[Theory]
[InlineData("http")]
[InlineData("https")]
public void Create_ValidWebRequestUriScheme_Success(string scheme)
{
var uri = new Uri($"{scheme}://example.com/folder/resource.txt");
WebRequest request = WebRequest.Create(uri);
}
[Theory]
[InlineData("ws")]
[InlineData("wss")]
[InlineData("file")]
[InlineData("ftp")]
[InlineData("custom")]
public void Create_InvalidWebRequestUriScheme_Throws(string scheme)
{
var uri = new Uri($"{scheme}://example.com/folder/resource.txt");
Assert.Throws<NotSupportedException>(() => WebRequest.Create(uri));
}
}
}
|