forked from dotnet/corefx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebRequestTest.cs
More file actions
58 lines (51 loc) · 2.05 KB
/
WebRequestTest.cs
File metadata and controls
58 lines (51 loc) · 2.05 KB
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
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Xunit;
namespace System.Net.Requests.Test
{
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;
}
}
}
}