public HttpConnection(IHostInput hostInput) { if (hostInput == null) { throw new ArgumentNullException(nameof(hostInput)); } else if (string.IsNullOrEmpty(hostInput.Address)) { throw new ArgumentException(nameof(hostInput.Address)); } else if (hostInput.TimeOut.TotalMilliseconds <= 0 || hostInput.TimeOut.TotalMilliseconds > int.MaxValue) { throw new ArgumentOutOfRangeException(nameof(hostInput.TimeOut)); } else { IHostInputCheck inputCheck = new HostInputValidate(); if (!inputCheck.Check(hostInput.Address, Constant.HttpUrlOrIpCheckPattern)) { throw new FormatException(nameof(hostInput.Address)); } HostInput = hostInput; } }
public void HostInputCheckHostOrPatternNullFailTest() { var hostInputCheck = new HostInputValidate(); Assert.ThrowsException <ArgumentNullException>(() => hostInputCheck.Check(null, Constant.HttpUrlOrIpCheckPattern)); Assert.ThrowsException <ArgumentNullException>(() => hostInputCheck.Check("https://ya.ru", null)); }
public TcpConnection(IHostInput hostInput) { if (hostInput == null) { throw new ArgumentNullException(nameof(hostInput)); } else if (string.IsNullOrEmpty(hostInput.Address)) { throw new ArgumentException(nameof(hostInput.Address)); } else if (hostInput.TimeOut.TotalMilliseconds <= 0 || hostInput.TimeOut.TotalMilliseconds > int.MaxValue) { throw new ArgumentOutOfRangeException(nameof(hostInput.TimeOut)); } else { var inputParser = new HostInputValidate(); (_ip, _port) = inputParser.Parse(hostInput.Address); if (_port <= 0) { throw new ArgumentOutOfRangeException(nameof(_port)); } HostInput = hostInput; _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); } }
public void TcpHostInputParseFormatFailTest() { var hostInputCheck = new HostInputValidate(); Assert.ThrowsException <FormatException>(() => hostInputCheck.Parse("173.194.216.113")); Assert.ThrowsException <FormatException>(() => hostInputCheck.Parse("173.194.216:80")); Assert.ThrowsException <FormatException>(() => hostInputCheck.Parse("173.194.216.113:")); }
public void IcmpHostInputCheckFormatFailTest() { var hostInputCheck = new HostInputValidate(); Assert.IsFalse(hostInputCheck.Check("google", Constant.IcmpUrlOrIpCheckPattern)); Assert.IsFalse(hostInputCheck.Check("173.194.216", Constant.IcmpUrlOrIpCheckPattern)); }
public void IcmpHostInputSuccessTest() { var hostInputCheck = new HostInputValidate(); Assert.IsTrue(hostInputCheck.Check("google.com", Constant.IcmpUrlOrIpCheckPattern)); Assert.IsTrue(hostInputCheck.Check("173.194.216.113", Constant.IcmpUrlOrIpCheckPattern)); }
public void TcpHostInputParseSuccessTest() { var hostInputCheck = new HostInputValidate(); (var ip, var port) = hostInputCheck.Parse("173.194.216.113:1234"); Assert.AreEqual(ip, "173.194.216.113"); Assert.AreEqual(port, 1234); }
public void HttpHostInputCheckFormatFailTest() { var hostInputCheck = new HostInputValidate(); Assert.IsFalse(hostInputCheck.Check("https:google.com", Constant.HttpUrlOrIpCheckPattern)); Assert.IsFalse(hostInputCheck.Check("https://google.com:", Constant.HttpUrlOrIpCheckPattern)); Assert.IsFalse(hostInputCheck.Check("https://173.194.216", Constant.HttpUrlOrIpCheckPattern)); Assert.IsFalse(hostInputCheck.Check("asd", Constant.HttpUrlOrIpCheckPattern)); }
public void HttpHostInputCheckSuccessTest() { var hostInputCheck = new HostInputValidate(); Assert.IsTrue(hostInputCheck.Check("https://google.com", Constant.HttpUrlOrIpCheckPattern)); Assert.IsTrue(hostInputCheck.Check("https://google.com:80", Constant.HttpUrlOrIpCheckPattern)); Assert.IsTrue(hostInputCheck.Check("https://173.194.216.113", Constant.HttpUrlOrIpCheckPattern)); Assert.IsTrue(hostInputCheck.Check("https://173.194.216.113:80", Constant.HttpUrlOrIpCheckPattern)); }
public void TcpHostInputSuccessTest() { var hostInputCheck = new HostInputValidate(); Assert.IsTrue(hostInputCheck.Check("173.194.216.113", Constant.TcpIpCheckPattern)); }
public void HostInputParseHostNullFailTest() { var hostInputCheck = new HostInputValidate(); Assert.ThrowsException <ArgumentNullException>(() => hostInputCheck.Parse(null)); }