public void DoCommandShouldAutoConnectToServer()
        {
            var started = _server.Start();

            Assert.True(started, "Could not start server");

            _server.HandleCommand += (socket, line) => socket.Send(Encoding.ASCII.GetBytes(line));

            _client = new SocketCommandClient("localhost", _testServerPort, _ => { });

            const string cmd      = "TEST*TEST";
            var          response = _client.DoCommand(cmd + _server.Eoc.First());

            Assert.True(_client.IsConnected);
            Assert.Equal(cmd, response);
        }
        public void IncompleteCommandShouldNotTimeoutIfNotSpecified()
        {
            var started = _server.Start();

            Assert.True(started, "Could not start server");

            _client = new SocketCommandClient("localhost", _testServerPort, _ => { });

            var connected = _client.Connect();

            Assert.True(connected, "LastResult: " + _client.LastResult);

            _cancel = new CancellationTokenSource();
            _task   = Task.Run(() => _client.DoCommand("TEST"), _cancel.Token);
            var completedInTime = Task.WaitAll(new[] { _task }, 5000, _cancel.Token);

            _cancel.Cancel();

            Assert.False(completedInTime, "Should NOT timeout");
        }
        public void IncompleteCommandShouldTimeoutInTimeIfSpecified()
        {
            var started = _server.Start();

            Assert.True(started, "Could not start server");

            _client = new SocketCommandClient("localhost", _testServerPort, _ => { })
            {
                ConnectTimeout    = 1000,
                CommandRetryCount = 0
            };

            _client.Connect();
            _client.SetReceiveTimeout(1000);

            _cancel = new CancellationTokenSource();
            _task   = Task.Run(() => _client.DoCommand("TEST"), _cancel.Token);
            var completedInTime = Task.WaitAll(new[] { _task }, 6000, _cancel.Token);

            _cancel.Cancel();

            Assert.True(completedInTime, "Should timeout");
        }