コード例 #1
0
        public void CtorTest()
        {
            var target = new Uri("https://www.baidu.com/");
            var uri    = "http://localhost:5533/";
            var proxy  = new HttpProxy(uri);

            Assert.True(proxy.Host == "localhost" && proxy.Port == 5533);
            Assert.True(proxy.GetProxy(target) == new Uri(uri));
            Assert.True(proxy.UserName == null);
            Assert.True(((IWebProxy)proxy).Credentials == null);


            proxy = new HttpProxy(new Uri(uri));
            Assert.True(proxy.Host == "localhost" && proxy.Port == 5533);
            Assert.True(proxy.GetProxy(target) == new Uri(uri));
            Assert.True(proxy.UserName == null);
            Assert.True(((IWebProxy)proxy).Credentials == null);


            proxy = new HttpProxy("localhost", 5533, "laojiu", "123456");
            Assert.True(proxy.Host == "localhost" && proxy.Port == 5533);
            Assert.True(proxy.GetProxy(target) == new Uri(uri));
            Assert.True(proxy.UserName == "laojiu");
            Assert.True(proxy.Password == "123456");
            Assert.True(((IWebProxy)proxy).Credentials.GetCredential(null, null).UserName == "laojiu");
            Assert.True(((IWebProxy)proxy).Credentials.GetCredential(null, null).Password == "123456");
        }