示例#1
0
        public CaptchaProxy(CaptchaProxyType type, string address)
        {
            Validate(type, address);

            Type    = type;
            Address = address;
        }
示例#2
0
        public CaptchaProxy(string type, string address)
        {
            bool typeIsValid = Enum.TryParse(type.Trim().ToUpper(), out CaptchaProxyType proxyType);

            if (!typeIsValid)
            {
                throw new ArgumentException(@"Proxy type is invalid. Available: HTTP, HTTPS, SOCKS4, SOCKS5", nameof(address));
            }

            Validate(proxyType, address);

            Type    = proxyType;
            Address = address;
        }
示例#3
0
        // ReSharper disable once UnusedParameter.Local
        private static void Validate(CaptchaProxyType type, string address)
        {
            if (string.IsNullOrEmpty(address))
            {
                throw new ArgumentException($@"{nameof(CaptchaProxy)} should contain {nameof(address)}", nameof(address));
            }

            // Simple validate port
            int       portIndex     = address.IndexOf(':');
            const int minPortLength = 2;

            if (portIndex == -1 || address.Length - 1 - portIndex < minPortLength)
            {
                throw new ArgumentException($@"{nameof(address)} should contain port", nameof(address));
            }
        }
示例#4
0
        public void CaptchaProxy__Invalid_Address()
        {
            const CaptchaProxyType type = CaptchaProxyType.HTTPS;

            Assert.ThrowsException <ArgumentException>(() => {
                var cp = new CaptchaProxy(type, null);
            });

            Assert.ThrowsException <ArgumentException>(() => {
                var cp = new CaptchaProxy(type, string.Empty);
            });

            Assert.ThrowsException <ArgumentException>(() => {
                var cp = new CaptchaProxy(type, "127.0.0.1");
            });

            Assert.ThrowsException <ArgumentException>(() => {
                var cp = new CaptchaProxy(type, "127.0.0.1:");
            });

            Assert.ThrowsException <ArgumentException>(() => {
                var cp = new CaptchaProxy(type, "127.0.0.1:8");
            });
        }