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 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 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 HostInputParseHostNullFailTest() { var hostInputCheck = new HostInputValidate(); Assert.ThrowsException <ArgumentNullException>(() => hostInputCheck.Parse(null)); }