public void ClientDecorator_Handshake_CallGetStreamOnceIfNoBytesAvailable()
        {
            _client.Setup(c => c.Available).Returns(0);
            _client.Setup(c => c.GetStream()).Returns(new MemoryStream());
            var clientDecorator = new ClientDecorator(_client.Object);

            clientDecorator.Handshake();

            _client.Verify(c => c.Available, Times.Once);
            _client.Verify(c => c.GetStream(), Times.Exactly(1));
        }
        public void ClientDecorator_Handshake_CallGetStreamOnceIfNotGetFoundInIncomingStream()
        {
            var testBytes = Encoding.UTF8.GetBytes("Something");

            _client.Setup(c => c.Available).Returns(testBytes.Length);
            _client.Setup(c => c.GetStream()).Returns(new MemoryStream(testBytes));
            var clientDecorator = new ClientDecorator(_client.Object);

            clientDecorator.Handshake();

            _client.Verify(c => c.Available, Times.Once);
            _client.Verify(c => c.GetStream(), Times.Exactly(1));
        }
        public void ClientDecorator_Handshake_CallGetStreamTwiceIfGetFoundInIncomingStream()
        {
            var testBytes = Encoding.UTF8.GetBytes("GET");

            using (var testStream = new MemoryStream())
            {
                testStream.Write(testBytes, 0, testBytes.Length);
                testStream.Position = 0;
                _client.Setup(c => c.Available).Returns(testBytes.Length);
                _client.Setup(c => c.GetStream()).Returns(testStream);
                var clientDecorator = new ClientDecorator(_client.Object);

                clientDecorator.Handshake();
            }

            _client.Verify(c => c.Available, Times.Once);
            _client.Verify(c => c.GetStream(), Times.Exactly(2));
        }