示例#1
0
        /// <summary>
        /// Once we have established that we need to authenticate
        /// we try a username and password / domain to 
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="domain"></param>
        /// <returns></returns>
        public virtual ProxyDetails TryAuthenticate(string userName, string password, string domain = null)
        {
            ProxyDetails proxyDetails = new ProxyDetails();
            WebClient webClient = new WebClient();

            // Set the credentials
            WebRequest.DefaultWebProxy.Credentials = new NetworkCredential(userName, password, domain);

            // Try and connect again
            try
            {
                CheckExists();
                proxyDetails.Result = "Sucessful";
                proxyDetails.WebClient = webClient;
                proxyDetails.Successful = true;
            }
            catch (Exception exception)
            {
                proxyDetails.Result = exception.Message;
                proxyDetails.WebClient = null;
                proxyDetails.Successful = false;
            }

            return proxyDetails;
        }
示例#2
0
 public void Setup()
 {
     _mock = new Mock<ProxyHelper>();
     _userCredentials = new UserCredentials {Domain = "", Password = "******", UserName = "******"};
     _trueProxyDetails = new ProxyDetails {Result = "true", Successful = true, WebClient = null};
     _falseProxyDetails = new ProxyDetails { Result = "false", Successful = false, WebClient = null };
 }